Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1 | /* |
| 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 Verkuil | 144bd0e | 2018-05-21 04:54:56 -0400 | [diff] [blame] | 6 | * destination, processes the data and issues an "irq" (simulated by a delayed |
| 7 | * workqueue). |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 8 | * 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 Osciak | 9507208 | 2011-03-13 15:23:32 -0300 | [diff] [blame] | 12 | * Pawel Osciak, <pawel@osciak.com> |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 13 | * 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 Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 23 | #include <linux/sched.h> |
Randy Dunlap | 6b46c39 | 2010-05-07 15:22:26 -0300 | [diff] [blame] | 24 | #include <linux/slab.h> |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 25 | |
| 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 Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 30 | #include <media/v4l2-ctrls.h> |
Hans Verkuil | 97a3c90 | 2012-07-18 10:54:59 -0300 | [diff] [blame] | 31 | #include <media/v4l2-event.h> |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 32 | #include <media/videobuf2-vmalloc.h> |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 33 | |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 34 | MODULE_DESCRIPTION("Virtual device for mem2mem framework testing"); |
Pawel Osciak | 9507208 | 2011-03-13 15:23:32 -0300 | [diff] [blame] | 35 | MODULE_AUTHOR("Pawel Osciak, <pawel@osciak.com>"); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 36 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 1990d50 | 2011-06-24 14:45:49 -0300 | [diff] [blame] | 37 | MODULE_VERSION("0.1.1"); |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 38 | MODULE_ALIAS("mem2mem_testdev"); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 39 | |
Hans Verkuil | d95d7c6 | 2013-04-17 03:04:10 -0300 | [diff] [blame] | 40 | static unsigned debug; |
| 41 | module_param(debug, uint, 0644); |
| 42 | MODULE_PARM_DESC(debug, "activates debug info"); |
| 43 | |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 44 | #define MIN_W 32 |
| 45 | #define MIN_H 32 |
| 46 | #define MAX_W 640 |
| 47 | #define MAX_H 480 |
Guennadi Liakhovetski | 9ce3ce4d4 | 2012-04-27 04:16:46 -0300 | [diff] [blame] | 48 | #define DIM_ALIGN_MASK 7 /* 8-byte alignment for line length */ |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 49 | |
| 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 Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 54 | #define MEM2MEM_NAME "vim2m" |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 55 | |
| 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 Verkuil | 4340583 | 2014-03-10 10:58:23 -0300 | [diff] [blame] | 62 | #define MEM2MEM_DEF_TRANSTIME 40 |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 63 | #define MEM2MEM_COLOR_STEP (0xff >> 4) |
| 64 | #define MEM2MEM_NUM_TILES 8 |
| 65 | |
Tomasz Moń | 8007287 | 2012-06-12 06:43:49 -0300 | [diff] [blame] | 66 | /* Flags that indicate processing mode */ |
| 67 | #define MEM2MEM_HFLIP (1 << 0) |
| 68 | #define MEM2MEM_VFLIP (1 << 1) |
| 69 | |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 70 | #define dprintk(dev, fmt, arg...) \ |
Hans Verkuil | d95d7c6 | 2013-04-17 03:04:10 -0300 | [diff] [blame] | 71 | v4l2_dbg(1, debug, &dev->v4l2_dev, "%s: " fmt, __func__, ## arg) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 72 | |
| 73 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 74 | static void vim2m_dev_release(struct device *dev) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 75 | {} |
| 76 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 77 | static struct platform_device vim2m_pdev = { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 78 | .name = MEM2MEM_NAME, |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 79 | .dev.release = vim2m_dev_release, |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 80 | }; |
| 81 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 82 | struct vim2m_fmt { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 83 | u32 fourcc; |
| 84 | int depth; |
| 85 | /* Types the format can be used for */ |
| 86 | u32 types; |
| 87 | }; |
| 88 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 89 | static struct vim2m_fmt formats[] = { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 90 | { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 91 | .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 Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 97 | .fourcc = V4L2_PIX_FMT_YUYV, |
| 98 | .depth = 16, |
| 99 | /* Output-only format */ |
| 100 | .types = MEM2MEM_OUTPUT, |
| 101 | }, |
| 102 | }; |
| 103 | |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 104 | #define NUM_FORMATS ARRAY_SIZE(formats) |
| 105 | |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 106 | /* Per-queue, driver-specific private data */ |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 107 | struct vim2m_q_data { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 108 | unsigned int width; |
| 109 | unsigned int height; |
| 110 | unsigned int sizeimage; |
Hans Verkuil | ca5f5fd | 2014-03-10 10:58:28 -0300 | [diff] [blame] | 111 | unsigned int sequence; |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 112 | struct vim2m_fmt *fmt; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | enum { |
| 116 | V4L2_M2M_SRC = 0, |
| 117 | V4L2_M2M_DST = 1, |
| 118 | }; |
| 119 | |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 120 | #define V4L2_CID_TRANS_TIME_MSEC (V4L2_CID_USER_BASE + 0x1000) |
| 121 | #define V4L2_CID_TRANS_NUM_BUFS (V4L2_CID_USER_BASE + 0x1001) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 122 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 123 | static struct vim2m_fmt *find_format(struct v4l2_format *f) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 124 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 125 | struct vim2m_fmt *fmt; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 126 | 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 Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 140 | struct vim2m_dev { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 141 | struct v4l2_device v4l2_dev; |
Hans Verkuil | 0936542 | 2015-03-09 13:33:56 -0300 | [diff] [blame] | 142 | struct video_device vfd; |
Hans Verkuil | e35f702 | 2018-07-02 11:36:06 -0400 | [diff] [blame] | 143 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 144 | struct media_device mdev; |
| 145 | #endif |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 146 | |
| 147 | atomic_t num_inst; |
| 148 | struct mutex dev_mutex; |
| 149 | spinlock_t irqlock; |
| 150 | |
Hans Verkuil | 144bd0e | 2018-05-21 04:54:56 -0400 | [diff] [blame] | 151 | struct delayed_work work_run; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 152 | |
| 153 | struct v4l2_m2m_dev *m2m_dev; |
| 154 | }; |
| 155 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 156 | struct vim2m_ctx { |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 157 | struct v4l2_fh fh; |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 158 | struct vim2m_dev *dev; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 159 | |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 160 | struct v4l2_ctrl_handler hdl; |
| 161 | |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 162 | /* 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ń | 8007287 | 2012-06-12 06:43:49 -0300 | [diff] [blame] | 173 | /* Processing mode */ |
| 174 | int mode; |
| 175 | |
Hans Verkuil | 47556ff | 2012-07-18 11:33:22 -0300 | [diff] [blame] | 176 | enum v4l2_colorspace colorspace; |
Hans Verkuil | 9f8b333 | 2016-07-18 08:00:20 -0300 | [diff] [blame] | 177 | enum v4l2_ycbcr_encoding ycbcr_enc; |
| 178 | enum v4l2_xfer_func xfer_func; |
| 179 | enum v4l2_quantization quant; |
Hans Verkuil | 47556ff | 2012-07-18 11:33:22 -0300 | [diff] [blame] | 180 | |
Tomasz Moń | 9f4161a | 2012-06-08 04:47:34 -0300 | [diff] [blame] | 181 | /* Source and destination queue data */ |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 182 | struct vim2m_q_data q_data[2]; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 183 | }; |
| 184 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 185 | static inline struct vim2m_ctx *file2ctx(struct file *file) |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 186 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 187 | return container_of(file->private_data, struct vim2m_ctx, fh); |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 188 | } |
| 189 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 190 | static struct vim2m_q_data *get_q_data(struct vim2m_ctx *ctx, |
Tomasz Moń | 9f4161a | 2012-06-08 04:47:34 -0300 | [diff] [blame] | 191 | 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 Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 205 | static int device_process(struct vim2m_ctx *ctx, |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 206 | struct vb2_v4l2_buffer *in_vb, |
| 207 | struct vb2_v4l2_buffer *out_vb) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 208 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 209 | struct vim2m_dev *dev = ctx->dev; |
| 210 | struct vim2m_q_data *q_data; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 211 | u8 *p_in, *p_out; |
| 212 | int x, y, t, w; |
| 213 | int tile_w, bytes_left; |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 214 | int width, height, bytesperline; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 215 | |
Tomasz Moń | 9f4161a | 2012-06-08 04:47:34 -0300 | [diff] [blame] | 216 | q_data = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 217 | |
| 218 | width = q_data->width; |
| 219 | height = q_data->height; |
| 220 | bytesperline = (q_data->width * q_data->fmt->depth) >> 3; |
| 221 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 222 | p_in = vb2_plane_vaddr(&in_vb->vb2_buf, 0); |
| 223 | p_out = vb2_plane_vaddr(&out_vb->vb2_buf, 0); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 224 | 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 Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 230 | if (vb2_plane_size(&in_vb->vb2_buf, 0) > |
| 231 | vb2_plane_size(&out_vb->vb2_buf, 0)) { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 232 | v4l2_err(&dev->v4l2_dev, "Output buffer is too small\n"); |
| 233 | return -EINVAL; |
| 234 | } |
| 235 | |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 236 | tile_w = (width * (q_data[V4L2_M2M_DST].fmt->depth >> 3)) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 237 | / MEM2MEM_NUM_TILES; |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 238 | bytes_left = bytesperline - tile_w * MEM2MEM_NUM_TILES; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 239 | w = 0; |
| 240 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 241 | out_vb->sequence = |
| 242 | get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE)->sequence++; |
| 243 | in_vb->sequence = q_data->sequence++; |
Hans Verkuil | 8682469 | 2019-01-11 06:43:12 -0500 | [diff] [blame] | 244 | v4l2_m2m_buf_copy_data(in_vb, out_vb, true); |
Hans Verkuil | d95d7c6 | 2013-04-17 03:04:10 -0300 | [diff] [blame] | 245 | |
Tomasz Moń | 8007287 | 2012-06-12 06:43:49 -0300 | [diff] [blame] | 246 | switch (ctx->mode) { |
| 247 | case MEM2MEM_HFLIP | MEM2MEM_VFLIP: |
| 248 | p_out += bytesperline * height - bytes_left; |
| 249 | for (y = 0; y < height; ++y) { |
| 250 | for (t = 0; t < MEM2MEM_NUM_TILES; ++t) { |
| 251 | if (w & 0x1) { |
| 252 | for (x = 0; x < tile_w; ++x) |
| 253 | *--p_out = *p_in++ + |
| 254 | MEM2MEM_COLOR_STEP; |
| 255 | } else { |
| 256 | for (x = 0; x < tile_w; ++x) |
| 257 | *--p_out = *p_in++ - |
| 258 | MEM2MEM_COLOR_STEP; |
| 259 | } |
| 260 | ++w; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 261 | } |
Tomasz Moń | 8007287 | 2012-06-12 06:43:49 -0300 | [diff] [blame] | 262 | p_in += bytes_left; |
| 263 | p_out -= bytes_left; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 264 | } |
Tomasz Moń | 8007287 | 2012-06-12 06:43:49 -0300 | [diff] [blame] | 265 | break; |
| 266 | |
| 267 | case MEM2MEM_HFLIP: |
| 268 | for (y = 0; y < height; ++y) { |
| 269 | p_out += MEM2MEM_NUM_TILES * tile_w; |
| 270 | for (t = 0; t < MEM2MEM_NUM_TILES; ++t) { |
| 271 | if (w & 0x01) { |
| 272 | for (x = 0; x < tile_w; ++x) |
| 273 | *--p_out = *p_in++ + |
| 274 | MEM2MEM_COLOR_STEP; |
| 275 | } else { |
| 276 | for (x = 0; x < tile_w; ++x) |
| 277 | *--p_out = *p_in++ - |
| 278 | MEM2MEM_COLOR_STEP; |
| 279 | } |
| 280 | ++w; |
| 281 | } |
| 282 | p_in += bytes_left; |
| 283 | p_out += bytesperline; |
| 284 | } |
| 285 | break; |
| 286 | |
| 287 | case MEM2MEM_VFLIP: |
| 288 | p_out += bytesperline * (height - 1); |
| 289 | for (y = 0; y < height; ++y) { |
| 290 | for (t = 0; t < MEM2MEM_NUM_TILES; ++t) { |
| 291 | if (w & 0x1) { |
| 292 | for (x = 0; x < tile_w; ++x) |
| 293 | *p_out++ = *p_in++ + |
| 294 | MEM2MEM_COLOR_STEP; |
| 295 | } else { |
| 296 | for (x = 0; x < tile_w; ++x) |
| 297 | *p_out++ = *p_in++ - |
| 298 | MEM2MEM_COLOR_STEP; |
| 299 | } |
| 300 | ++w; |
| 301 | } |
| 302 | p_in += bytes_left; |
| 303 | p_out += bytes_left - 2 * bytesperline; |
| 304 | } |
| 305 | break; |
| 306 | |
| 307 | default: |
| 308 | for (y = 0; y < height; ++y) { |
| 309 | for (t = 0; t < MEM2MEM_NUM_TILES; ++t) { |
| 310 | if (w & 0x1) { |
| 311 | for (x = 0; x < tile_w; ++x) |
| 312 | *p_out++ = *p_in++ + |
| 313 | MEM2MEM_COLOR_STEP; |
| 314 | } else { |
| 315 | for (x = 0; x < tile_w; ++x) |
| 316 | *p_out++ = *p_in++ - |
| 317 | MEM2MEM_COLOR_STEP; |
| 318 | } |
| 319 | ++w; |
| 320 | } |
| 321 | p_in += bytes_left; |
| 322 | p_out += bytes_left; |
| 323 | } |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 329 | /* |
| 330 | * mem2mem callbacks |
| 331 | */ |
| 332 | |
Mauro Carvalho Chehab | cba862d | 2017-11-29 08:33:45 -0500 | [diff] [blame] | 333 | /* |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 334 | * job_ready() - check whether an instance is ready to be scheduled to run |
| 335 | */ |
| 336 | static int job_ready(void *priv) |
| 337 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 338 | struct vim2m_ctx *ctx = priv; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 339 | |
Sylwester Nawrocki | 20702eb | 2013-08-25 17:27:45 -0300 | [diff] [blame] | 340 | if (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) < ctx->translen |
| 341 | || v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx) < ctx->translen) { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 342 | dprintk(ctx->dev, "Not enough buffers available\n"); |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | return 1; |
| 347 | } |
| 348 | |
| 349 | static void job_abort(void *priv) |
| 350 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 351 | struct vim2m_ctx *ctx = priv; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 352 | |
| 353 | /* Will cancel the transaction in the next interrupt handler */ |
| 354 | ctx->aborting = 1; |
| 355 | } |
| 356 | |
| 357 | /* device_run() - prepares and starts the device |
| 358 | * |
| 359 | * This simulates all the immediate preparations required before starting |
| 360 | * a device. This will be called by the framework when it decides to schedule |
| 361 | * a particular instance. |
| 362 | */ |
| 363 | static void device_run(void *priv) |
| 364 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 365 | struct vim2m_ctx *ctx = priv; |
| 366 | struct vim2m_dev *dev = ctx->dev; |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 367 | struct vb2_v4l2_buffer *src_buf, *dst_buf; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 368 | |
Sylwester Nawrocki | 20702eb | 2013-08-25 17:27:45 -0300 | [diff] [blame] | 369 | src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); |
| 370 | dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 371 | |
Hans Verkuil | 86b93b2 | 2018-05-21 04:54:57 -0400 | [diff] [blame] | 372 | /* Apply request controls if any */ |
| 373 | v4l2_ctrl_request_setup(src_buf->vb2_buf.req_obj.req, |
| 374 | &ctx->hdl); |
| 375 | |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 376 | device_process(ctx, src_buf, dst_buf); |
| 377 | |
Hans Verkuil | 86b93b2 | 2018-05-21 04:54:57 -0400 | [diff] [blame] | 378 | /* Complete request controls if any */ |
| 379 | v4l2_ctrl_request_complete(src_buf->vb2_buf.req_obj.req, |
| 380 | &ctx->hdl); |
| 381 | |
Hans Verkuil | 144bd0e | 2018-05-21 04:54:56 -0400 | [diff] [blame] | 382 | /* Run delayed work, which simulates a hardware irq */ |
| 383 | schedule_delayed_work(&dev->work_run, msecs_to_jiffies(ctx->transtime)); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 384 | } |
| 385 | |
Hans Verkuil | 144bd0e | 2018-05-21 04:54:56 -0400 | [diff] [blame] | 386 | static void device_work(struct work_struct *w) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 387 | { |
Hans Verkuil | 144bd0e | 2018-05-21 04:54:56 -0400 | [diff] [blame] | 388 | struct vim2m_dev *vim2m_dev = |
| 389 | container_of(w, struct vim2m_dev, work_run.work); |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 390 | struct vim2m_ctx *curr_ctx; |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 391 | struct vb2_v4l2_buffer *src_vb, *dst_vb; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 392 | unsigned long flags; |
| 393 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 394 | curr_ctx = v4l2_m2m_get_curr_priv(vim2m_dev->m2m_dev); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 395 | |
| 396 | if (NULL == curr_ctx) { |
Sachin Kamat | 26fdcf0 | 2012-09-24 02:17:47 -0300 | [diff] [blame] | 397 | pr_err("Instance released before the end of transaction\n"); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 398 | return; |
| 399 | } |
| 400 | |
Sylwester Nawrocki | 20702eb | 2013-08-25 17:27:45 -0300 | [diff] [blame] | 401 | src_vb = v4l2_m2m_src_buf_remove(curr_ctx->fh.m2m_ctx); |
| 402 | dst_vb = v4l2_m2m_dst_buf_remove(curr_ctx->fh.m2m_ctx); |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 403 | |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 404 | curr_ctx->num_processed++; |
| 405 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 406 | spin_lock_irqsave(&vim2m_dev->irqlock, flags); |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 407 | v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_DONE); |
| 408 | v4l2_m2m_buf_done(dst_vb, VB2_BUF_STATE_DONE); |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 409 | spin_unlock_irqrestore(&vim2m_dev->irqlock, flags); |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 410 | |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 411 | if (curr_ctx->num_processed == curr_ctx->translen |
| 412 | || curr_ctx->aborting) { |
| 413 | dprintk(curr_ctx->dev, "Finishing transaction\n"); |
| 414 | curr_ctx->num_processed = 0; |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 415 | v4l2_m2m_job_finish(vim2m_dev->m2m_dev, curr_ctx->fh.m2m_ctx); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 416 | } else { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 417 | device_run(curr_ctx); |
| 418 | } |
| 419 | } |
| 420 | |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 421 | /* |
| 422 | * video ioctls |
| 423 | */ |
| 424 | static int vidioc_querycap(struct file *file, void *priv, |
| 425 | struct v4l2_capability *cap) |
| 426 | { |
| 427 | strncpy(cap->driver, MEM2MEM_NAME, sizeof(cap->driver) - 1); |
| 428 | strncpy(cap->card, MEM2MEM_NAME, sizeof(cap->card) - 1); |
Hans Verkuil | 72c2af6 | 2012-09-14 06:23:12 -0300 | [diff] [blame] | 429 | snprintf(cap->bus_info, sizeof(cap->bus_info), |
| 430 | "platform:%s", MEM2MEM_NAME); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | static int enum_fmt(struct v4l2_fmtdesc *f, u32 type) |
| 435 | { |
| 436 | int i, num; |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 437 | struct vim2m_fmt *fmt; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 438 | |
| 439 | num = 0; |
| 440 | |
| 441 | for (i = 0; i < NUM_FORMATS; ++i) { |
| 442 | if (formats[i].types & type) { |
| 443 | /* index-th format of type type found ? */ |
| 444 | if (num == f->index) |
| 445 | break; |
| 446 | /* Correct type but haven't reached our index yet, |
| 447 | * just increment per-type index */ |
| 448 | ++num; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | if (i < NUM_FORMATS) { |
| 453 | /* Format found */ |
| 454 | fmt = &formats[i]; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 455 | f->pixelformat = fmt->fourcc; |
| 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | /* Format not found */ |
| 460 | return -EINVAL; |
| 461 | } |
| 462 | |
| 463 | static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
| 464 | struct v4l2_fmtdesc *f) |
| 465 | { |
| 466 | return enum_fmt(f, MEM2MEM_CAPTURE); |
| 467 | } |
| 468 | |
| 469 | static int vidioc_enum_fmt_vid_out(struct file *file, void *priv, |
| 470 | struct v4l2_fmtdesc *f) |
| 471 | { |
| 472 | return enum_fmt(f, MEM2MEM_OUTPUT); |
| 473 | } |
| 474 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 475 | static int vidioc_g_fmt(struct vim2m_ctx *ctx, struct v4l2_format *f) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 476 | { |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 477 | struct vb2_queue *vq; |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 478 | struct vim2m_q_data *q_data; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 479 | |
Sylwester Nawrocki | 20702eb | 2013-08-25 17:27:45 -0300 | [diff] [blame] | 480 | vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 481 | if (!vq) |
| 482 | return -EINVAL; |
| 483 | |
Tomasz Moń | 9f4161a | 2012-06-08 04:47:34 -0300 | [diff] [blame] | 484 | q_data = get_q_data(ctx, f->type); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 485 | |
| 486 | f->fmt.pix.width = q_data->width; |
| 487 | f->fmt.pix.height = q_data->height; |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 488 | f->fmt.pix.field = V4L2_FIELD_NONE; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 489 | f->fmt.pix.pixelformat = q_data->fmt->fourcc; |
| 490 | f->fmt.pix.bytesperline = (q_data->width * q_data->fmt->depth) >> 3; |
| 491 | f->fmt.pix.sizeimage = q_data->sizeimage; |
Hans Verkuil | 47556ff | 2012-07-18 11:33:22 -0300 | [diff] [blame] | 492 | f->fmt.pix.colorspace = ctx->colorspace; |
Hans Verkuil | 9f8b333 | 2016-07-18 08:00:20 -0300 | [diff] [blame] | 493 | f->fmt.pix.xfer_func = ctx->xfer_func; |
| 494 | f->fmt.pix.ycbcr_enc = ctx->ycbcr_enc; |
| 495 | f->fmt.pix.quantization = ctx->quant; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 496 | |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | static int vidioc_g_fmt_vid_out(struct file *file, void *priv, |
| 501 | struct v4l2_format *f) |
| 502 | { |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 503 | return vidioc_g_fmt(file2ctx(file), f); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
| 507 | struct v4l2_format *f) |
| 508 | { |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 509 | return vidioc_g_fmt(file2ctx(file), f); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 510 | } |
| 511 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 512 | static int vidioc_try_fmt(struct v4l2_format *f, struct vim2m_fmt *fmt) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 513 | { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 514 | /* V4L2 specification suggests the driver corrects the format struct |
| 515 | * if any of the dimensions is unsupported */ |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 516 | if (f->fmt.pix.height < MIN_H) |
| 517 | f->fmt.pix.height = MIN_H; |
| 518 | else if (f->fmt.pix.height > MAX_H) |
| 519 | f->fmt.pix.height = MAX_H; |
| 520 | |
| 521 | if (f->fmt.pix.width < MIN_W) |
| 522 | f->fmt.pix.width = MIN_W; |
| 523 | else if (f->fmt.pix.width > MAX_W) |
| 524 | f->fmt.pix.width = MAX_W; |
| 525 | |
| 526 | f->fmt.pix.width &= ~DIM_ALIGN_MASK; |
| 527 | f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; |
| 528 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; |
Hans Verkuil | 5c3112b | 2014-03-10 10:58:29 -0300 | [diff] [blame] | 529 | f->fmt.pix.field = V4L2_FIELD_NONE; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 530 | |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
| 535 | struct v4l2_format *f) |
| 536 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 537 | struct vim2m_fmt *fmt; |
| 538 | struct vim2m_ctx *ctx = file2ctx(file); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 539 | |
| 540 | fmt = find_format(f); |
Hans Verkuil | 4e8ec0a | 2014-03-10 10:58:24 -0300 | [diff] [blame] | 541 | if (!fmt) { |
| 542 | f->fmt.pix.pixelformat = formats[0].fourcc; |
| 543 | fmt = find_format(f); |
| 544 | } |
| 545 | if (!(fmt->types & MEM2MEM_CAPTURE)) { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 546 | v4l2_err(&ctx->dev->v4l2_dev, |
| 547 | "Fourcc format (0x%08x) invalid.\n", |
| 548 | f->fmt.pix.pixelformat); |
| 549 | return -EINVAL; |
| 550 | } |
Hans Verkuil | 47556ff | 2012-07-18 11:33:22 -0300 | [diff] [blame] | 551 | f->fmt.pix.colorspace = ctx->colorspace; |
Hans Verkuil | 9f8b333 | 2016-07-18 08:00:20 -0300 | [diff] [blame] | 552 | f->fmt.pix.xfer_func = ctx->xfer_func; |
| 553 | f->fmt.pix.ycbcr_enc = ctx->ycbcr_enc; |
| 554 | f->fmt.pix.quantization = ctx->quant; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 555 | |
| 556 | return vidioc_try_fmt(f, fmt); |
| 557 | } |
| 558 | |
| 559 | static int vidioc_try_fmt_vid_out(struct file *file, void *priv, |
| 560 | struct v4l2_format *f) |
| 561 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 562 | struct vim2m_fmt *fmt; |
| 563 | struct vim2m_ctx *ctx = file2ctx(file); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 564 | |
| 565 | fmt = find_format(f); |
Hans Verkuil | 4e8ec0a | 2014-03-10 10:58:24 -0300 | [diff] [blame] | 566 | if (!fmt) { |
| 567 | f->fmt.pix.pixelformat = formats[0].fourcc; |
| 568 | fmt = find_format(f); |
| 569 | } |
| 570 | if (!(fmt->types & MEM2MEM_OUTPUT)) { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 571 | v4l2_err(&ctx->dev->v4l2_dev, |
| 572 | "Fourcc format (0x%08x) invalid.\n", |
| 573 | f->fmt.pix.pixelformat); |
| 574 | return -EINVAL; |
| 575 | } |
Hans Verkuil | 47556ff | 2012-07-18 11:33:22 -0300 | [diff] [blame] | 576 | if (!f->fmt.pix.colorspace) |
| 577 | f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 578 | |
| 579 | return vidioc_try_fmt(f, fmt); |
| 580 | } |
| 581 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 582 | static int vidioc_s_fmt(struct vim2m_ctx *ctx, struct v4l2_format *f) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 583 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 584 | struct vim2m_q_data *q_data; |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 585 | struct vb2_queue *vq; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 586 | |
Sylwester Nawrocki | 20702eb | 2013-08-25 17:27:45 -0300 | [diff] [blame] | 587 | vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 588 | if (!vq) |
| 589 | return -EINVAL; |
| 590 | |
Tomasz Moń | 9f4161a | 2012-06-08 04:47:34 -0300 | [diff] [blame] | 591 | q_data = get_q_data(ctx, f->type); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 592 | if (!q_data) |
| 593 | return -EINVAL; |
| 594 | |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 595 | if (vb2_is_busy(vq)) { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 596 | v4l2_err(&ctx->dev->v4l2_dev, "%s queue busy\n", __func__); |
Marek Szyprowski | 07e8030 | 2010-12-20 14:39:25 -0300 | [diff] [blame] | 597 | return -EBUSY; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | q_data->fmt = find_format(f); |
| 601 | q_data->width = f->fmt.pix.width; |
| 602 | q_data->height = f->fmt.pix.height; |
| 603 | q_data->sizeimage = q_data->width * q_data->height |
| 604 | * q_data->fmt->depth >> 3; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 605 | |
| 606 | dprintk(ctx->dev, |
| 607 | "Setting format for type %d, wxh: %dx%d, fmt: %d\n", |
| 608 | f->type, q_data->width, q_data->height, q_data->fmt->fourcc); |
| 609 | |
Marek Szyprowski | 07e8030 | 2010-12-20 14:39:25 -0300 | [diff] [blame] | 610 | return 0; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, |
| 614 | struct v4l2_format *f) |
| 615 | { |
| 616 | int ret; |
| 617 | |
| 618 | ret = vidioc_try_fmt_vid_cap(file, priv, f); |
| 619 | if (ret) |
| 620 | return ret; |
| 621 | |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 622 | return vidioc_s_fmt(file2ctx(file), f); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | static int vidioc_s_fmt_vid_out(struct file *file, void *priv, |
| 626 | struct v4l2_format *f) |
| 627 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 628 | struct vim2m_ctx *ctx = file2ctx(file); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 629 | int ret; |
| 630 | |
| 631 | ret = vidioc_try_fmt_vid_out(file, priv, f); |
| 632 | if (ret) |
| 633 | return ret; |
| 634 | |
Hans Verkuil | 47556ff | 2012-07-18 11:33:22 -0300 | [diff] [blame] | 635 | ret = vidioc_s_fmt(file2ctx(file), f); |
Hans Verkuil | 9f8b333 | 2016-07-18 08:00:20 -0300 | [diff] [blame] | 636 | if (!ret) { |
Hans Verkuil | 47556ff | 2012-07-18 11:33:22 -0300 | [diff] [blame] | 637 | ctx->colorspace = f->fmt.pix.colorspace; |
Hans Verkuil | 9f8b333 | 2016-07-18 08:00:20 -0300 | [diff] [blame] | 638 | ctx->xfer_func = f->fmt.pix.xfer_func; |
| 639 | ctx->ycbcr_enc = f->fmt.pix.ycbcr_enc; |
| 640 | ctx->quant = f->fmt.pix.quantization; |
| 641 | } |
Hans Verkuil | 47556ff | 2012-07-18 11:33:22 -0300 | [diff] [blame] | 642 | return ret; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 643 | } |
| 644 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 645 | static int vim2m_s_ctrl(struct v4l2_ctrl *ctrl) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 646 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 647 | struct vim2m_ctx *ctx = |
| 648 | container_of(ctrl->handler, struct vim2m_ctx, hdl); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 649 | |
| 650 | switch (ctrl->id) { |
Tomasz Moń | 8007287 | 2012-06-12 06:43:49 -0300 | [diff] [blame] | 651 | case V4L2_CID_HFLIP: |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 652 | if (ctrl->val) |
Tomasz Moń | 8007287 | 2012-06-12 06:43:49 -0300 | [diff] [blame] | 653 | ctx->mode |= MEM2MEM_HFLIP; |
| 654 | else |
| 655 | ctx->mode &= ~MEM2MEM_HFLIP; |
| 656 | break; |
| 657 | |
| 658 | case V4L2_CID_VFLIP: |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 659 | if (ctrl->val) |
Tomasz Moń | 8007287 | 2012-06-12 06:43:49 -0300 | [diff] [blame] | 660 | ctx->mode |= MEM2MEM_VFLIP; |
| 661 | else |
| 662 | ctx->mode &= ~MEM2MEM_VFLIP; |
| 663 | break; |
| 664 | |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 665 | case V4L2_CID_TRANS_TIME_MSEC: |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 666 | ctx->transtime = ctrl->val; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 667 | break; |
| 668 | |
| 669 | case V4L2_CID_TRANS_NUM_BUFS: |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 670 | ctx->translen = ctrl->val; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 671 | break; |
| 672 | |
| 673 | default: |
| 674 | v4l2_err(&ctx->dev->v4l2_dev, "Invalid control\n"); |
| 675 | return -EINVAL; |
| 676 | } |
| 677 | |
| 678 | return 0; |
| 679 | } |
| 680 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 681 | static const struct v4l2_ctrl_ops vim2m_ctrl_ops = { |
| 682 | .s_ctrl = vim2m_s_ctrl, |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 683 | }; |
| 684 | |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 685 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 686 | static const struct v4l2_ioctl_ops vim2m_ioctl_ops = { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 687 | .vidioc_querycap = vidioc_querycap, |
| 688 | |
| 689 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 690 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 691 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 692 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
| 693 | |
| 694 | .vidioc_enum_fmt_vid_out = vidioc_enum_fmt_vid_out, |
| 695 | .vidioc_g_fmt_vid_out = vidioc_g_fmt_vid_out, |
| 696 | .vidioc_try_fmt_vid_out = vidioc_try_fmt_vid_out, |
| 697 | .vidioc_s_fmt_vid_out = vidioc_s_fmt_vid_out, |
| 698 | |
Sylwester Nawrocki | 20702eb | 2013-08-25 17:27:45 -0300 | [diff] [blame] | 699 | .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, |
| 700 | .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, |
| 701 | .vidioc_qbuf = v4l2_m2m_ioctl_qbuf, |
| 702 | .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, |
Hans Verkuil | 7bcff1c | 2015-06-05 11:28:52 -0300 | [diff] [blame] | 703 | .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, |
| 704 | .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, |
Hans Verkuil | f5294f4 | 2014-11-18 09:51:07 -0300 | [diff] [blame] | 705 | .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 706 | |
Sylwester Nawrocki | 20702eb | 2013-08-25 17:27:45 -0300 | [diff] [blame] | 707 | .vidioc_streamon = v4l2_m2m_ioctl_streamon, |
| 708 | .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 709 | |
Hans Verkuil | 97a3c90 | 2012-07-18 10:54:59 -0300 | [diff] [blame] | 710 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
| 711 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 712 | }; |
| 713 | |
| 714 | |
| 715 | /* |
| 716 | * Queue operations |
| 717 | */ |
| 718 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 719 | static int vim2m_queue_setup(struct vb2_queue *vq, |
Guennadi Liakhovetski | fc714e70 | 2011-08-24 10:30:21 -0300 | [diff] [blame] | 720 | unsigned int *nbuffers, unsigned int *nplanes, |
Hans Verkuil | 36c0f8b | 2016-04-15 09:15:05 -0300 | [diff] [blame] | 721 | unsigned int sizes[], struct device *alloc_devs[]) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 722 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 723 | struct vim2m_ctx *ctx = vb2_get_drv_priv(vq); |
| 724 | struct vim2m_q_data *q_data; |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 725 | unsigned int size, count = *nbuffers; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 726 | |
Tomasz Moń | 9f4161a | 2012-06-08 04:47:34 -0300 | [diff] [blame] | 727 | q_data = get_q_data(ctx, vq->type); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 728 | |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 729 | size = q_data->width * q_data->height * q_data->fmt->depth >> 3; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 730 | |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 731 | while (size * count > MEM2MEM_VID_MEM_LIMIT) |
| 732 | (count)--; |
Hans Verkuil | df9ecb0c | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 733 | *nbuffers = count; |
| 734 | |
| 735 | if (*nplanes) |
| 736 | return sizes[0] < size ? -EINVAL : 0; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 737 | |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 738 | *nplanes = 1; |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 739 | sizes[0] = size; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 740 | |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 741 | dprintk(ctx->dev, "get %d buffer(s) of size %d each.\n", count, size); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 742 | |
| 743 | return 0; |
| 744 | } |
| 745 | |
Hans Verkuil | ab7afaf3 | 2019-01-16 10:01:14 -0200 | [diff] [blame^] | 746 | static int vim2m_buf_out_validate(struct vb2_buffer *vb) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 747 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 748 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 749 | struct vim2m_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); |
Hans Verkuil | ab7afaf3 | 2019-01-16 10:01:14 -0200 | [diff] [blame^] | 750 | |
| 751 | if (vbuf->field == V4L2_FIELD_ANY) |
| 752 | vbuf->field = V4L2_FIELD_NONE; |
| 753 | if (vbuf->field != V4L2_FIELD_NONE) { |
| 754 | dprintk(ctx->dev, "%s field isn't supported\n", __func__); |
| 755 | return -EINVAL; |
| 756 | } |
| 757 | |
| 758 | return 0; |
| 759 | } |
| 760 | |
| 761 | static int vim2m_buf_prepare(struct vb2_buffer *vb) |
| 762 | { |
| 763 | struct vim2m_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 764 | struct vim2m_q_data *q_data; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 765 | |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 766 | dprintk(ctx->dev, "type: %d\n", vb->vb2_queue->type); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 767 | |
Tomasz Moń | 9f4161a | 2012-06-08 04:47:34 -0300 | [diff] [blame] | 768 | q_data = get_q_data(ctx, vb->vb2_queue->type); |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 769 | if (vb2_plane_size(vb, 0) < q_data->sizeimage) { |
| 770 | dprintk(ctx->dev, "%s data will not fit into plane (%lu < %lu)\n", |
| 771 | __func__, vb2_plane_size(vb, 0), (long)q_data->sizeimage); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 772 | return -EINVAL; |
| 773 | } |
| 774 | |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 775 | vb2_set_plane_payload(vb, 0, q_data->sizeimage); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 776 | |
| 777 | return 0; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 778 | } |
| 779 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 780 | static void vim2m_buf_queue(struct vb2_buffer *vb) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 781 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 782 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 783 | struct vim2m_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); |
Hans Verkuil | ca5f5fd | 2014-03-10 10:58:28 -0300 | [diff] [blame] | 784 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 785 | v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf); |
Michael Olbrich | 0f910bf | 2011-07-12 09:46:44 -0300 | [diff] [blame] | 786 | } |
| 787 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 788 | static int vim2m_start_streaming(struct vb2_queue *q, unsigned count) |
Hans Verkuil | ca5f5fd | 2014-03-10 10:58:28 -0300 | [diff] [blame] | 789 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 790 | struct vim2m_ctx *ctx = vb2_get_drv_priv(q); |
| 791 | struct vim2m_q_data *q_data = get_q_data(ctx, q->type); |
Hans Verkuil | ca5f5fd | 2014-03-10 10:58:28 -0300 | [diff] [blame] | 792 | |
| 793 | q_data->sequence = 0; |
| 794 | return 0; |
| 795 | } |
| 796 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 797 | static void vim2m_stop_streaming(struct vb2_queue *q) |
Hans Verkuil | a773632 | 2014-03-10 10:58:27 -0300 | [diff] [blame] | 798 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 799 | struct vim2m_ctx *ctx = vb2_get_drv_priv(q); |
Hans Verkuil | 52117be | 2018-11-07 09:04:54 -0500 | [diff] [blame] | 800 | struct vim2m_dev *dev = ctx->dev; |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 801 | struct vb2_v4l2_buffer *vbuf; |
Hans Verkuil | a773632 | 2014-03-10 10:58:27 -0300 | [diff] [blame] | 802 | unsigned long flags; |
| 803 | |
Hans Verkuil | 52117be | 2018-11-07 09:04:54 -0500 | [diff] [blame] | 804 | cancel_delayed_work_sync(&dev->work_run); |
Hans Verkuil | a773632 | 2014-03-10 10:58:27 -0300 | [diff] [blame] | 805 | for (;;) { |
| 806 | if (V4L2_TYPE_IS_OUTPUT(q->type)) |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 807 | vbuf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); |
Hans Verkuil | a773632 | 2014-03-10 10:58:27 -0300 | [diff] [blame] | 808 | else |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 809 | vbuf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); |
| 810 | if (vbuf == NULL) |
Hans Verkuil | e37559b | 2014-04-17 02:47:21 -0300 | [diff] [blame] | 811 | return; |
Hans Verkuil | 86b93b2 | 2018-05-21 04:54:57 -0400 | [diff] [blame] | 812 | v4l2_ctrl_request_complete(vbuf->vb2_buf.req_obj.req, |
| 813 | &ctx->hdl); |
Hans Verkuil | a773632 | 2014-03-10 10:58:27 -0300 | [diff] [blame] | 814 | spin_lock_irqsave(&ctx->dev->irqlock, flags); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 815 | v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_ERROR); |
Hans Verkuil | a773632 | 2014-03-10 10:58:27 -0300 | [diff] [blame] | 816 | spin_unlock_irqrestore(&ctx->dev->irqlock, flags); |
| 817 | } |
Hans Verkuil | a773632 | 2014-03-10 10:58:27 -0300 | [diff] [blame] | 818 | } |
| 819 | |
Hans Verkuil | 86b93b2 | 2018-05-21 04:54:57 -0400 | [diff] [blame] | 820 | static void vim2m_buf_request_complete(struct vb2_buffer *vb) |
| 821 | { |
| 822 | struct vim2m_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); |
| 823 | |
| 824 | v4l2_ctrl_request_complete(vb->req_obj.req, &ctx->hdl); |
| 825 | } |
| 826 | |
Julia Lawall | b7b361f | 2016-09-08 20:59:10 -0300 | [diff] [blame] | 827 | static const struct vb2_ops vim2m_qops = { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 828 | .queue_setup = vim2m_queue_setup, |
Hans Verkuil | ab7afaf3 | 2019-01-16 10:01:14 -0200 | [diff] [blame^] | 829 | .buf_out_validate = vim2m_buf_out_validate, |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 830 | .buf_prepare = vim2m_buf_prepare, |
| 831 | .buf_queue = vim2m_buf_queue, |
| 832 | .start_streaming = vim2m_start_streaming, |
| 833 | .stop_streaming = vim2m_stop_streaming, |
Sylwester Nawrocki | 20702eb | 2013-08-25 17:27:45 -0300 | [diff] [blame] | 834 | .wait_prepare = vb2_ops_wait_prepare, |
| 835 | .wait_finish = vb2_ops_wait_finish, |
Hans Verkuil | 86b93b2 | 2018-05-21 04:54:57 -0400 | [diff] [blame] | 836 | .buf_request_complete = vim2m_buf_request_complete, |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 837 | }; |
| 838 | |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 839 | static int queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 840 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 841 | struct vim2m_ctx *ctx = priv; |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 842 | int ret; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 843 | |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 844 | src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; |
Hans Verkuil | 782f36c | 2014-03-10 10:58:26 -0300 | [diff] [blame] | 845 | src_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 846 | src_vq->drv_priv = ctx; |
| 847 | src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 848 | src_vq->ops = &vim2m_qops; |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 849 | src_vq->mem_ops = &vb2_vmalloc_memops; |
Sakari Ailus | ade4868 | 2014-02-25 19:12:19 -0300 | [diff] [blame] | 850 | src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; |
Sylwester Nawrocki | 20702eb | 2013-08-25 17:27:45 -0300 | [diff] [blame] | 851 | src_vq->lock = &ctx->dev->dev_mutex; |
Hans Verkuil | e5079cf | 2018-08-23 10:18:35 -0400 | [diff] [blame] | 852 | src_vq->supports_requests = true; |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 853 | |
| 854 | ret = vb2_queue_init(src_vq); |
| 855 | if (ret) |
| 856 | return ret; |
| 857 | |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 858 | dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Hans Verkuil | 782f36c | 2014-03-10 10:58:26 -0300 | [diff] [blame] | 859 | dst_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 860 | dst_vq->drv_priv = ctx; |
| 861 | dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 862 | dst_vq->ops = &vim2m_qops; |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 863 | dst_vq->mem_ops = &vb2_vmalloc_memops; |
Sakari Ailus | ade4868 | 2014-02-25 19:12:19 -0300 | [diff] [blame] | 864 | dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; |
Sylwester Nawrocki | 20702eb | 2013-08-25 17:27:45 -0300 | [diff] [blame] | 865 | dst_vq->lock = &ctx->dev->dev_mutex; |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 866 | |
| 867 | return vb2_queue_init(dst_vq); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 868 | } |
| 869 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 870 | static const struct v4l2_ctrl_config vim2m_ctrl_trans_time_msec = { |
| 871 | .ops = &vim2m_ctrl_ops, |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 872 | .id = V4L2_CID_TRANS_TIME_MSEC, |
| 873 | .name = "Transaction Time (msec)", |
| 874 | .type = V4L2_CTRL_TYPE_INTEGER, |
Hans Verkuil | 4340583 | 2014-03-10 10:58:23 -0300 | [diff] [blame] | 875 | .def = MEM2MEM_DEF_TRANSTIME, |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 876 | .min = 1, |
| 877 | .max = 10001, |
Hans Verkuil | 4340583 | 2014-03-10 10:58:23 -0300 | [diff] [blame] | 878 | .step = 1, |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 879 | }; |
| 880 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 881 | static const struct v4l2_ctrl_config vim2m_ctrl_trans_num_bufs = { |
| 882 | .ops = &vim2m_ctrl_ops, |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 883 | .id = V4L2_CID_TRANS_NUM_BUFS, |
| 884 | .name = "Buffers Per Transaction", |
| 885 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 886 | .def = 1, |
| 887 | .min = 1, |
| 888 | .max = MEM2MEM_DEF_NUM_BUFS, |
| 889 | .step = 1, |
| 890 | }; |
| 891 | |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 892 | /* |
| 893 | * File operations |
| 894 | */ |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 895 | static int vim2m_open(struct file *file) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 896 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 897 | struct vim2m_dev *dev = video_drvdata(file); |
| 898 | struct vim2m_ctx *ctx = NULL; |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 899 | struct v4l2_ctrl_handler *hdl; |
Hans Verkuil | f469403 | 2012-07-31 03:51:25 -0300 | [diff] [blame] | 900 | int rc = 0; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 901 | |
Hans Verkuil | f469403 | 2012-07-31 03:51:25 -0300 | [diff] [blame] | 902 | if (mutex_lock_interruptible(&dev->dev_mutex)) |
| 903 | return -ERESTARTSYS; |
Sachin Kamat | 56ed221 | 2012-09-24 02:17:46 -0300 | [diff] [blame] | 904 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
Hans Verkuil | f469403 | 2012-07-31 03:51:25 -0300 | [diff] [blame] | 905 | if (!ctx) { |
| 906 | rc = -ENOMEM; |
| 907 | goto open_unlock; |
| 908 | } |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 909 | |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 910 | v4l2_fh_init(&ctx->fh, video_devdata(file)); |
| 911 | file->private_data = &ctx->fh; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 912 | ctx->dev = dev; |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 913 | hdl = &ctx->hdl; |
| 914 | v4l2_ctrl_handler_init(hdl, 4); |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 915 | v4l2_ctrl_new_std(hdl, &vim2m_ctrl_ops, V4L2_CID_HFLIP, 0, 1, 1, 0); |
| 916 | v4l2_ctrl_new_std(hdl, &vim2m_ctrl_ops, V4L2_CID_VFLIP, 0, 1, 1, 0); |
| 917 | v4l2_ctrl_new_custom(hdl, &vim2m_ctrl_trans_time_msec, NULL); |
| 918 | v4l2_ctrl_new_custom(hdl, &vim2m_ctrl_trans_num_bufs, NULL); |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 919 | if (hdl->error) { |
Dan Carpenter | a7bd775 | 2012-08-14 02:58:56 -0300 | [diff] [blame] | 920 | rc = hdl->error; |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 921 | v4l2_ctrl_handler_free(hdl); |
Santosh Kumar Singh | 7c13a4d | 2016-12-19 14:12:46 -0200 | [diff] [blame] | 922 | kfree(ctx); |
Dan Carpenter | a7bd775 | 2012-08-14 02:58:56 -0300 | [diff] [blame] | 923 | goto open_unlock; |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 924 | } |
| 925 | ctx->fh.ctrl_handler = hdl; |
| 926 | v4l2_ctrl_handler_setup(hdl); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 927 | |
Tomasz Moń | 9f4161a | 2012-06-08 04:47:34 -0300 | [diff] [blame] | 928 | ctx->q_data[V4L2_M2M_SRC].fmt = &formats[0]; |
Hans Verkuil | 47556ff | 2012-07-18 11:33:22 -0300 | [diff] [blame] | 929 | ctx->q_data[V4L2_M2M_SRC].width = 640; |
| 930 | ctx->q_data[V4L2_M2M_SRC].height = 480; |
| 931 | ctx->q_data[V4L2_M2M_SRC].sizeimage = |
| 932 | ctx->q_data[V4L2_M2M_SRC].width * |
| 933 | ctx->q_data[V4L2_M2M_SRC].height * |
| 934 | (ctx->q_data[V4L2_M2M_SRC].fmt->depth >> 3); |
| 935 | ctx->q_data[V4L2_M2M_DST] = ctx->q_data[V4L2_M2M_SRC]; |
| 936 | ctx->colorspace = V4L2_COLORSPACE_REC709; |
Tomasz Moń | 9f4161a | 2012-06-08 04:47:34 -0300 | [diff] [blame] | 937 | |
Sylwester Nawrocki | 20702eb | 2013-08-25 17:27:45 -0300 | [diff] [blame] | 938 | ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init); |
Marek Szyprowski | d80ee38 | 2011-01-12 06:50:55 -0300 | [diff] [blame] | 939 | |
Sylwester Nawrocki | 20702eb | 2013-08-25 17:27:45 -0300 | [diff] [blame] | 940 | if (IS_ERR(ctx->fh.m2m_ctx)) { |
| 941 | rc = PTR_ERR(ctx->fh.m2m_ctx); |
Dan Carpenter | 16ee9bb1 | 2010-05-05 02:58:57 -0300 | [diff] [blame] | 942 | |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 943 | v4l2_ctrl_handler_free(hdl); |
Santosh Kumar Singh | 7c13a4d | 2016-12-19 14:12:46 -0200 | [diff] [blame] | 944 | v4l2_fh_exit(&ctx->fh); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 945 | kfree(ctx); |
Hans Verkuil | f469403 | 2012-07-31 03:51:25 -0300 | [diff] [blame] | 946 | goto open_unlock; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 947 | } |
| 948 | |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 949 | v4l2_fh_add(&ctx->fh); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 950 | atomic_inc(&dev->num_inst); |
| 951 | |
Sylwester Nawrocki | 20702eb | 2013-08-25 17:27:45 -0300 | [diff] [blame] | 952 | dprintk(dev, "Created instance: %p, m2m_ctx: %p\n", |
| 953 | ctx, ctx->fh.m2m_ctx); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 954 | |
Hans Verkuil | f469403 | 2012-07-31 03:51:25 -0300 | [diff] [blame] | 955 | open_unlock: |
| 956 | mutex_unlock(&dev->dev_mutex); |
Dan Carpenter | a7bd775 | 2012-08-14 02:58:56 -0300 | [diff] [blame] | 957 | return rc; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 958 | } |
| 959 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 960 | static int vim2m_release(struct file *file) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 961 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 962 | struct vim2m_dev *dev = video_drvdata(file); |
| 963 | struct vim2m_ctx *ctx = file2ctx(file); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 964 | |
| 965 | dprintk(dev, "Releasing instance %p\n", ctx); |
| 966 | |
Hans Verkuil | d3dd59c | 2012-07-18 10:35:37 -0300 | [diff] [blame] | 967 | v4l2_fh_del(&ctx->fh); |
| 968 | v4l2_fh_exit(&ctx->fh); |
| 969 | v4l2_ctrl_handler_free(&ctx->hdl); |
Hans Verkuil | f469403 | 2012-07-31 03:51:25 -0300 | [diff] [blame] | 970 | mutex_lock(&dev->dev_mutex); |
Sylwester Nawrocki | 20702eb | 2013-08-25 17:27:45 -0300 | [diff] [blame] | 971 | v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); |
Hans Verkuil | f469403 | 2012-07-31 03:51:25 -0300 | [diff] [blame] | 972 | mutex_unlock(&dev->dev_mutex); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 973 | kfree(ctx); |
| 974 | |
| 975 | atomic_dec(&dev->num_inst); |
| 976 | |
| 977 | return 0; |
| 978 | } |
| 979 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 980 | static const struct v4l2_file_operations vim2m_fops = { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 981 | .owner = THIS_MODULE, |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 982 | .open = vim2m_open, |
| 983 | .release = vim2m_release, |
Sylwester Nawrocki | 20702eb | 2013-08-25 17:27:45 -0300 | [diff] [blame] | 984 | .poll = v4l2_m2m_fop_poll, |
Marek Szyprowski | 07e8030 | 2010-12-20 14:39:25 -0300 | [diff] [blame] | 985 | .unlocked_ioctl = video_ioctl2, |
Sylwester Nawrocki | 20702eb | 2013-08-25 17:27:45 -0300 | [diff] [blame] | 986 | .mmap = v4l2_m2m_fop_mmap, |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 987 | }; |
| 988 | |
Bhumika Goyal | 5303135 | 2017-08-26 08:57:26 -0400 | [diff] [blame] | 989 | static const struct video_device vim2m_videodev = { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 990 | .name = MEM2MEM_NAME, |
Hans Verkuil | 954f340 | 2012-09-05 06:05:50 -0300 | [diff] [blame] | 991 | .vfl_dir = VFL_DIR_M2M, |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 992 | .fops = &vim2m_fops, |
| 993 | .ioctl_ops = &vim2m_ioctl_ops, |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 994 | .minor = -1, |
Hans Verkuil | 0936542 | 2015-03-09 13:33:56 -0300 | [diff] [blame] | 995 | .release = video_device_release_empty, |
Hans Verkuil | 47fc65fa | 2018-11-15 03:16:22 -0500 | [diff] [blame] | 996 | .device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING, |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 997 | }; |
| 998 | |
Julia Lawall | 86ab0b1 | 2017-08-06 04:25:19 -0400 | [diff] [blame] | 999 | static const struct v4l2_m2m_ops m2m_ops = { |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1000 | .device_run = device_run, |
| 1001 | .job_ready = job_ready, |
| 1002 | .job_abort = job_abort, |
| 1003 | }; |
| 1004 | |
Hans Verkuil | 86b93b2 | 2018-05-21 04:54:57 -0400 | [diff] [blame] | 1005 | static const struct media_device_ops m2m_media_ops = { |
| 1006 | .req_validate = vb2_request_validate, |
Ezequiel Garcia | ef86eaf | 2018-10-18 14:54:29 -0400 | [diff] [blame] | 1007 | .req_queue = v4l2_m2m_request_queue, |
Hans Verkuil | 86b93b2 | 2018-05-21 04:54:57 -0400 | [diff] [blame] | 1008 | }; |
| 1009 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 1010 | static int vim2m_probe(struct platform_device *pdev) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1011 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 1012 | struct vim2m_dev *dev; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1013 | struct video_device *vfd; |
| 1014 | int ret; |
| 1015 | |
Sachin Kamat | 38a7996 | 2012-09-24 02:17:48 -0300 | [diff] [blame] | 1016 | dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1017 | if (!dev) |
| 1018 | return -ENOMEM; |
| 1019 | |
| 1020 | spin_lock_init(&dev->irqlock); |
| 1021 | |
| 1022 | ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev); |
| 1023 | if (ret) |
Sachin Kamat | 38a7996 | 2012-09-24 02:17:48 -0300 | [diff] [blame] | 1024 | return ret; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1025 | |
| 1026 | atomic_set(&dev->num_inst, 0); |
| 1027 | mutex_init(&dev->dev_mutex); |
| 1028 | |
Hans Verkuil | 0936542 | 2015-03-09 13:33:56 -0300 | [diff] [blame] | 1029 | dev->vfd = vim2m_videodev; |
| 1030 | vfd = &dev->vfd; |
Marek Szyprowski | 07e8030 | 2010-12-20 14:39:25 -0300 | [diff] [blame] | 1031 | vfd->lock = &dev->dev_mutex; |
Hans Verkuil | 8f484d8 | 2013-06-27 02:44:04 -0300 | [diff] [blame] | 1032 | vfd->v4l2_dev = &dev->v4l2_dev; |
Hans Verkuil | 144bd0e | 2018-05-21 04:54:56 -0400 | [diff] [blame] | 1033 | INIT_DELAYED_WORK(&dev->work_run, device_work); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1034 | |
| 1035 | ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0); |
| 1036 | if (ret) { |
| 1037 | v4l2_err(&dev->v4l2_dev, "Failed to register video device\n"); |
Hans Verkuil | e35f702 | 2018-07-02 11:36:06 -0400 | [diff] [blame] | 1038 | goto unreg_v4l2; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | video_set_drvdata(vfd, dev); |
Hans Verkuil | 8f484d8 | 2013-06-27 02:44:04 -0300 | [diff] [blame] | 1042 | v4l2_info(&dev->v4l2_dev, |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1043 | "Device registered as /dev/video%d\n", vfd->num); |
| 1044 | |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1045 | platform_set_drvdata(pdev, dev); |
| 1046 | |
| 1047 | dev->m2m_dev = v4l2_m2m_init(&m2m_ops); |
| 1048 | if (IS_ERR(dev->m2m_dev)) { |
| 1049 | v4l2_err(&dev->v4l2_dev, "Failed to init mem2mem device\n"); |
| 1050 | ret = PTR_ERR(dev->m2m_dev); |
Hans Verkuil | e35f702 | 2018-07-02 11:36:06 -0400 | [diff] [blame] | 1051 | goto unreg_dev; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1052 | } |
| 1053 | |
Hans Verkuil | e35f702 | 2018-07-02 11:36:06 -0400 | [diff] [blame] | 1054 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 1055 | dev->mdev.dev = &pdev->dev; |
Mauro Carvalho Chehab | c0decac | 2018-09-10 08:19:14 -0400 | [diff] [blame] | 1056 | strscpy(dev->mdev.model, "vim2m", sizeof(dev->mdev.model)); |
Hans Verkuil | e35f702 | 2018-07-02 11:36:06 -0400 | [diff] [blame] | 1057 | media_device_init(&dev->mdev); |
Hans Verkuil | 86b93b2 | 2018-05-21 04:54:57 -0400 | [diff] [blame] | 1058 | dev->mdev.ops = &m2m_media_ops; |
Hans Verkuil | e35f702 | 2018-07-02 11:36:06 -0400 | [diff] [blame] | 1059 | dev->v4l2_dev.mdev = &dev->mdev; |
| 1060 | |
| 1061 | ret = v4l2_m2m_register_media_controller(dev->m2m_dev, |
| 1062 | vfd, MEDIA_ENT_F_PROC_VIDEO_SCALER); |
| 1063 | if (ret) { |
| 1064 | v4l2_err(&dev->v4l2_dev, "Failed to init mem2mem media controller\n"); |
| 1065 | goto unreg_m2m; |
| 1066 | } |
| 1067 | |
| 1068 | ret = media_device_register(&dev->mdev); |
| 1069 | if (ret) { |
| 1070 | v4l2_err(&dev->v4l2_dev, "Failed to register mem2mem media device\n"); |
| 1071 | goto unreg_m2m_mc; |
| 1072 | } |
| 1073 | #endif |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1074 | return 0; |
| 1075 | |
Hans Verkuil | e35f702 | 2018-07-02 11:36:06 -0400 | [diff] [blame] | 1076 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 1077 | unreg_m2m_mc: |
| 1078 | v4l2_m2m_unregister_media_controller(dev->m2m_dev); |
| 1079 | unreg_m2m: |
Sachin Kamat | b7e13ef | 2012-09-24 02:17:45 -0300 | [diff] [blame] | 1080 | v4l2_m2m_release(dev->m2m_dev); |
Hans Verkuil | e35f702 | 2018-07-02 11:36:06 -0400 | [diff] [blame] | 1081 | #endif |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1082 | unreg_dev: |
Hans Verkuil | e35f702 | 2018-07-02 11:36:06 -0400 | [diff] [blame] | 1083 | video_unregister_device(&dev->vfd); |
| 1084 | unreg_v4l2: |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1085 | v4l2_device_unregister(&dev->v4l2_dev); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1086 | |
| 1087 | return ret; |
| 1088 | } |
| 1089 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 1090 | static int vim2m_remove(struct platform_device *pdev) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1091 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 1092 | struct vim2m_dev *dev = platform_get_drvdata(pdev); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1093 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 1094 | v4l2_info(&dev->v4l2_dev, "Removing " MEM2MEM_NAME); |
Hans Verkuil | e35f702 | 2018-07-02 11:36:06 -0400 | [diff] [blame] | 1095 | |
| 1096 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 1097 | media_device_unregister(&dev->mdev); |
| 1098 | v4l2_m2m_unregister_media_controller(dev->m2m_dev); |
| 1099 | media_device_cleanup(&dev->mdev); |
| 1100 | #endif |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1101 | v4l2_m2m_release(dev->m2m_dev); |
Hans Verkuil | 0936542 | 2015-03-09 13:33:56 -0300 | [diff] [blame] | 1102 | video_unregister_device(&dev->vfd); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1103 | v4l2_device_unregister(&dev->v4l2_dev); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1104 | |
| 1105 | return 0; |
| 1106 | } |
| 1107 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 1108 | static struct platform_driver vim2m_pdrv = { |
| 1109 | .probe = vim2m_probe, |
| 1110 | .remove = vim2m_remove, |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1111 | .driver = { |
| 1112 | .name = MEM2MEM_NAME, |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1113 | }, |
| 1114 | }; |
| 1115 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 1116 | static void __exit vim2m_exit(void) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1117 | { |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 1118 | platform_driver_unregister(&vim2m_pdrv); |
| 1119 | platform_device_unregister(&vim2m_pdev); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1120 | } |
| 1121 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 1122 | static int __init vim2m_init(void) |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1123 | { |
| 1124 | int ret; |
| 1125 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 1126 | ret = platform_device_register(&vim2m_pdev); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1127 | if (ret) |
| 1128 | return ret; |
| 1129 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 1130 | ret = platform_driver_register(&vim2m_pdrv); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1131 | if (ret) |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 1132 | platform_device_unregister(&vim2m_pdev); |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1133 | |
Niklas Söderlund | b20b51f | 2015-12-25 15:25:16 -0200 | [diff] [blame] | 1134 | return ret; |
Pawel Osciak | 96d8eab | 2010-04-23 05:38:38 -0300 | [diff] [blame] | 1135 | } |
| 1136 | |
Hans Verkuil | 1f923a4 | 2014-09-22 09:27:17 -0300 | [diff] [blame] | 1137 | module_init(vim2m_init); |
| 1138 | module_exit(vim2m_exit); |