blob: 93837d9eecd2faa829e9ceb669fb9d577a0bad5c [file] [log] [blame]
Helen Koikef2fe8902017-04-07 14:55:19 -03001/*
2 * vimc-capture.c Virtual Media Controller Driver
3 *
4 * Copyright (C) 2015-2017 Helen Koike <helen.fornazier@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
Helen Fornazier4a29b702017-06-19 14:00:18 -030018#include <linux/component.h>
19#include <linux/module.h>
Randy Dunlapac316722018-06-19 22:47:28 -070020#include <linux/mod_devicetable.h>
Helen Fornazier4a29b702017-06-19 14:00:18 -030021#include <linux/platform_device.h>
Helen Koikef2fe8902017-04-07 14:55:19 -030022#include <media/v4l2-ioctl.h>
23#include <media/videobuf2-core.h>
24#include <media/videobuf2-vmalloc.h>
25
Helen Fornazier4a29b702017-06-19 14:00:18 -030026#include "vimc-common.h"
Lucas A. M. Magalhãesadc589d2019-01-21 20:05:01 -050027#include "vimc-streamer.h"
Helen Fornazier4a29b702017-06-19 14:00:18 -030028
29#define VIMC_CAP_DRV_NAME "vimc-capture"
Helen Koikef2fe8902017-04-07 14:55:19 -030030
31struct vimc_cap_device {
32 struct vimc_ent_device ved;
33 struct video_device vdev;
Helen Fornazier4a29b702017-06-19 14:00:18 -030034 struct device *dev;
Helen Koikef2fe8902017-04-07 14:55:19 -030035 struct v4l2_pix_format format;
36 struct vb2_queue queue;
37 struct list_head buf_list;
38 /*
39 * NOTE: in a real driver, a spin lock must be used to access the
40 * queue because the frames are generated from a hardware interruption
41 * and the isr is not allowed to sleep.
42 * Even if it is not necessary a spinlock in the vimc driver, we
43 * use it here as a code reference
44 */
45 spinlock_t qlock;
46 struct mutex lock;
47 u32 sequence;
Lucas A. M. Magalhãesadc589d2019-01-21 20:05:01 -050048 struct vimc_stream stream;
Helen Koikef2fe8902017-04-07 14:55:19 -030049};
50
Helen Fornazier535d2962017-06-19 14:00:17 -030051static const struct v4l2_pix_format fmt_default = {
52 .width = 640,
53 .height = 480,
54 .pixelformat = V4L2_PIX_FMT_RGB24,
55 .field = V4L2_FIELD_NONE,
56 .colorspace = V4L2_COLORSPACE_DEFAULT,
57};
58
Helen Koikef2fe8902017-04-07 14:55:19 -030059struct vimc_cap_buffer {
60 /*
61 * struct vb2_v4l2_buffer must be the first element
62 * the videobuf2 framework will allocate this struct based on
63 * buf_struct_size and use the first sizeof(struct vb2_buffer) bytes of
64 * memory as a vb2_buffer
65 */
66 struct vb2_v4l2_buffer vb2;
67 struct list_head list;
68};
69
70static int vimc_cap_querycap(struct file *file, void *priv,
71 struct v4l2_capability *cap)
72{
73 struct vimc_cap_device *vcap = video_drvdata(file);
74
Hans Verkuil04ee6d62019-01-14 10:27:45 -020075 strscpy(cap->driver, VIMC_PDEV_NAME, sizeof(cap->driver));
Mauro Carvalho Chehabc0decac2018-09-10 08:19:14 -040076 strscpy(cap->card, KBUILD_MODNAME, sizeof(cap->card));
Helen Koikef2fe8902017-04-07 14:55:19 -030077 snprintf(cap->bus_info, sizeof(cap->bus_info),
78 "platform:%s", vcap->vdev.v4l2_dev->name);
79
80 return 0;
81}
82
Helen Fornazier288a22d2017-06-19 14:00:14 -030083static void vimc_cap_get_format(struct vimc_ent_device *ved,
84 struct v4l2_pix_format *fmt)
85{
86 struct vimc_cap_device *vcap = container_of(ved, struct vimc_cap_device,
87 ved);
88
89 *fmt = vcap->format;
90}
91
Helen Fornazier535d2962017-06-19 14:00:17 -030092static int vimc_cap_g_fmt_vid_cap(struct file *file, void *priv,
Helen Koikef2fe8902017-04-07 14:55:19 -030093 struct v4l2_format *f)
94{
95 struct vimc_cap_device *vcap = video_drvdata(file);
96
97 f->fmt.pix = vcap->format;
98
99 return 0;
100}
101
Helen Fornazier535d2962017-06-19 14:00:17 -0300102static int vimc_cap_try_fmt_vid_cap(struct file *file, void *priv,
103 struct v4l2_format *f)
104{
105 struct v4l2_pix_format *format = &f->fmt.pix;
106 const struct vimc_pix_map *vpix;
107
108 format->width = clamp_t(u32, format->width, VIMC_FRAME_MIN_WIDTH,
109 VIMC_FRAME_MAX_WIDTH) & ~1;
110 format->height = clamp_t(u32, format->height, VIMC_FRAME_MIN_HEIGHT,
111 VIMC_FRAME_MAX_HEIGHT) & ~1;
112
113 /* Don't accept a pixelformat that is not on the table */
114 vpix = vimc_pix_map_by_pixelformat(format->pixelformat);
115 if (!vpix) {
116 format->pixelformat = fmt_default.pixelformat;
117 vpix = vimc_pix_map_by_pixelformat(format->pixelformat);
118 }
119 /* TODO: Add support for custom bytesperline values */
120 format->bytesperline = format->width * vpix->bpp;
121 format->sizeimage = format->bytesperline * format->height;
122
123 if (format->field == V4L2_FIELD_ANY)
124 format->field = fmt_default.field;
125
126 vimc_colorimetry_clamp(format);
127
128 return 0;
129}
130
131static int vimc_cap_s_fmt_vid_cap(struct file *file, void *priv,
132 struct v4l2_format *f)
Helen Koikef2fe8902017-04-07 14:55:19 -0300133{
134 struct vimc_cap_device *vcap = video_drvdata(file);
135
Helen Fornazier535d2962017-06-19 14:00:17 -0300136 /* Do not change the format while stream is on */
137 if (vb2_is_busy(&vcap->queue))
138 return -EBUSY;
139
140 vimc_cap_try_fmt_vid_cap(file, priv, f);
141
Helen Fornazier4a29b702017-06-19 14:00:18 -0300142 dev_dbg(vcap->dev, "%s: format update: "
Helen Fornazier535d2962017-06-19 14:00:17 -0300143 "old:%dx%d (0x%x, %d, %d, %d, %d) "
144 "new:%dx%d (0x%x, %d, %d, %d, %d)\n", vcap->vdev.name,
145 /* old */
146 vcap->format.width, vcap->format.height,
147 vcap->format.pixelformat, vcap->format.colorspace,
148 vcap->format.quantization, vcap->format.xfer_func,
149 vcap->format.ycbcr_enc,
150 /* new */
151 f->fmt.pix.width, f->fmt.pix.height,
152 f->fmt.pix.pixelformat, f->fmt.pix.colorspace,
153 f->fmt.pix.quantization, f->fmt.pix.xfer_func,
154 f->fmt.pix.ycbcr_enc);
155
156 vcap->format = f->fmt.pix;
157
158 return 0;
159}
160
161static int vimc_cap_enum_fmt_vid_cap(struct file *file, void *priv,
162 struct v4l2_fmtdesc *f)
163{
164 const struct vimc_pix_map *vpix = vimc_pix_map_by_index(f->index);
165
166 if (!vpix)
Helen Koikef2fe8902017-04-07 14:55:19 -0300167 return -EINVAL;
168
Helen Fornazier535d2962017-06-19 14:00:17 -0300169 f->pixelformat = vpix->pixelformat;
170
171 return 0;
172}
173
174static int vimc_cap_enum_framesizes(struct file *file, void *fh,
175 struct v4l2_frmsizeenum *fsize)
176{
177 const struct vimc_pix_map *vpix;
178
179 if (fsize->index)
180 return -EINVAL;
181
182 /* Only accept code in the pix map table */
183 vpix = vimc_pix_map_by_code(fsize->pixel_format);
184 if (!vpix)
185 return -EINVAL;
186
187 fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS;
188 fsize->stepwise.min_width = VIMC_FRAME_MIN_WIDTH;
189 fsize->stepwise.max_width = VIMC_FRAME_MAX_WIDTH;
190 fsize->stepwise.min_height = VIMC_FRAME_MIN_HEIGHT;
191 fsize->stepwise.max_height = VIMC_FRAME_MAX_HEIGHT;
192 fsize->stepwise.step_width = 2;
193 fsize->stepwise.step_height = 2;
Helen Koikef2fe8902017-04-07 14:55:19 -0300194
195 return 0;
196}
197
198static const struct v4l2_file_operations vimc_cap_fops = {
199 .owner = THIS_MODULE,
200 .open = v4l2_fh_open,
201 .release = vb2_fop_release,
202 .read = vb2_fop_read,
203 .poll = vb2_fop_poll,
204 .unlocked_ioctl = video_ioctl2,
205 .mmap = vb2_fop_mmap,
206};
207
208static const struct v4l2_ioctl_ops vimc_cap_ioctl_ops = {
209 .vidioc_querycap = vimc_cap_querycap,
210
Helen Fornazier535d2962017-06-19 14:00:17 -0300211 .vidioc_g_fmt_vid_cap = vimc_cap_g_fmt_vid_cap,
212 .vidioc_s_fmt_vid_cap = vimc_cap_s_fmt_vid_cap,
213 .vidioc_try_fmt_vid_cap = vimc_cap_try_fmt_vid_cap,
Helen Koikef2fe8902017-04-07 14:55:19 -0300214 .vidioc_enum_fmt_vid_cap = vimc_cap_enum_fmt_vid_cap,
Helen Fornazier535d2962017-06-19 14:00:17 -0300215 .vidioc_enum_framesizes = vimc_cap_enum_framesizes,
Helen Koikef2fe8902017-04-07 14:55:19 -0300216
217 .vidioc_reqbufs = vb2_ioctl_reqbufs,
218 .vidioc_create_bufs = vb2_ioctl_create_bufs,
219 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
220 .vidioc_querybuf = vb2_ioctl_querybuf,
221 .vidioc_qbuf = vb2_ioctl_qbuf,
222 .vidioc_dqbuf = vb2_ioctl_dqbuf,
223 .vidioc_expbuf = vb2_ioctl_expbuf,
224 .vidioc_streamon = vb2_ioctl_streamon,
225 .vidioc_streamoff = vb2_ioctl_streamoff,
226};
227
228static void vimc_cap_return_all_buffers(struct vimc_cap_device *vcap,
229 enum vb2_buffer_state state)
230{
231 struct vimc_cap_buffer *vbuf, *node;
232
233 spin_lock(&vcap->qlock);
234
235 list_for_each_entry_safe(vbuf, node, &vcap->buf_list, list) {
236 list_del(&vbuf->list);
237 vb2_buffer_done(&vbuf->vb2.vb2_buf, state);
238 }
239
240 spin_unlock(&vcap->qlock);
241}
242
Helen Koikef2fe8902017-04-07 14:55:19 -0300243static int vimc_cap_start_streaming(struct vb2_queue *vq, unsigned int count)
244{
245 struct vimc_cap_device *vcap = vb2_get_drv_priv(vq);
246 struct media_entity *entity = &vcap->vdev.entity;
247 int ret;
248
249 vcap->sequence = 0;
250
251 /* Start the media pipeline */
Lucas A. M. Magalhãesadc589d2019-01-21 20:05:01 -0500252 ret = media_pipeline_start(entity, &vcap->stream.pipe);
Helen Koikef2fe8902017-04-07 14:55:19 -0300253 if (ret) {
254 vimc_cap_return_all_buffers(vcap, VB2_BUF_STATE_QUEUED);
255 return ret;
256 }
257
Lucas A. M. Magalhãesadc589d2019-01-21 20:05:01 -0500258 ret = vimc_streamer_s_stream(&vcap->stream, &vcap->ved, 1);
Helen Koikef2fe8902017-04-07 14:55:19 -0300259 if (ret) {
260 media_pipeline_stop(entity);
261 vimc_cap_return_all_buffers(vcap, VB2_BUF_STATE_QUEUED);
262 return ret;
263 }
264
265 return 0;
266}
267
268/*
269 * Stop the stream engine. Any remaining buffers in the stream queue are
270 * dequeued and passed on to the vb2 framework marked as STATE_ERROR.
271 */
272static void vimc_cap_stop_streaming(struct vb2_queue *vq)
273{
274 struct vimc_cap_device *vcap = vb2_get_drv_priv(vq);
275
Lucas A. M. Magalhãesadc589d2019-01-21 20:05:01 -0500276 vimc_streamer_s_stream(&vcap->stream, &vcap->ved, 0);
Helen Koikef2fe8902017-04-07 14:55:19 -0300277
278 /* Stop the media pipeline */
279 media_pipeline_stop(&vcap->vdev.entity);
280
281 /* Release all active buffers */
282 vimc_cap_return_all_buffers(vcap, VB2_BUF_STATE_ERROR);
283}
284
285static void vimc_cap_buf_queue(struct vb2_buffer *vb2_buf)
286{
287 struct vimc_cap_device *vcap = vb2_get_drv_priv(vb2_buf->vb2_queue);
288 struct vimc_cap_buffer *buf = container_of(vb2_buf,
289 struct vimc_cap_buffer,
290 vb2.vb2_buf);
291
292 spin_lock(&vcap->qlock);
293 list_add_tail(&buf->list, &vcap->buf_list);
294 spin_unlock(&vcap->qlock);
295}
296
297static int vimc_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
298 unsigned int *nplanes, unsigned int sizes[],
299 struct device *alloc_devs[])
300{
301 struct vimc_cap_device *vcap = vb2_get_drv_priv(vq);
302
303 if (*nplanes)
304 return sizes[0] < vcap->format.sizeimage ? -EINVAL : 0;
305 /* We don't support multiplanes for now */
306 *nplanes = 1;
307 sizes[0] = vcap->format.sizeimage;
308
309 return 0;
310}
311
312static int vimc_cap_buffer_prepare(struct vb2_buffer *vb)
313{
314 struct vimc_cap_device *vcap = vb2_get_drv_priv(vb->vb2_queue);
315 unsigned long size = vcap->format.sizeimage;
316
317 if (vb2_plane_size(vb, 0) < size) {
Helen Fornazier4a29b702017-06-19 14:00:18 -0300318 dev_err(vcap->dev, "%s: buffer too small (%lu < %lu)\n",
Helen Koikef2fe8902017-04-07 14:55:19 -0300319 vcap->vdev.name, vb2_plane_size(vb, 0), size);
320 return -EINVAL;
321 }
322 return 0;
323}
324
325static const struct vb2_ops vimc_cap_qops = {
326 .start_streaming = vimc_cap_start_streaming,
327 .stop_streaming = vimc_cap_stop_streaming,
328 .buf_queue = vimc_cap_buf_queue,
329 .queue_setup = vimc_cap_queue_setup,
330 .buf_prepare = vimc_cap_buffer_prepare,
331 /*
332 * Since q->lock is set we can use the standard
333 * vb2_ops_wait_prepare/finish helper functions.
334 */
335 .wait_prepare = vb2_ops_wait_prepare,
336 .wait_finish = vb2_ops_wait_finish,
337};
338
Helen Koikef2fe8902017-04-07 14:55:19 -0300339static const struct media_entity_operations vimc_cap_mops = {
Helen Fornazier288a22d2017-06-19 14:00:14 -0300340 .link_validate = vimc_link_validate,
Helen Koikef2fe8902017-04-07 14:55:19 -0300341};
342
Helen Fornazier4a29b702017-06-19 14:00:18 -0300343static void vimc_cap_comp_unbind(struct device *comp, struct device *master,
344 void *master_data)
Helen Koikef2fe8902017-04-07 14:55:19 -0300345{
Helen Fornazier4a29b702017-06-19 14:00:18 -0300346 struct vimc_ent_device *ved = dev_get_drvdata(comp);
Helen Koikef2fe8902017-04-07 14:55:19 -0300347 struct vimc_cap_device *vcap = container_of(ved, struct vimc_cap_device,
348 ved);
349
350 vb2_queue_release(&vcap->queue);
351 media_entity_cleanup(ved->ent);
352 video_unregister_device(&vcap->vdev);
353 vimc_pads_cleanup(vcap->ved.pads);
354 kfree(vcap);
355}
356
Lucas A. M. Magalhãesadc589d2019-01-21 20:05:01 -0500357static void *vimc_cap_process_frame(struct vimc_ent_device *ved,
358 const void *frame)
Helen Koikef2fe8902017-04-07 14:55:19 -0300359{
360 struct vimc_cap_device *vcap = container_of(ved, struct vimc_cap_device,
361 ved);
362 struct vimc_cap_buffer *vimc_buf;
363 void *vbuf;
364
365 spin_lock(&vcap->qlock);
366
367 /* Get the first entry of the list */
368 vimc_buf = list_first_entry_or_null(&vcap->buf_list,
369 typeof(*vimc_buf), list);
370 if (!vimc_buf) {
371 spin_unlock(&vcap->qlock);
Lucas A. M. Magalhãesadc589d2019-01-21 20:05:01 -0500372 return ERR_PTR(-EAGAIN);
Helen Koikef2fe8902017-04-07 14:55:19 -0300373 }
374
375 /* Remove this entry from the list */
376 list_del(&vimc_buf->list);
377
378 spin_unlock(&vcap->qlock);
379
380 /* Fill the buffer */
381 vimc_buf->vb2.vb2_buf.timestamp = ktime_get_ns();
382 vimc_buf->vb2.sequence = vcap->sequence++;
383 vimc_buf->vb2.field = vcap->format.field;
384
385 vbuf = vb2_plane_vaddr(&vimc_buf->vb2.vb2_buf, 0);
386
387 memcpy(vbuf, frame, vcap->format.sizeimage);
388
389 /* Set it as ready */
390 vb2_set_plane_payload(&vimc_buf->vb2.vb2_buf, 0,
391 vcap->format.sizeimage);
392 vb2_buffer_done(&vimc_buf->vb2.vb2_buf, VB2_BUF_STATE_DONE);
Lucas A. M. Magalhãesadc589d2019-01-21 20:05:01 -0500393 return NULL;
Helen Koikef2fe8902017-04-07 14:55:19 -0300394}
395
Helen Fornazier4a29b702017-06-19 14:00:18 -0300396static int vimc_cap_comp_bind(struct device *comp, struct device *master,
397 void *master_data)
Helen Koikef2fe8902017-04-07 14:55:19 -0300398{
Helen Fornazier4a29b702017-06-19 14:00:18 -0300399 struct v4l2_device *v4l2_dev = master_data;
400 struct vimc_platform_data *pdata = comp->platform_data;
Helen Koikef2fe8902017-04-07 14:55:19 -0300401 const struct vimc_pix_map *vpix;
402 struct vimc_cap_device *vcap;
403 struct video_device *vdev;
404 struct vb2_queue *q;
405 int ret;
406
Helen Koikef2fe8902017-04-07 14:55:19 -0300407 /* Allocate the vimc_cap_device struct */
408 vcap = kzalloc(sizeof(*vcap), GFP_KERNEL);
409 if (!vcap)
Helen Fornazier4a29b702017-06-19 14:00:18 -0300410 return -ENOMEM;
Helen Koikef2fe8902017-04-07 14:55:19 -0300411
412 /* Allocate the pads */
Helen Fornazier4a29b702017-06-19 14:00:18 -0300413 vcap->ved.pads =
414 vimc_pads_init(1, (const unsigned long[1]) {MEDIA_PAD_FL_SINK});
Helen Koikef2fe8902017-04-07 14:55:19 -0300415 if (IS_ERR(vcap->ved.pads)) {
416 ret = PTR_ERR(vcap->ved.pads);
417 goto err_free_vcap;
418 }
419
420 /* Initialize the media entity */
Helen Fornazier4a29b702017-06-19 14:00:18 -0300421 vcap->vdev.entity.name = pdata->entity_name;
Helen Koikef2fe8902017-04-07 14:55:19 -0300422 vcap->vdev.entity.function = MEDIA_ENT_F_IO_V4L;
423 ret = media_entity_pads_init(&vcap->vdev.entity,
Helen Fornazier4a29b702017-06-19 14:00:18 -0300424 1, vcap->ved.pads);
Helen Koikef2fe8902017-04-07 14:55:19 -0300425 if (ret)
426 goto err_clean_pads;
427
428 /* Initialize the lock */
429 mutex_init(&vcap->lock);
430
431 /* Initialize the vb2 queue */
432 q = &vcap->queue;
433 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
434 q->io_modes = VB2_MMAP | VB2_DMABUF;
435 q->drv_priv = vcap;
436 q->buf_struct_size = sizeof(struct vimc_cap_buffer);
437 q->ops = &vimc_cap_qops;
438 q->mem_ops = &vb2_vmalloc_memops;
439 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
440 q->min_buffers_needed = 2;
441 q->lock = &vcap->lock;
442
443 ret = vb2_queue_init(q);
444 if (ret) {
Helen Fornazier4a29b702017-06-19 14:00:18 -0300445 dev_err(comp, "%s: vb2 queue init failed (err=%d)\n",
446 pdata->entity_name, ret);
Helen Koikef2fe8902017-04-07 14:55:19 -0300447 goto err_clean_m_ent;
448 }
449
450 /* Initialize buffer list and its lock */
451 INIT_LIST_HEAD(&vcap->buf_list);
452 spin_lock_init(&vcap->qlock);
453
Helen Fornazier535d2962017-06-19 14:00:17 -0300454 /* Set default frame format */
455 vcap->format = fmt_default;
Helen Koikef2fe8902017-04-07 14:55:19 -0300456 vpix = vimc_pix_map_by_pixelformat(vcap->format.pixelformat);
Helen Koikef2fe8902017-04-07 14:55:19 -0300457 vcap->format.bytesperline = vcap->format.width * vpix->bpp;
458 vcap->format.sizeimage = vcap->format.bytesperline *
459 vcap->format.height;
460
461 /* Fill the vimc_ent_device struct */
Helen Koikef2fe8902017-04-07 14:55:19 -0300462 vcap->ved.ent = &vcap->vdev.entity;
463 vcap->ved.process_frame = vimc_cap_process_frame;
Helen Fornazier288a22d2017-06-19 14:00:14 -0300464 vcap->ved.vdev_get_format = vimc_cap_get_format;
Helen Fornazier4a29b702017-06-19 14:00:18 -0300465 dev_set_drvdata(comp, &vcap->ved);
466 vcap->dev = comp;
Helen Koikef2fe8902017-04-07 14:55:19 -0300467
468 /* Initialize the video_device struct */
469 vdev = &vcap->vdev;
470 vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
471 vdev->entity.ops = &vimc_cap_mops;
472 vdev->release = video_device_release_empty;
473 vdev->fops = &vimc_cap_fops;
474 vdev->ioctl_ops = &vimc_cap_ioctl_ops;
475 vdev->lock = &vcap->lock;
476 vdev->queue = q;
477 vdev->v4l2_dev = v4l2_dev;
478 vdev->vfl_dir = VFL_DIR_RX;
Mauro Carvalho Chehabc0decac2018-09-10 08:19:14 -0400479 strscpy(vdev->name, pdata->entity_name, sizeof(vdev->name));
Helen Koikef2fe8902017-04-07 14:55:19 -0300480 video_set_drvdata(vdev, &vcap->ved);
481
482 /* Register the video_device with the v4l2 and the media framework */
483 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
484 if (ret) {
Helen Fornazier4a29b702017-06-19 14:00:18 -0300485 dev_err(comp, "%s: video register failed (err=%d)\n",
Helen Koikef2fe8902017-04-07 14:55:19 -0300486 vcap->vdev.name, ret);
487 goto err_release_queue;
488 }
489
Helen Fornazier4a29b702017-06-19 14:00:18 -0300490 return 0;
Helen Koikef2fe8902017-04-07 14:55:19 -0300491
492err_release_queue:
493 vb2_queue_release(q);
494err_clean_m_ent:
495 media_entity_cleanup(&vcap->vdev.entity);
496err_clean_pads:
497 vimc_pads_cleanup(vcap->ved.pads);
498err_free_vcap:
499 kfree(vcap);
500
Helen Fornazier4a29b702017-06-19 14:00:18 -0300501 return ret;
Helen Koikef2fe8902017-04-07 14:55:19 -0300502}
Helen Fornazier4a29b702017-06-19 14:00:18 -0300503
504static const struct component_ops vimc_cap_comp_ops = {
505 .bind = vimc_cap_comp_bind,
506 .unbind = vimc_cap_comp_unbind,
507};
508
509static int vimc_cap_probe(struct platform_device *pdev)
510{
511 return component_add(&pdev->dev, &vimc_cap_comp_ops);
512}
513
514static int vimc_cap_remove(struct platform_device *pdev)
515{
516 component_del(&pdev->dev, &vimc_cap_comp_ops);
517
518 return 0;
519}
520
Helen Fornazier4a29b702017-06-19 14:00:18 -0300521static const struct platform_device_id vimc_cap_driver_ids[] = {
522 {
523 .name = VIMC_CAP_DRV_NAME,
524 },
525 { }
526};
527
Javier Martinez Canillasbf183e02017-07-14 05:58:39 -0300528static struct platform_driver vimc_cap_pdrv = {
529 .probe = vimc_cap_probe,
530 .remove = vimc_cap_remove,
531 .id_table = vimc_cap_driver_ids,
532 .driver = {
533 .name = VIMC_CAP_DRV_NAME,
534 },
535};
536
Helen Fornazier4a29b702017-06-19 14:00:18 -0300537module_platform_driver(vimc_cap_pdrv);
538
539MODULE_DEVICE_TABLE(platform, vimc_cap_driver_ids);
540
541MODULE_DESCRIPTION("Virtual Media Controller Driver (VIMC) Capture");
542MODULE_AUTHOR("Helen Mae Koike Fornazier <helen.fornazier@gmail.com>");
543MODULE_LICENSE("GPL");