blob: 40fbb1e429af34ede51043502c28778fb60c19c0 [file] [log] [blame]
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001/*
2 * A virtual v4l2-mem2mem example device.
3 *
4 * This is a virtual device driver for testing mem-to-mem videobuf framework.
5 * It simulates a device that uses memory buffers for both source and
Hans Verkuil144bd0e2018-05-21 04:54:56 -04006 * destination, processes the data and issues an "irq" (simulated by a delayed
7 * workqueue).
Pawel Osciak96d8eab2010-04-23 05:38:38 -03008 * The device is capable of multi-instance, multi-buffer-per-transaction
9 * operation (via the mem2mem framework).
10 *
11 * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd.
Pawel Osciak95072082011-03-13 15:23:32 -030012 * Pawel Osciak, <pawel@osciak.com>
Pawel Osciak96d8eab2010-04-23 05:38:38 -030013 * Marek Szyprowski, <m.szyprowski@samsung.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by the
17 * Free Software Foundation; either version 2 of the
18 * License, or (at your option) any later version
19 */
20#include <linux/module.h>
21#include <linux/delay.h>
22#include <linux/fs.h>
Pawel Osciak96d8eab2010-04-23 05:38:38 -030023#include <linux/sched.h>
Randy Dunlap6b46c392010-05-07 15:22:26 -030024#include <linux/slab.h>
Pawel Osciak96d8eab2010-04-23 05:38:38 -030025
26#include <linux/platform_device.h>
27#include <media/v4l2-mem2mem.h>
28#include <media/v4l2-device.h>
29#include <media/v4l2-ioctl.h>
Hans Verkuild3dd59c2012-07-18 10:35:37 -030030#include <media/v4l2-ctrls.h>
Hans Verkuil97a3c902012-07-18 10:54:59 -030031#include <media/v4l2-event.h>
Marek Szyprowskid80ee382011-01-12 06:50:55 -030032#include <media/videobuf2-vmalloc.h>
Pawel Osciak96d8eab2010-04-23 05:38:38 -030033
Pawel Osciak96d8eab2010-04-23 05:38:38 -030034MODULE_DESCRIPTION("Virtual device for mem2mem framework testing");
Pawel Osciak95072082011-03-13 15:23:32 -030035MODULE_AUTHOR("Pawel Osciak, <pawel@osciak.com>");
Pawel Osciak96d8eab2010-04-23 05:38:38 -030036MODULE_LICENSE("GPL");
Mauro Carvalho Chehab1990d502011-06-24 14:45:49 -030037MODULE_VERSION("0.1.1");
Hans Verkuil1f923a42014-09-22 09:27:17 -030038MODULE_ALIAS("mem2mem_testdev");
Pawel Osciak96d8eab2010-04-23 05:38:38 -030039
Hans Verkuild95d7c62013-04-17 03:04:10 -030040static unsigned debug;
41module_param(debug, uint, 0644);
42MODULE_PARM_DESC(debug, "activates debug info");
43
Pawel Osciak96d8eab2010-04-23 05:38:38 -030044#define MIN_W 32
45#define MIN_H 32
46#define MAX_W 640
47#define MAX_H 480
Guennadi Liakhovetski9ce3ce4d42012-04-27 04:16:46 -030048#define DIM_ALIGN_MASK 7 /* 8-byte alignment for line length */
Pawel Osciak96d8eab2010-04-23 05:38:38 -030049
50/* Flags that indicate a format can be used for capture/output */
51#define MEM2MEM_CAPTURE (1 << 0)
52#define MEM2MEM_OUTPUT (1 << 1)
53
Hans Verkuil1f923a42014-09-22 09:27:17 -030054#define MEM2MEM_NAME "vim2m"
Pawel Osciak96d8eab2010-04-23 05:38:38 -030055
56/* Per queue */
57#define MEM2MEM_DEF_NUM_BUFS VIDEO_MAX_FRAME
58/* In bytes, per queue */
59#define MEM2MEM_VID_MEM_LIMIT (16 * 1024 * 1024)
60
61/* Default transaction time in msec */
Hans Verkuil43405832014-03-10 10:58:23 -030062#define MEM2MEM_DEF_TRANSTIME 40
Pawel Osciak96d8eab2010-04-23 05:38:38 -030063#define MEM2MEM_COLOR_STEP (0xff >> 4)
64#define MEM2MEM_NUM_TILES 8
65
Tomasz Moń80072872012-06-12 06:43:49 -030066/* Flags that indicate processing mode */
67#define MEM2MEM_HFLIP (1 << 0)
68#define MEM2MEM_VFLIP (1 << 1)
69
Pawel Osciak96d8eab2010-04-23 05:38:38 -030070#define dprintk(dev, fmt, arg...) \
Hans Verkuild95d7c62013-04-17 03:04:10 -030071 v4l2_dbg(1, debug, &dev->v4l2_dev, "%s: " fmt, __func__, ## arg)
Pawel Osciak96d8eab2010-04-23 05:38:38 -030072
73
Hans Verkuil1f923a42014-09-22 09:27:17 -030074static void vim2m_dev_release(struct device *dev)
Pawel Osciak96d8eab2010-04-23 05:38:38 -030075{}
76
Hans Verkuil1f923a42014-09-22 09:27:17 -030077static struct platform_device vim2m_pdev = {
Pawel Osciak96d8eab2010-04-23 05:38:38 -030078 .name = MEM2MEM_NAME,
Hans Verkuil1f923a42014-09-22 09:27:17 -030079 .dev.release = vim2m_dev_release,
Pawel Osciak96d8eab2010-04-23 05:38:38 -030080};
81
Hans Verkuil1f923a42014-09-22 09:27:17 -030082struct vim2m_fmt {
Pawel Osciak96d8eab2010-04-23 05:38:38 -030083 u32 fourcc;
84 int depth;
85 /* Types the format can be used for */
86 u32 types;
87};
88
Hans Verkuil1f923a42014-09-22 09:27:17 -030089static struct vim2m_fmt formats[] = {
Pawel Osciak96d8eab2010-04-23 05:38:38 -030090 {
Pawel Osciak96d8eab2010-04-23 05:38:38 -030091 .fourcc = V4L2_PIX_FMT_RGB565X, /* rrrrrggg gggbbbbb */
92 .depth = 16,
93 /* Both capture and output format */
94 .types = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT,
95 },
96 {
Pawel Osciak96d8eab2010-04-23 05:38:38 -030097 .fourcc = V4L2_PIX_FMT_YUYV,
98 .depth = 16,
99 /* Output-only format */
100 .types = MEM2MEM_OUTPUT,
101 },
102};
103
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300104#define NUM_FORMATS ARRAY_SIZE(formats)
105
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300106/* Per-queue, driver-specific private data */
Hans Verkuil1f923a42014-09-22 09:27:17 -0300107struct vim2m_q_data {
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300108 unsigned int width;
109 unsigned int height;
110 unsigned int sizeimage;
Hans Verkuilca5f5fd2014-03-10 10:58:28 -0300111 unsigned int sequence;
Hans Verkuil1f923a42014-09-22 09:27:17 -0300112 struct vim2m_fmt *fmt;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300113};
114
115enum {
116 V4L2_M2M_SRC = 0,
117 V4L2_M2M_DST = 1,
118};
119
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300120#define V4L2_CID_TRANS_TIME_MSEC (V4L2_CID_USER_BASE + 0x1000)
121#define V4L2_CID_TRANS_NUM_BUFS (V4L2_CID_USER_BASE + 0x1001)
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300122
Hans Verkuil1f923a42014-09-22 09:27:17 -0300123static struct vim2m_fmt *find_format(struct v4l2_format *f)
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300124{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300125 struct vim2m_fmt *fmt;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300126 unsigned int k;
127
128 for (k = 0; k < NUM_FORMATS; k++) {
129 fmt = &formats[k];
130 if (fmt->fourcc == f->fmt.pix.pixelformat)
131 break;
132 }
133
134 if (k == NUM_FORMATS)
135 return NULL;
136
137 return &formats[k];
138}
139
Hans Verkuil1f923a42014-09-22 09:27:17 -0300140struct vim2m_dev {
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300141 struct v4l2_device v4l2_dev;
Hans Verkuil09365422015-03-09 13:33:56 -0300142 struct video_device vfd;
Hans Verkuile35f7022018-07-02 11:36:06 -0400143#ifdef CONFIG_MEDIA_CONTROLLER
144 struct media_device mdev;
145#endif
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300146
147 atomic_t num_inst;
148 struct mutex dev_mutex;
149 spinlock_t irqlock;
150
Hans Verkuil144bd0e2018-05-21 04:54:56 -0400151 struct delayed_work work_run;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300152
153 struct v4l2_m2m_dev *m2m_dev;
154};
155
Hans Verkuil1f923a42014-09-22 09:27:17 -0300156struct vim2m_ctx {
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300157 struct v4l2_fh fh;
Hans Verkuil1f923a42014-09-22 09:27:17 -0300158 struct vim2m_dev *dev;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300159
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300160 struct v4l2_ctrl_handler hdl;
161
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300162 /* Processed buffers in this transaction */
163 u8 num_processed;
164
165 /* Transaction length (i.e. how many buffers per transaction) */
166 u32 translen;
167 /* Transaction time (i.e. simulated processing time) in milliseconds */
168 u32 transtime;
169
170 /* Abort requested by m2m */
171 int aborting;
172
Tomasz Moń80072872012-06-12 06:43:49 -0300173 /* Processing mode */
174 int mode;
175
Hans Verkuil47556ff2012-07-18 11:33:22 -0300176 enum v4l2_colorspace colorspace;
Hans Verkuil9f8b3332016-07-18 08:00:20 -0300177 enum v4l2_ycbcr_encoding ycbcr_enc;
178 enum v4l2_xfer_func xfer_func;
179 enum v4l2_quantization quant;
Hans Verkuil47556ff2012-07-18 11:33:22 -0300180
Tomasz Moń9f4161a2012-06-08 04:47:34 -0300181 /* Source and destination queue data */
Hans Verkuil1f923a42014-09-22 09:27:17 -0300182 struct vim2m_q_data q_data[2];
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300183};
184
Hans Verkuil1f923a42014-09-22 09:27:17 -0300185static inline struct vim2m_ctx *file2ctx(struct file *file)
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300186{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300187 return container_of(file->private_data, struct vim2m_ctx, fh);
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300188}
189
Hans Verkuil1f923a42014-09-22 09:27:17 -0300190static struct vim2m_q_data *get_q_data(struct vim2m_ctx *ctx,
Tomasz Moń9f4161a2012-06-08 04:47:34 -0300191 enum v4l2_buf_type type)
192{
193 switch (type) {
194 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
195 return &ctx->q_data[V4L2_M2M_SRC];
196 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
197 return &ctx->q_data[V4L2_M2M_DST];
198 default:
199 BUG();
200 }
201 return NULL;
202}
203
204
Hans Verkuil1f923a42014-09-22 09:27:17 -0300205static int device_process(struct vim2m_ctx *ctx,
Junghak Sung2d700712015-09-22 10:30:30 -0300206 struct vb2_v4l2_buffer *in_vb,
207 struct vb2_v4l2_buffer *out_vb)
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300208{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300209 struct vim2m_dev *dev = ctx->dev;
210 struct vim2m_q_data *q_data;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300211 u8 *p_in, *p_out;
212 int x, y, t, w;
213 int tile_w, bytes_left;
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300214 int width, height, bytesperline;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300215
Tomasz Moń9f4161a2012-06-08 04:47:34 -0300216 q_data = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300217
218 width = q_data->width;
219 height = q_data->height;
220 bytesperline = (q_data->width * q_data->fmt->depth) >> 3;
221
Junghak Sung2d700712015-09-22 10:30:30 -0300222 p_in = vb2_plane_vaddr(&in_vb->vb2_buf, 0);
223 p_out = vb2_plane_vaddr(&out_vb->vb2_buf, 0);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300224 if (!p_in || !p_out) {
225 v4l2_err(&dev->v4l2_dev,
226 "Acquiring kernel pointers to buffers failed\n");
227 return -EFAULT;
228 }
229
Junghak Sung2d700712015-09-22 10:30:30 -0300230 if (vb2_plane_size(&in_vb->vb2_buf, 0) >
231 vb2_plane_size(&out_vb->vb2_buf, 0)) {
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300232 v4l2_err(&dev->v4l2_dev, "Output buffer is too small\n");
233 return -EINVAL;
234 }
235
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300236 tile_w = (width * (q_data[V4L2_M2M_DST].fmt->depth >> 3))
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300237 / MEM2MEM_NUM_TILES;
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300238 bytes_left = bytesperline - tile_w * MEM2MEM_NUM_TILES;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300239 w = 0;
240
Junghak Sung2d700712015-09-22 10:30:30 -0300241 out_vb->sequence =
242 get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE)->sequence++;
243 in_vb->sequence = q_data->sequence++;
Junghak Sungd6dd6452015-11-03 08:16:37 -0200244 out_vb->vb2_buf.timestamp = in_vb->vb2_buf.timestamp;
Junghak Sung2d700712015-09-22 10:30:30 -0300245
246 if (in_vb->flags & V4L2_BUF_FLAG_TIMECODE)
247 out_vb->timecode = in_vb->timecode;
248 out_vb->field = in_vb->field;
249 out_vb->flags = in_vb->flags &
Hans Verkuilca5f5fd2014-03-10 10:58:28 -0300250 (V4L2_BUF_FLAG_TIMECODE |
251 V4L2_BUF_FLAG_KEYFRAME |
252 V4L2_BUF_FLAG_PFRAME |
253 V4L2_BUF_FLAG_BFRAME |
254 V4L2_BUF_FLAG_TSTAMP_SRC_MASK);
Hans Verkuild95d7c62013-04-17 03:04:10 -0300255
Tomasz Moń80072872012-06-12 06:43:49 -0300256 switch (ctx->mode) {
257 case MEM2MEM_HFLIP | MEM2MEM_VFLIP:
258 p_out += bytesperline * height - bytes_left;
259 for (y = 0; y < height; ++y) {
260 for (t = 0; t < MEM2MEM_NUM_TILES; ++t) {
261 if (w & 0x1) {
262 for (x = 0; x < tile_w; ++x)
263 *--p_out = *p_in++ +
264 MEM2MEM_COLOR_STEP;
265 } else {
266 for (x = 0; x < tile_w; ++x)
267 *--p_out = *p_in++ -
268 MEM2MEM_COLOR_STEP;
269 }
270 ++w;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300271 }
Tomasz Moń80072872012-06-12 06:43:49 -0300272 p_in += bytes_left;
273 p_out -= bytes_left;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300274 }
Tomasz Moń80072872012-06-12 06:43:49 -0300275 break;
276
277 case MEM2MEM_HFLIP:
278 for (y = 0; y < height; ++y) {
279 p_out += MEM2MEM_NUM_TILES * tile_w;
280 for (t = 0; t < MEM2MEM_NUM_TILES; ++t) {
281 if (w & 0x01) {
282 for (x = 0; x < tile_w; ++x)
283 *--p_out = *p_in++ +
284 MEM2MEM_COLOR_STEP;
285 } else {
286 for (x = 0; x < tile_w; ++x)
287 *--p_out = *p_in++ -
288 MEM2MEM_COLOR_STEP;
289 }
290 ++w;
291 }
292 p_in += bytes_left;
293 p_out += bytesperline;
294 }
295 break;
296
297 case MEM2MEM_VFLIP:
298 p_out += bytesperline * (height - 1);
299 for (y = 0; y < height; ++y) {
300 for (t = 0; t < MEM2MEM_NUM_TILES; ++t) {
301 if (w & 0x1) {
302 for (x = 0; x < tile_w; ++x)
303 *p_out++ = *p_in++ +
304 MEM2MEM_COLOR_STEP;
305 } else {
306 for (x = 0; x < tile_w; ++x)
307 *p_out++ = *p_in++ -
308 MEM2MEM_COLOR_STEP;
309 }
310 ++w;
311 }
312 p_in += bytes_left;
313 p_out += bytes_left - 2 * bytesperline;
314 }
315 break;
316
317 default:
318 for (y = 0; y < height; ++y) {
319 for (t = 0; t < MEM2MEM_NUM_TILES; ++t) {
320 if (w & 0x1) {
321 for (x = 0; x < tile_w; ++x)
322 *p_out++ = *p_in++ +
323 MEM2MEM_COLOR_STEP;
324 } else {
325 for (x = 0; x < tile_w; ++x)
326 *p_out++ = *p_in++ -
327 MEM2MEM_COLOR_STEP;
328 }
329 ++w;
330 }
331 p_in += bytes_left;
332 p_out += bytes_left;
333 }
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300334 }
335
336 return 0;
337}
338
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300339/*
340 * mem2mem callbacks
341 */
342
Mauro Carvalho Chehabcba862d2017-11-29 08:33:45 -0500343/*
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300344 * job_ready() - check whether an instance is ready to be scheduled to run
345 */
346static int job_ready(void *priv)
347{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300348 struct vim2m_ctx *ctx = priv;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300349
Sylwester Nawrocki20702eb2013-08-25 17:27:45 -0300350 if (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) < ctx->translen
351 || v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx) < ctx->translen) {
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300352 dprintk(ctx->dev, "Not enough buffers available\n");
353 return 0;
354 }
355
356 return 1;
357}
358
359static void job_abort(void *priv)
360{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300361 struct vim2m_ctx *ctx = priv;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300362
363 /* Will cancel the transaction in the next interrupt handler */
364 ctx->aborting = 1;
365}
366
367/* device_run() - prepares and starts the device
368 *
369 * This simulates all the immediate preparations required before starting
370 * a device. This will be called by the framework when it decides to schedule
371 * a particular instance.
372 */
373static void device_run(void *priv)
374{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300375 struct vim2m_ctx *ctx = priv;
376 struct vim2m_dev *dev = ctx->dev;
Junghak Sung2d700712015-09-22 10:30:30 -0300377 struct vb2_v4l2_buffer *src_buf, *dst_buf;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300378
Sylwester Nawrocki20702eb2013-08-25 17:27:45 -0300379 src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
380 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300381
Hans Verkuil86b93b22018-05-21 04:54:57 -0400382 /* Apply request controls if any */
383 v4l2_ctrl_request_setup(src_buf->vb2_buf.req_obj.req,
384 &ctx->hdl);
385
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300386 device_process(ctx, src_buf, dst_buf);
387
Hans Verkuil86b93b22018-05-21 04:54:57 -0400388 /* Complete request controls if any */
389 v4l2_ctrl_request_complete(src_buf->vb2_buf.req_obj.req,
390 &ctx->hdl);
391
Hans Verkuil144bd0e2018-05-21 04:54:56 -0400392 /* Run delayed work, which simulates a hardware irq */
393 schedule_delayed_work(&dev->work_run, msecs_to_jiffies(ctx->transtime));
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300394}
395
Hans Verkuil144bd0e2018-05-21 04:54:56 -0400396static void device_work(struct work_struct *w)
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300397{
Hans Verkuil144bd0e2018-05-21 04:54:56 -0400398 struct vim2m_dev *vim2m_dev =
399 container_of(w, struct vim2m_dev, work_run.work);
Hans Verkuil1f923a42014-09-22 09:27:17 -0300400 struct vim2m_ctx *curr_ctx;
Junghak Sung2d700712015-09-22 10:30:30 -0300401 struct vb2_v4l2_buffer *src_vb, *dst_vb;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300402 unsigned long flags;
403
Hans Verkuil1f923a42014-09-22 09:27:17 -0300404 curr_ctx = v4l2_m2m_get_curr_priv(vim2m_dev->m2m_dev);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300405
406 if (NULL == curr_ctx) {
Sachin Kamat26fdcf02012-09-24 02:17:47 -0300407 pr_err("Instance released before the end of transaction\n");
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300408 return;
409 }
410
Sylwester Nawrocki20702eb2013-08-25 17:27:45 -0300411 src_vb = v4l2_m2m_src_buf_remove(curr_ctx->fh.m2m_ctx);
412 dst_vb = v4l2_m2m_dst_buf_remove(curr_ctx->fh.m2m_ctx);
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300413
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300414 curr_ctx->num_processed++;
415
Hans Verkuil1f923a42014-09-22 09:27:17 -0300416 spin_lock_irqsave(&vim2m_dev->irqlock, flags);
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300417 v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_DONE);
418 v4l2_m2m_buf_done(dst_vb, VB2_BUF_STATE_DONE);
Hans Verkuil1f923a42014-09-22 09:27:17 -0300419 spin_unlock_irqrestore(&vim2m_dev->irqlock, flags);
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300420
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300421 if (curr_ctx->num_processed == curr_ctx->translen
422 || curr_ctx->aborting) {
423 dprintk(curr_ctx->dev, "Finishing transaction\n");
424 curr_ctx->num_processed = 0;
Hans Verkuil1f923a42014-09-22 09:27:17 -0300425 v4l2_m2m_job_finish(vim2m_dev->m2m_dev, curr_ctx->fh.m2m_ctx);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300426 } else {
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300427 device_run(curr_ctx);
428 }
429}
430
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300431/*
432 * video ioctls
433 */
434static int vidioc_querycap(struct file *file, void *priv,
435 struct v4l2_capability *cap)
436{
437 strncpy(cap->driver, MEM2MEM_NAME, sizeof(cap->driver) - 1);
438 strncpy(cap->card, MEM2MEM_NAME, sizeof(cap->card) - 1);
Hans Verkuil72c2af62012-09-14 06:23:12 -0300439 snprintf(cap->bus_info, sizeof(cap->bus_info),
440 "platform:%s", MEM2MEM_NAME);
Mauro Carvalho Chehab79e8c7b2012-08-24 11:25:10 -0300441 cap->device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING;
Hans Verkuilb0d14992012-07-18 10:46:01 -0300442 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300443 return 0;
444}
445
446static int enum_fmt(struct v4l2_fmtdesc *f, u32 type)
447{
448 int i, num;
Hans Verkuil1f923a42014-09-22 09:27:17 -0300449 struct vim2m_fmt *fmt;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300450
451 num = 0;
452
453 for (i = 0; i < NUM_FORMATS; ++i) {
454 if (formats[i].types & type) {
455 /* index-th format of type type found ? */
456 if (num == f->index)
457 break;
458 /* Correct type but haven't reached our index yet,
459 * just increment per-type index */
460 ++num;
461 }
462 }
463
464 if (i < NUM_FORMATS) {
465 /* Format found */
466 fmt = &formats[i];
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300467 f->pixelformat = fmt->fourcc;
468 return 0;
469 }
470
471 /* Format not found */
472 return -EINVAL;
473}
474
475static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
476 struct v4l2_fmtdesc *f)
477{
478 return enum_fmt(f, MEM2MEM_CAPTURE);
479}
480
481static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
482 struct v4l2_fmtdesc *f)
483{
484 return enum_fmt(f, MEM2MEM_OUTPUT);
485}
486
Hans Verkuil1f923a42014-09-22 09:27:17 -0300487static int vidioc_g_fmt(struct vim2m_ctx *ctx, struct v4l2_format *f)
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300488{
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300489 struct vb2_queue *vq;
Hans Verkuil1f923a42014-09-22 09:27:17 -0300490 struct vim2m_q_data *q_data;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300491
Sylwester Nawrocki20702eb2013-08-25 17:27:45 -0300492 vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300493 if (!vq)
494 return -EINVAL;
495
Tomasz Moń9f4161a2012-06-08 04:47:34 -0300496 q_data = get_q_data(ctx, f->type);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300497
498 f->fmt.pix.width = q_data->width;
499 f->fmt.pix.height = q_data->height;
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300500 f->fmt.pix.field = V4L2_FIELD_NONE;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300501 f->fmt.pix.pixelformat = q_data->fmt->fourcc;
502 f->fmt.pix.bytesperline = (q_data->width * q_data->fmt->depth) >> 3;
503 f->fmt.pix.sizeimage = q_data->sizeimage;
Hans Verkuil47556ff2012-07-18 11:33:22 -0300504 f->fmt.pix.colorspace = ctx->colorspace;
Hans Verkuil9f8b3332016-07-18 08:00:20 -0300505 f->fmt.pix.xfer_func = ctx->xfer_func;
506 f->fmt.pix.ycbcr_enc = ctx->ycbcr_enc;
507 f->fmt.pix.quantization = ctx->quant;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300508
509 return 0;
510}
511
512static int vidioc_g_fmt_vid_out(struct file *file, void *priv,
513 struct v4l2_format *f)
514{
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300515 return vidioc_g_fmt(file2ctx(file), f);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300516}
517
518static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
519 struct v4l2_format *f)
520{
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300521 return vidioc_g_fmt(file2ctx(file), f);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300522}
523
Hans Verkuil1f923a42014-09-22 09:27:17 -0300524static int vidioc_try_fmt(struct v4l2_format *f, struct vim2m_fmt *fmt)
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300525{
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300526 /* V4L2 specification suggests the driver corrects the format struct
527 * if any of the dimensions is unsupported */
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300528 if (f->fmt.pix.height < MIN_H)
529 f->fmt.pix.height = MIN_H;
530 else if (f->fmt.pix.height > MAX_H)
531 f->fmt.pix.height = MAX_H;
532
533 if (f->fmt.pix.width < MIN_W)
534 f->fmt.pix.width = MIN_W;
535 else if (f->fmt.pix.width > MAX_W)
536 f->fmt.pix.width = MAX_W;
537
538 f->fmt.pix.width &= ~DIM_ALIGN_MASK;
539 f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3;
540 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
Hans Verkuil5c3112b2014-03-10 10:58:29 -0300541 f->fmt.pix.field = V4L2_FIELD_NONE;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300542
543 return 0;
544}
545
546static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
547 struct v4l2_format *f)
548{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300549 struct vim2m_fmt *fmt;
550 struct vim2m_ctx *ctx = file2ctx(file);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300551
552 fmt = find_format(f);
Hans Verkuil4e8ec0a2014-03-10 10:58:24 -0300553 if (!fmt) {
554 f->fmt.pix.pixelformat = formats[0].fourcc;
555 fmt = find_format(f);
556 }
557 if (!(fmt->types & MEM2MEM_CAPTURE)) {
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300558 v4l2_err(&ctx->dev->v4l2_dev,
559 "Fourcc format (0x%08x) invalid.\n",
560 f->fmt.pix.pixelformat);
561 return -EINVAL;
562 }
Hans Verkuil47556ff2012-07-18 11:33:22 -0300563 f->fmt.pix.colorspace = ctx->colorspace;
Hans Verkuil9f8b3332016-07-18 08:00:20 -0300564 f->fmt.pix.xfer_func = ctx->xfer_func;
565 f->fmt.pix.ycbcr_enc = ctx->ycbcr_enc;
566 f->fmt.pix.quantization = ctx->quant;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300567
568 return vidioc_try_fmt(f, fmt);
569}
570
571static int vidioc_try_fmt_vid_out(struct file *file, void *priv,
572 struct v4l2_format *f)
573{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300574 struct vim2m_fmt *fmt;
575 struct vim2m_ctx *ctx = file2ctx(file);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300576
577 fmt = find_format(f);
Hans Verkuil4e8ec0a2014-03-10 10:58:24 -0300578 if (!fmt) {
579 f->fmt.pix.pixelformat = formats[0].fourcc;
580 fmt = find_format(f);
581 }
582 if (!(fmt->types & MEM2MEM_OUTPUT)) {
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300583 v4l2_err(&ctx->dev->v4l2_dev,
584 "Fourcc format (0x%08x) invalid.\n",
585 f->fmt.pix.pixelformat);
586 return -EINVAL;
587 }
Hans Verkuil47556ff2012-07-18 11:33:22 -0300588 if (!f->fmt.pix.colorspace)
589 f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300590
591 return vidioc_try_fmt(f, fmt);
592}
593
Hans Verkuil1f923a42014-09-22 09:27:17 -0300594static int vidioc_s_fmt(struct vim2m_ctx *ctx, struct v4l2_format *f)
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300595{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300596 struct vim2m_q_data *q_data;
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300597 struct vb2_queue *vq;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300598
Sylwester Nawrocki20702eb2013-08-25 17:27:45 -0300599 vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300600 if (!vq)
601 return -EINVAL;
602
Tomasz Moń9f4161a2012-06-08 04:47:34 -0300603 q_data = get_q_data(ctx, f->type);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300604 if (!q_data)
605 return -EINVAL;
606
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300607 if (vb2_is_busy(vq)) {
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300608 v4l2_err(&ctx->dev->v4l2_dev, "%s queue busy\n", __func__);
Marek Szyprowski07e80302010-12-20 14:39:25 -0300609 return -EBUSY;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300610 }
611
612 q_data->fmt = find_format(f);
613 q_data->width = f->fmt.pix.width;
614 q_data->height = f->fmt.pix.height;
615 q_data->sizeimage = q_data->width * q_data->height
616 * q_data->fmt->depth >> 3;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300617
618 dprintk(ctx->dev,
619 "Setting format for type %d, wxh: %dx%d, fmt: %d\n",
620 f->type, q_data->width, q_data->height, q_data->fmt->fourcc);
621
Marek Szyprowski07e80302010-12-20 14:39:25 -0300622 return 0;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300623}
624
625static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
626 struct v4l2_format *f)
627{
628 int ret;
629
630 ret = vidioc_try_fmt_vid_cap(file, priv, f);
631 if (ret)
632 return ret;
633
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300634 return vidioc_s_fmt(file2ctx(file), f);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300635}
636
637static int vidioc_s_fmt_vid_out(struct file *file, void *priv,
638 struct v4l2_format *f)
639{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300640 struct vim2m_ctx *ctx = file2ctx(file);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300641 int ret;
642
643 ret = vidioc_try_fmt_vid_out(file, priv, f);
644 if (ret)
645 return ret;
646
Hans Verkuil47556ff2012-07-18 11:33:22 -0300647 ret = vidioc_s_fmt(file2ctx(file), f);
Hans Verkuil9f8b3332016-07-18 08:00:20 -0300648 if (!ret) {
Hans Verkuil47556ff2012-07-18 11:33:22 -0300649 ctx->colorspace = f->fmt.pix.colorspace;
Hans Verkuil9f8b3332016-07-18 08:00:20 -0300650 ctx->xfer_func = f->fmt.pix.xfer_func;
651 ctx->ycbcr_enc = f->fmt.pix.ycbcr_enc;
652 ctx->quant = f->fmt.pix.quantization;
653 }
Hans Verkuil47556ff2012-07-18 11:33:22 -0300654 return ret;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300655}
656
Hans Verkuil1f923a42014-09-22 09:27:17 -0300657static int vim2m_s_ctrl(struct v4l2_ctrl *ctrl)
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300658{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300659 struct vim2m_ctx *ctx =
660 container_of(ctrl->handler, struct vim2m_ctx, hdl);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300661
662 switch (ctrl->id) {
Tomasz Moń80072872012-06-12 06:43:49 -0300663 case V4L2_CID_HFLIP:
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300664 if (ctrl->val)
Tomasz Moń80072872012-06-12 06:43:49 -0300665 ctx->mode |= MEM2MEM_HFLIP;
666 else
667 ctx->mode &= ~MEM2MEM_HFLIP;
668 break;
669
670 case V4L2_CID_VFLIP:
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300671 if (ctrl->val)
Tomasz Moń80072872012-06-12 06:43:49 -0300672 ctx->mode |= MEM2MEM_VFLIP;
673 else
674 ctx->mode &= ~MEM2MEM_VFLIP;
675 break;
676
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300677 case V4L2_CID_TRANS_TIME_MSEC:
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300678 ctx->transtime = ctrl->val;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300679 break;
680
681 case V4L2_CID_TRANS_NUM_BUFS:
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300682 ctx->translen = ctrl->val;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300683 break;
684
685 default:
686 v4l2_err(&ctx->dev->v4l2_dev, "Invalid control\n");
687 return -EINVAL;
688 }
689
690 return 0;
691}
692
Hans Verkuil1f923a42014-09-22 09:27:17 -0300693static const struct v4l2_ctrl_ops vim2m_ctrl_ops = {
694 .s_ctrl = vim2m_s_ctrl,
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300695};
696
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300697
Hans Verkuil1f923a42014-09-22 09:27:17 -0300698static const struct v4l2_ioctl_ops vim2m_ioctl_ops = {
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300699 .vidioc_querycap = vidioc_querycap,
700
701 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
702 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
703 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
704 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
705
706 .vidioc_enum_fmt_vid_out = vidioc_enum_fmt_vid_out,
707 .vidioc_g_fmt_vid_out = vidioc_g_fmt_vid_out,
708 .vidioc_try_fmt_vid_out = vidioc_try_fmt_vid_out,
709 .vidioc_s_fmt_vid_out = vidioc_s_fmt_vid_out,
710
Sylwester Nawrocki20702eb2013-08-25 17:27:45 -0300711 .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs,
712 .vidioc_querybuf = v4l2_m2m_ioctl_querybuf,
713 .vidioc_qbuf = v4l2_m2m_ioctl_qbuf,
714 .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf,
Hans Verkuil7bcff1c2015-06-05 11:28:52 -0300715 .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf,
716 .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs,
Hans Verkuilf5294f42014-11-18 09:51:07 -0300717 .vidioc_expbuf = v4l2_m2m_ioctl_expbuf,
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300718
Sylwester Nawrocki20702eb2013-08-25 17:27:45 -0300719 .vidioc_streamon = v4l2_m2m_ioctl_streamon,
720 .vidioc_streamoff = v4l2_m2m_ioctl_streamoff,
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300721
Hans Verkuil97a3c902012-07-18 10:54:59 -0300722 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
723 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300724};
725
726
727/*
728 * Queue operations
729 */
730
Hans Verkuil1f923a42014-09-22 09:27:17 -0300731static int vim2m_queue_setup(struct vb2_queue *vq,
Guennadi Liakhovetskifc714e702011-08-24 10:30:21 -0300732 unsigned int *nbuffers, unsigned int *nplanes,
Hans Verkuil36c0f8b2016-04-15 09:15:05 -0300733 unsigned int sizes[], struct device *alloc_devs[])
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300734{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300735 struct vim2m_ctx *ctx = vb2_get_drv_priv(vq);
736 struct vim2m_q_data *q_data;
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300737 unsigned int size, count = *nbuffers;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300738
Tomasz Moń9f4161a2012-06-08 04:47:34 -0300739 q_data = get_q_data(ctx, vq->type);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300740
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300741 size = q_data->width * q_data->height * q_data->fmt->depth >> 3;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300742
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300743 while (size * count > MEM2MEM_VID_MEM_LIMIT)
744 (count)--;
Hans Verkuildf9ecb0c2015-10-28 00:50:37 -0200745 *nbuffers = count;
746
747 if (*nplanes)
748 return sizes[0] < size ? -EINVAL : 0;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300749
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300750 *nplanes = 1;
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300751 sizes[0] = size;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300752
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300753 dprintk(ctx->dev, "get %d buffer(s) of size %d each.\n", count, size);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300754
755 return 0;
756}
757
Hans Verkuil1f923a42014-09-22 09:27:17 -0300758static int vim2m_buf_prepare(struct vb2_buffer *vb)
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300759{
Junghak Sung2d700712015-09-22 10:30:30 -0300760 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
Hans Verkuil1f923a42014-09-22 09:27:17 -0300761 struct vim2m_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
762 struct vim2m_q_data *q_data;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300763
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300764 dprintk(ctx->dev, "type: %d\n", vb->vb2_queue->type);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300765
Tomasz Moń9f4161a2012-06-08 04:47:34 -0300766 q_data = get_q_data(ctx, vb->vb2_queue->type);
Hans Verkuil5c3112b2014-03-10 10:58:29 -0300767 if (V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) {
Junghak Sung2d700712015-09-22 10:30:30 -0300768 if (vbuf->field == V4L2_FIELD_ANY)
769 vbuf->field = V4L2_FIELD_NONE;
770 if (vbuf->field != V4L2_FIELD_NONE) {
Hans Verkuil5c3112b2014-03-10 10:58:29 -0300771 dprintk(ctx->dev, "%s field isn't supported\n",
772 __func__);
773 return -EINVAL;
774 }
775 }
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300776
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300777 if (vb2_plane_size(vb, 0) < q_data->sizeimage) {
778 dprintk(ctx->dev, "%s data will not fit into plane (%lu < %lu)\n",
779 __func__, vb2_plane_size(vb, 0), (long)q_data->sizeimage);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300780 return -EINVAL;
781 }
782
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300783 vb2_set_plane_payload(vb, 0, q_data->sizeimage);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300784
785 return 0;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300786}
787
Hans Verkuil1f923a42014-09-22 09:27:17 -0300788static void vim2m_buf_queue(struct vb2_buffer *vb)
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300789{
Junghak Sung2d700712015-09-22 10:30:30 -0300790 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
Hans Verkuil1f923a42014-09-22 09:27:17 -0300791 struct vim2m_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
Hans Verkuilca5f5fd2014-03-10 10:58:28 -0300792
Junghak Sung2d700712015-09-22 10:30:30 -0300793 v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
Michael Olbrich0f910bf2011-07-12 09:46:44 -0300794}
795
Hans Verkuil1f923a42014-09-22 09:27:17 -0300796static int vim2m_start_streaming(struct vb2_queue *q, unsigned count)
Hans Verkuilca5f5fd2014-03-10 10:58:28 -0300797{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300798 struct vim2m_ctx *ctx = vb2_get_drv_priv(q);
799 struct vim2m_q_data *q_data = get_q_data(ctx, q->type);
Hans Verkuilca5f5fd2014-03-10 10:58:28 -0300800
801 q_data->sequence = 0;
802 return 0;
803}
804
Hans Verkuil1f923a42014-09-22 09:27:17 -0300805static void vim2m_stop_streaming(struct vb2_queue *q)
Hans Verkuila7736322014-03-10 10:58:27 -0300806{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300807 struct vim2m_ctx *ctx = vb2_get_drv_priv(q);
Junghak Sung2d700712015-09-22 10:30:30 -0300808 struct vb2_v4l2_buffer *vbuf;
Hans Verkuila7736322014-03-10 10:58:27 -0300809 unsigned long flags;
810
Hans Verkuil144bd0e2018-05-21 04:54:56 -0400811 flush_scheduled_work();
Hans Verkuila7736322014-03-10 10:58:27 -0300812 for (;;) {
813 if (V4L2_TYPE_IS_OUTPUT(q->type))
Junghak Sung2d700712015-09-22 10:30:30 -0300814 vbuf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
Hans Verkuila7736322014-03-10 10:58:27 -0300815 else
Junghak Sung2d700712015-09-22 10:30:30 -0300816 vbuf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
817 if (vbuf == NULL)
Hans Verkuile37559b2014-04-17 02:47:21 -0300818 return;
Hans Verkuil86b93b22018-05-21 04:54:57 -0400819 v4l2_ctrl_request_complete(vbuf->vb2_buf.req_obj.req,
820 &ctx->hdl);
Hans Verkuila7736322014-03-10 10:58:27 -0300821 spin_lock_irqsave(&ctx->dev->irqlock, flags);
Junghak Sung2d700712015-09-22 10:30:30 -0300822 v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_ERROR);
Hans Verkuila7736322014-03-10 10:58:27 -0300823 spin_unlock_irqrestore(&ctx->dev->irqlock, flags);
824 }
Hans Verkuila7736322014-03-10 10:58:27 -0300825}
826
Hans Verkuil86b93b22018-05-21 04:54:57 -0400827static void vim2m_buf_request_complete(struct vb2_buffer *vb)
828{
829 struct vim2m_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
830
831 v4l2_ctrl_request_complete(vb->req_obj.req, &ctx->hdl);
832}
833
Julia Lawallb7b361f2016-09-08 20:59:10 -0300834static const struct vb2_ops vim2m_qops = {
Hans Verkuil1f923a42014-09-22 09:27:17 -0300835 .queue_setup = vim2m_queue_setup,
836 .buf_prepare = vim2m_buf_prepare,
837 .buf_queue = vim2m_buf_queue,
838 .start_streaming = vim2m_start_streaming,
839 .stop_streaming = vim2m_stop_streaming,
Sylwester Nawrocki20702eb2013-08-25 17:27:45 -0300840 .wait_prepare = vb2_ops_wait_prepare,
841 .wait_finish = vb2_ops_wait_finish,
Hans Verkuil86b93b22018-05-21 04:54:57 -0400842 .buf_request_complete = vim2m_buf_request_complete,
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300843};
844
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300845static int queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq)
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300846{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300847 struct vim2m_ctx *ctx = priv;
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300848 int ret;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300849
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300850 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
Hans Verkuil782f36c2014-03-10 10:58:26 -0300851 src_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300852 src_vq->drv_priv = ctx;
853 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
Hans Verkuil1f923a42014-09-22 09:27:17 -0300854 src_vq->ops = &vim2m_qops;
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300855 src_vq->mem_ops = &vb2_vmalloc_memops;
Sakari Ailusade48682014-02-25 19:12:19 -0300856 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
Sylwester Nawrocki20702eb2013-08-25 17:27:45 -0300857 src_vq->lock = &ctx->dev->dev_mutex;
Hans Verkuile5079cf2018-08-23 10:18:35 -0400858 src_vq->supports_requests = true;
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300859
860 ret = vb2_queue_init(src_vq);
861 if (ret)
862 return ret;
863
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300864 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
Hans Verkuil782f36c2014-03-10 10:58:26 -0300865 dst_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300866 dst_vq->drv_priv = ctx;
867 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
Hans Verkuil1f923a42014-09-22 09:27:17 -0300868 dst_vq->ops = &vim2m_qops;
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300869 dst_vq->mem_ops = &vb2_vmalloc_memops;
Sakari Ailusade48682014-02-25 19:12:19 -0300870 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
Sylwester Nawrocki20702eb2013-08-25 17:27:45 -0300871 dst_vq->lock = &ctx->dev->dev_mutex;
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300872
873 return vb2_queue_init(dst_vq);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300874}
875
Hans Verkuil1f923a42014-09-22 09:27:17 -0300876static const struct v4l2_ctrl_config vim2m_ctrl_trans_time_msec = {
877 .ops = &vim2m_ctrl_ops,
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300878 .id = V4L2_CID_TRANS_TIME_MSEC,
879 .name = "Transaction Time (msec)",
880 .type = V4L2_CTRL_TYPE_INTEGER,
Hans Verkuil43405832014-03-10 10:58:23 -0300881 .def = MEM2MEM_DEF_TRANSTIME,
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300882 .min = 1,
883 .max = 10001,
Hans Verkuil43405832014-03-10 10:58:23 -0300884 .step = 1,
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300885};
886
Hans Verkuil1f923a42014-09-22 09:27:17 -0300887static const struct v4l2_ctrl_config vim2m_ctrl_trans_num_bufs = {
888 .ops = &vim2m_ctrl_ops,
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300889 .id = V4L2_CID_TRANS_NUM_BUFS,
890 .name = "Buffers Per Transaction",
891 .type = V4L2_CTRL_TYPE_INTEGER,
892 .def = 1,
893 .min = 1,
894 .max = MEM2MEM_DEF_NUM_BUFS,
895 .step = 1,
896};
897
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300898/*
899 * File operations
900 */
Hans Verkuil1f923a42014-09-22 09:27:17 -0300901static int vim2m_open(struct file *file)
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300902{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300903 struct vim2m_dev *dev = video_drvdata(file);
904 struct vim2m_ctx *ctx = NULL;
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300905 struct v4l2_ctrl_handler *hdl;
Hans Verkuilf4694032012-07-31 03:51:25 -0300906 int rc = 0;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300907
Hans Verkuilf4694032012-07-31 03:51:25 -0300908 if (mutex_lock_interruptible(&dev->dev_mutex))
909 return -ERESTARTSYS;
Sachin Kamat56ed2212012-09-24 02:17:46 -0300910 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
Hans Verkuilf4694032012-07-31 03:51:25 -0300911 if (!ctx) {
912 rc = -ENOMEM;
913 goto open_unlock;
914 }
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300915
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300916 v4l2_fh_init(&ctx->fh, video_devdata(file));
917 file->private_data = &ctx->fh;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300918 ctx->dev = dev;
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300919 hdl = &ctx->hdl;
920 v4l2_ctrl_handler_init(hdl, 4);
Hans Verkuil1f923a42014-09-22 09:27:17 -0300921 v4l2_ctrl_new_std(hdl, &vim2m_ctrl_ops, V4L2_CID_HFLIP, 0, 1, 1, 0);
922 v4l2_ctrl_new_std(hdl, &vim2m_ctrl_ops, V4L2_CID_VFLIP, 0, 1, 1, 0);
923 v4l2_ctrl_new_custom(hdl, &vim2m_ctrl_trans_time_msec, NULL);
924 v4l2_ctrl_new_custom(hdl, &vim2m_ctrl_trans_num_bufs, NULL);
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300925 if (hdl->error) {
Dan Carpentera7bd7752012-08-14 02:58:56 -0300926 rc = hdl->error;
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300927 v4l2_ctrl_handler_free(hdl);
Santosh Kumar Singh7c13a4d2016-12-19 14:12:46 -0200928 kfree(ctx);
Dan Carpentera7bd7752012-08-14 02:58:56 -0300929 goto open_unlock;
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300930 }
931 ctx->fh.ctrl_handler = hdl;
932 v4l2_ctrl_handler_setup(hdl);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300933
Tomasz Moń9f4161a2012-06-08 04:47:34 -0300934 ctx->q_data[V4L2_M2M_SRC].fmt = &formats[0];
Hans Verkuil47556ff2012-07-18 11:33:22 -0300935 ctx->q_data[V4L2_M2M_SRC].width = 640;
936 ctx->q_data[V4L2_M2M_SRC].height = 480;
937 ctx->q_data[V4L2_M2M_SRC].sizeimage =
938 ctx->q_data[V4L2_M2M_SRC].width *
939 ctx->q_data[V4L2_M2M_SRC].height *
940 (ctx->q_data[V4L2_M2M_SRC].fmt->depth >> 3);
941 ctx->q_data[V4L2_M2M_DST] = ctx->q_data[V4L2_M2M_SRC];
942 ctx->colorspace = V4L2_COLORSPACE_REC709;
Tomasz Moń9f4161a2012-06-08 04:47:34 -0300943
Sylwester Nawrocki20702eb2013-08-25 17:27:45 -0300944 ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init);
Marek Szyprowskid80ee382011-01-12 06:50:55 -0300945
Sylwester Nawrocki20702eb2013-08-25 17:27:45 -0300946 if (IS_ERR(ctx->fh.m2m_ctx)) {
947 rc = PTR_ERR(ctx->fh.m2m_ctx);
Dan Carpenter16ee9bb12010-05-05 02:58:57 -0300948
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300949 v4l2_ctrl_handler_free(hdl);
Santosh Kumar Singh7c13a4d2016-12-19 14:12:46 -0200950 v4l2_fh_exit(&ctx->fh);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300951 kfree(ctx);
Hans Verkuilf4694032012-07-31 03:51:25 -0300952 goto open_unlock;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300953 }
954
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300955 v4l2_fh_add(&ctx->fh);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300956 atomic_inc(&dev->num_inst);
957
Sylwester Nawrocki20702eb2013-08-25 17:27:45 -0300958 dprintk(dev, "Created instance: %p, m2m_ctx: %p\n",
959 ctx, ctx->fh.m2m_ctx);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300960
Hans Verkuilf4694032012-07-31 03:51:25 -0300961open_unlock:
962 mutex_unlock(&dev->dev_mutex);
Dan Carpentera7bd7752012-08-14 02:58:56 -0300963 return rc;
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300964}
965
Hans Verkuil1f923a42014-09-22 09:27:17 -0300966static int vim2m_release(struct file *file)
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300967{
Hans Verkuil1f923a42014-09-22 09:27:17 -0300968 struct vim2m_dev *dev = video_drvdata(file);
969 struct vim2m_ctx *ctx = file2ctx(file);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300970
971 dprintk(dev, "Releasing instance %p\n", ctx);
972
Hans Verkuild3dd59c2012-07-18 10:35:37 -0300973 v4l2_fh_del(&ctx->fh);
974 v4l2_fh_exit(&ctx->fh);
975 v4l2_ctrl_handler_free(&ctx->hdl);
Hans Verkuilf4694032012-07-31 03:51:25 -0300976 mutex_lock(&dev->dev_mutex);
Sylwester Nawrocki20702eb2013-08-25 17:27:45 -0300977 v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
Hans Verkuilf4694032012-07-31 03:51:25 -0300978 mutex_unlock(&dev->dev_mutex);
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300979 kfree(ctx);
980
981 atomic_dec(&dev->num_inst);
982
983 return 0;
984}
985
Hans Verkuil1f923a42014-09-22 09:27:17 -0300986static const struct v4l2_file_operations vim2m_fops = {
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300987 .owner = THIS_MODULE,
Hans Verkuil1f923a42014-09-22 09:27:17 -0300988 .open = vim2m_open,
989 .release = vim2m_release,
Sylwester Nawrocki20702eb2013-08-25 17:27:45 -0300990 .poll = v4l2_m2m_fop_poll,
Marek Szyprowski07e80302010-12-20 14:39:25 -0300991 .unlocked_ioctl = video_ioctl2,
Sylwester Nawrocki20702eb2013-08-25 17:27:45 -0300992 .mmap = v4l2_m2m_fop_mmap,
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300993};
994
Bhumika Goyal53031352017-08-26 08:57:26 -0400995static const struct video_device vim2m_videodev = {
Pawel Osciak96d8eab2010-04-23 05:38:38 -0300996 .name = MEM2MEM_NAME,
Hans Verkuil954f3402012-09-05 06:05:50 -0300997 .vfl_dir = VFL_DIR_M2M,
Hans Verkuil1f923a42014-09-22 09:27:17 -0300998 .fops = &vim2m_fops,
999 .ioctl_ops = &vim2m_ioctl_ops,
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001000 .minor = -1,
Hans Verkuil09365422015-03-09 13:33:56 -03001001 .release = video_device_release_empty,
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001002};
1003
Julia Lawall86ab0b12017-08-06 04:25:19 -04001004static const struct v4l2_m2m_ops m2m_ops = {
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001005 .device_run = device_run,
1006 .job_ready = job_ready,
1007 .job_abort = job_abort,
1008};
1009
Hans Verkuil86b93b22018-05-21 04:54:57 -04001010static const struct media_device_ops m2m_media_ops = {
1011 .req_validate = vb2_request_validate,
1012 .req_queue = vb2_m2m_request_queue,
1013};
1014
Hans Verkuil1f923a42014-09-22 09:27:17 -03001015static int vim2m_probe(struct platform_device *pdev)
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001016{
Hans Verkuil1f923a42014-09-22 09:27:17 -03001017 struct vim2m_dev *dev;
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001018 struct video_device *vfd;
1019 int ret;
1020
Sachin Kamat38a79962012-09-24 02:17:48 -03001021 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001022 if (!dev)
1023 return -ENOMEM;
1024
1025 spin_lock_init(&dev->irqlock);
1026
1027 ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
1028 if (ret)
Sachin Kamat38a79962012-09-24 02:17:48 -03001029 return ret;
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001030
1031 atomic_set(&dev->num_inst, 0);
1032 mutex_init(&dev->dev_mutex);
1033
Hans Verkuil09365422015-03-09 13:33:56 -03001034 dev->vfd = vim2m_videodev;
1035 vfd = &dev->vfd;
Marek Szyprowski07e80302010-12-20 14:39:25 -03001036 vfd->lock = &dev->dev_mutex;
Hans Verkuil8f484d82013-06-27 02:44:04 -03001037 vfd->v4l2_dev = &dev->v4l2_dev;
Hans Verkuil144bd0e2018-05-21 04:54:56 -04001038 INIT_DELAYED_WORK(&dev->work_run, device_work);
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001039
1040 ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
1041 if (ret) {
1042 v4l2_err(&dev->v4l2_dev, "Failed to register video device\n");
Hans Verkuile35f7022018-07-02 11:36:06 -04001043 goto unreg_v4l2;
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001044 }
1045
1046 video_set_drvdata(vfd, dev);
Hans Verkuil8f484d82013-06-27 02:44:04 -03001047 v4l2_info(&dev->v4l2_dev,
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001048 "Device registered as /dev/video%d\n", vfd->num);
1049
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001050 platform_set_drvdata(pdev, dev);
1051
1052 dev->m2m_dev = v4l2_m2m_init(&m2m_ops);
1053 if (IS_ERR(dev->m2m_dev)) {
1054 v4l2_err(&dev->v4l2_dev, "Failed to init mem2mem device\n");
1055 ret = PTR_ERR(dev->m2m_dev);
Hans Verkuile35f7022018-07-02 11:36:06 -04001056 goto unreg_dev;
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001057 }
1058
Hans Verkuile35f7022018-07-02 11:36:06 -04001059#ifdef CONFIG_MEDIA_CONTROLLER
1060 dev->mdev.dev = &pdev->dev;
1061 strlcpy(dev->mdev.model, "vim2m", sizeof(dev->mdev.model));
1062 media_device_init(&dev->mdev);
Hans Verkuil86b93b22018-05-21 04:54:57 -04001063 dev->mdev.ops = &m2m_media_ops;
Hans Verkuile35f7022018-07-02 11:36:06 -04001064 dev->v4l2_dev.mdev = &dev->mdev;
1065
1066 ret = v4l2_m2m_register_media_controller(dev->m2m_dev,
1067 vfd, MEDIA_ENT_F_PROC_VIDEO_SCALER);
1068 if (ret) {
1069 v4l2_err(&dev->v4l2_dev, "Failed to init mem2mem media controller\n");
1070 goto unreg_m2m;
1071 }
1072
1073 ret = media_device_register(&dev->mdev);
1074 if (ret) {
1075 v4l2_err(&dev->v4l2_dev, "Failed to register mem2mem media device\n");
1076 goto unreg_m2m_mc;
1077 }
1078#endif
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001079 return 0;
1080
Hans Verkuile35f7022018-07-02 11:36:06 -04001081#ifdef CONFIG_MEDIA_CONTROLLER
1082unreg_m2m_mc:
1083 v4l2_m2m_unregister_media_controller(dev->m2m_dev);
1084unreg_m2m:
Sachin Kamatb7e13ef2012-09-24 02:17:45 -03001085 v4l2_m2m_release(dev->m2m_dev);
Hans Verkuile35f7022018-07-02 11:36:06 -04001086#endif
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001087unreg_dev:
Hans Verkuile35f7022018-07-02 11:36:06 -04001088 video_unregister_device(&dev->vfd);
1089unreg_v4l2:
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001090 v4l2_device_unregister(&dev->v4l2_dev);
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001091
1092 return ret;
1093}
1094
Hans Verkuil1f923a42014-09-22 09:27:17 -03001095static int vim2m_remove(struct platform_device *pdev)
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001096{
Hans Verkuil1f923a42014-09-22 09:27:17 -03001097 struct vim2m_dev *dev = platform_get_drvdata(pdev);
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001098
Hans Verkuil1f923a42014-09-22 09:27:17 -03001099 v4l2_info(&dev->v4l2_dev, "Removing " MEM2MEM_NAME);
Hans Verkuile35f7022018-07-02 11:36:06 -04001100
1101#ifdef CONFIG_MEDIA_CONTROLLER
1102 media_device_unregister(&dev->mdev);
1103 v4l2_m2m_unregister_media_controller(dev->m2m_dev);
1104 media_device_cleanup(&dev->mdev);
1105#endif
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001106 v4l2_m2m_release(dev->m2m_dev);
Hans Verkuil09365422015-03-09 13:33:56 -03001107 video_unregister_device(&dev->vfd);
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001108 v4l2_device_unregister(&dev->v4l2_dev);
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001109
1110 return 0;
1111}
1112
Hans Verkuil1f923a42014-09-22 09:27:17 -03001113static struct platform_driver vim2m_pdrv = {
1114 .probe = vim2m_probe,
1115 .remove = vim2m_remove,
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001116 .driver = {
1117 .name = MEM2MEM_NAME,
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001118 },
1119};
1120
Hans Verkuil1f923a42014-09-22 09:27:17 -03001121static void __exit vim2m_exit(void)
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001122{
Hans Verkuil1f923a42014-09-22 09:27:17 -03001123 platform_driver_unregister(&vim2m_pdrv);
1124 platform_device_unregister(&vim2m_pdev);
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001125}
1126
Hans Verkuil1f923a42014-09-22 09:27:17 -03001127static int __init vim2m_init(void)
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001128{
1129 int ret;
1130
Hans Verkuil1f923a42014-09-22 09:27:17 -03001131 ret = platform_device_register(&vim2m_pdev);
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001132 if (ret)
1133 return ret;
1134
Hans Verkuil1f923a42014-09-22 09:27:17 -03001135 ret = platform_driver_register(&vim2m_pdrv);
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001136 if (ret)
Hans Verkuil1f923a42014-09-22 09:27:17 -03001137 platform_device_unregister(&vim2m_pdev);
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001138
Niklas Söderlundb20b51f2015-12-25 15:25:16 -02001139 return ret;
Pawel Osciak96d8eab2010-04-23 05:38:38 -03001140}
1141
Hans Verkuil1f923a42014-09-22 09:27:17 -03001142module_init(vim2m_init);
1143module_exit(vim2m_exit);