blob: 24737f1a1a1bbc9dcd020c2e9e1d404046ad8ec0 [file] [log] [blame]
Javier Martin186b2502012-07-26 05:53:35 -03001/*
2 * Coda multi-standard codec IP
3 *
4 * Copyright (C) 2012 Vista Silicon S.L.
5 * Javier Martin, <javier.martin@vista-silicon.com>
6 * Xavier Duret
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#include <linux/clk.h>
Philipp Zabelf61c0b12014-07-11 06:36:40 -030015#include <linux/debugfs.h>
Javier Martin186b2502012-07-26 05:53:35 -030016#include <linux/delay.h>
17#include <linux/firmware.h>
Philipp Zabel657eee72013-04-29 16:17:14 -070018#include <linux/genalloc.h>
Javier Martin186b2502012-07-26 05:53:35 -030019#include <linux/interrupt.h>
20#include <linux/io.h>
21#include <linux/irq.h>
Philipp Zabel9082a7c2013-06-21 03:55:31 -030022#include <linux/kfifo.h>
Javier Martin186b2502012-07-26 05:53:35 -030023#include <linux/module.h>
24#include <linux/of_device.h>
25#include <linux/platform_device.h>
Philipp Zabel1e172732014-07-11 06:36:23 -030026#include <linux/pm_runtime.h>
Javier Martin186b2502012-07-26 05:53:35 -030027#include <linux/slab.h>
28#include <linux/videodev2.h>
29#include <linux/of.h>
Philipp Zabel657eee72013-04-29 16:17:14 -070030#include <linux/platform_data/coda.h>
Philipp Zabel8f452842014-07-11 06:36:35 -030031#include <linux/reset.h>
Javier Martin186b2502012-07-26 05:53:35 -030032
33#include <media/v4l2-ctrls.h>
34#include <media/v4l2-device.h>
Philipp Zabel918c66f2013-06-27 06:59:01 -030035#include <media/v4l2-event.h>
Javier Martin186b2502012-07-26 05:53:35 -030036#include <media/v4l2-ioctl.h>
37#include <media/v4l2-mem2mem.h>
38#include <media/videobuf2-core.h>
39#include <media/videobuf2-dma-contig.h>
Philipp Zabelbb04aa62015-01-23 13:51:30 -030040#include <media/videobuf2-vmalloc.h>
Javier Martin186b2502012-07-26 05:53:35 -030041
Philipp Zabela2b3e462014-07-23 12:28:39 -030042#include "coda.h"
Javier Martin186b2502012-07-26 05:53:35 -030043
44#define CODA_NAME "coda"
45
Philipp Zabel0cddc7e2013-09-30 10:34:44 -030046#define CODADX6_MAX_INSTANCES 4
Philipp Zabel2c11d1b2014-10-02 14:08:28 -030047#define CODA_MAX_FORMATS 4
Javier Martin186b2502012-07-26 05:53:35 -030048
Javier Martin186b2502012-07-26 05:53:35 -030049#define CODA_ISRAM_SIZE (2048 * 2)
50
Javier Martin186b2502012-07-26 05:53:35 -030051#define MIN_W 176
52#define MIN_H 144
Javier Martin186b2502012-07-26 05:53:35 -030053
54#define S_ALIGN 1 /* multiple of 2 */
55#define W_ALIGN 1 /* multiple of 2 */
56#define H_ALIGN 1 /* multiple of 2 */
57
58#define fh_to_ctx(__fh) container_of(__fh, struct coda_ctx, fh)
59
Philipp Zabel79924ca2014-07-23 12:28:45 -030060int coda_debug;
Philipp Zabelc4eb1bfc2013-05-21 04:24:16 -030061module_param(coda_debug, int, 0644);
Philipp Zabeld60b18b2014-08-05 14:00:15 -030062MODULE_PARM_DESC(coda_debug, "Debug level (0-2)");
Javier Martin186b2502012-07-26 05:53:35 -030063
Philipp Zabela2b3e462014-07-23 12:28:39 -030064void coda_write(struct coda_dev *dev, u32 data, u32 reg)
Javier Martin186b2502012-07-26 05:53:35 -030065{
Philipp Zabeld60b18b2014-08-05 14:00:15 -030066 v4l2_dbg(2, coda_debug, &dev->v4l2_dev,
Javier Martin186b2502012-07-26 05:53:35 -030067 "%s: data=0x%x, reg=0x%x\n", __func__, data, reg);
68 writel(data, dev->regs_base + reg);
69}
70
Philipp Zabela2b3e462014-07-23 12:28:39 -030071unsigned int coda_read(struct coda_dev *dev, u32 reg)
Javier Martin186b2502012-07-26 05:53:35 -030072{
73 u32 data;
Philipp Zabelf23797b2014-08-06 08:02:23 -030074
Javier Martin186b2502012-07-26 05:53:35 -030075 data = readl(dev->regs_base + reg);
Philipp Zabeld60b18b2014-08-05 14:00:15 -030076 v4l2_dbg(2, coda_debug, &dev->v4l2_dev,
Javier Martin186b2502012-07-26 05:53:35 -030077 "%s: data=0x%x, reg=0x%x\n", __func__, data, reg);
78 return data;
79}
80
Philipp Zabel856d7d92014-09-29 09:53:44 -030081void coda_write_base(struct coda_ctx *ctx, struct coda_q_data *q_data,
82 struct vb2_buffer *buf, unsigned int reg_y)
83{
84 u32 base_y = vb2_dma_contig_plane_dma_addr(buf, 0);
85 u32 base_cb, base_cr;
86
87 switch (q_data->fourcc) {
88 case V4L2_PIX_FMT_YVU420:
89 /* Switch Cb and Cr for YVU420 format */
90 base_cr = base_y + q_data->bytesperline * q_data->height;
91 base_cb = base_cr + q_data->bytesperline * q_data->height / 4;
92 break;
93 case V4L2_PIX_FMT_YUV420:
Philipp Zabel1cb12cf2014-09-29 09:53:47 -030094 case V4L2_PIX_FMT_NV12:
Philipp Zabel856d7d92014-09-29 09:53:44 -030095 default:
96 base_cb = base_y + q_data->bytesperline * q_data->height;
97 base_cr = base_cb + q_data->bytesperline * q_data->height / 4;
98 break;
Philipp Zabel4de69312014-10-02 14:08:26 -030099 case V4L2_PIX_FMT_YUV422P:
100 base_cb = base_y + q_data->bytesperline * q_data->height;
101 base_cr = base_cb + q_data->bytesperline * q_data->height / 2;
Philipp Zabel856d7d92014-09-29 09:53:44 -0300102 }
103
104 coda_write(ctx->dev, base_y, reg_y);
105 coda_write(ctx->dev, base_cb, reg_y + 4);
106 coda_write(ctx->dev, base_cr, reg_y + 8);
107}
108
Philipp Zabelb96904e2013-05-23 10:42:58 -0300109#define CODA_CODEC(mode, src_fourcc, dst_fourcc, max_w, max_h) \
110 { mode, src_fourcc, dst_fourcc, max_w, max_h }
111
112/*
113 * Arrays of codecs supported by each given version of Coda:
114 * i.MX27 -> codadx6
115 * i.MX5x -> coda7
116 * i.MX6 -> coda960
117 * Use V4L2_PIX_FMT_YUV420 as placeholder for all supported YUV 4:2:0 variants
118 */
Philipp Zabel814c3762014-07-18 07:22:45 -0300119static const struct coda_codec codadx6_codecs[] = {
Philipp Zabelb96904e2013-05-23 10:42:58 -0300120 CODA_CODEC(CODADX6_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 720, 576),
121 CODA_CODEC(CODADX6_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 720, 576),
Philipp Zabeldf1e74c2012-07-02 06:07:10 -0300122};
123
Philipp Zabel814c3762014-07-18 07:22:45 -0300124static const struct coda_codec coda7_codecs[] = {
Philipp Zabelb96904e2013-05-23 10:42:58 -0300125 CODA_CODEC(CODA7_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 1280, 720),
126 CODA_CODEC(CODA7_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 1280, 720),
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300127 CODA_CODEC(CODA7_MODE_ENCODE_MJPG, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_JPEG, 8192, 8192),
Philipp Zabelb0ed05b2014-08-05 14:00:14 -0300128 CODA_CODEC(CODA7_MODE_DECODE_H264, V4L2_PIX_FMT_H264, V4L2_PIX_FMT_YUV420, 1920, 1088),
129 CODA_CODEC(CODA7_MODE_DECODE_MP4, V4L2_PIX_FMT_MPEG4, V4L2_PIX_FMT_YUV420, 1920, 1088),
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300130 CODA_CODEC(CODA7_MODE_DECODE_MJPG, V4L2_PIX_FMT_JPEG, V4L2_PIX_FMT_YUV420, 8192, 8192),
Philipp Zabelb96904e2013-05-23 10:42:58 -0300131};
132
Philipp Zabel814c3762014-07-18 07:22:45 -0300133static const struct coda_codec coda9_codecs[] = {
Philipp Zabelb0ed05b2014-08-05 14:00:14 -0300134 CODA_CODEC(CODA9_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 1920, 1088),
135 CODA_CODEC(CODA9_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 1920, 1088),
136 CODA_CODEC(CODA9_MODE_DECODE_H264, V4L2_PIX_FMT_H264, V4L2_PIX_FMT_YUV420, 1920, 1088),
137 CODA_CODEC(CODA9_MODE_DECODE_MP4, V4L2_PIX_FMT_MPEG4, V4L2_PIX_FMT_YUV420, 1920, 1088),
Philipp Zabel89548442014-07-11 06:36:17 -0300138};
139
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300140struct coda_video_device {
141 const char *name;
142 enum coda_inst_type type;
143 const struct coda_context_ops *ops;
Philipp Zabela22496c2015-01-23 13:51:33 -0300144 bool direct;
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300145 u32 src_formats[CODA_MAX_FORMATS];
146 u32 dst_formats[CODA_MAX_FORMATS];
147};
148
149static const struct coda_video_device coda_bit_encoder = {
150 .name = "coda-encoder",
151 .type = CODA_INST_ENCODER,
152 .ops = &coda_bit_encode_ops,
153 .src_formats = {
154 V4L2_PIX_FMT_YUV420,
155 V4L2_PIX_FMT_YVU420,
156 V4L2_PIX_FMT_NV12,
157 },
158 .dst_formats = {
159 V4L2_PIX_FMT_H264,
160 V4L2_PIX_FMT_MPEG4,
161 },
162};
163
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300164static const struct coda_video_device coda_bit_jpeg_encoder = {
165 .name = "coda-jpeg-encoder",
166 .type = CODA_INST_ENCODER,
167 .ops = &coda_bit_encode_ops,
168 .src_formats = {
169 V4L2_PIX_FMT_YUV420,
170 V4L2_PIX_FMT_YVU420,
171 V4L2_PIX_FMT_NV12,
172 V4L2_PIX_FMT_YUV422P,
173 },
174 .dst_formats = {
175 V4L2_PIX_FMT_JPEG,
176 },
177};
178
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300179static const struct coda_video_device coda_bit_decoder = {
180 .name = "coda-decoder",
181 .type = CODA_INST_DECODER,
182 .ops = &coda_bit_decode_ops,
183 .src_formats = {
184 V4L2_PIX_FMT_H264,
185 V4L2_PIX_FMT_MPEG4,
186 },
187 .dst_formats = {
188 V4L2_PIX_FMT_YUV420,
189 V4L2_PIX_FMT_YVU420,
190 V4L2_PIX_FMT_NV12,
191 },
192};
193
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300194static const struct coda_video_device coda_bit_jpeg_decoder = {
195 .name = "coda-jpeg-decoder",
196 .type = CODA_INST_DECODER,
197 .ops = &coda_bit_decode_ops,
198 .src_formats = {
199 V4L2_PIX_FMT_JPEG,
200 },
201 .dst_formats = {
202 V4L2_PIX_FMT_YUV420,
203 V4L2_PIX_FMT_YVU420,
204 V4L2_PIX_FMT_NV12,
205 V4L2_PIX_FMT_YUV422P,
206 },
207};
208
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300209static const struct coda_video_device *codadx6_video_devices[] = {
210 &coda_bit_encoder,
211};
212
213static const struct coda_video_device *coda7_video_devices[] = {
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300214 &coda_bit_jpeg_encoder,
215 &coda_bit_jpeg_decoder,
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300216 &coda_bit_encoder,
217 &coda_bit_decoder,
218};
219
220static const struct coda_video_device *coda9_video_devices[] = {
221 &coda_bit_encoder,
222 &coda_bit_decoder,
223};
224
Philipp Zabelb96904e2013-05-23 10:42:58 -0300225/*
226 * Normalize all supported YUV 4:2:0 formats to the value used in the codec
227 * tables.
228 */
229static u32 coda_format_normalize_yuv(u32 fourcc)
230{
Philipp Zabel8076c7e2015-07-09 07:10:18 -0300231 switch (fourcc) {
232 case V4L2_PIX_FMT_YUV420:
233 case V4L2_PIX_FMT_YVU420:
234 case V4L2_PIX_FMT_NV12:
235 case V4L2_PIX_FMT_YUV422P:
236 return V4L2_PIX_FMT_YUV420;
237 default:
238 return fourcc;
239 }
Philipp Zabelb96904e2013-05-23 10:42:58 -0300240}
241
Philipp Zabel814c3762014-07-18 07:22:45 -0300242static const struct coda_codec *coda_find_codec(struct coda_dev *dev,
243 int src_fourcc, int dst_fourcc)
Philipp Zabelb96904e2013-05-23 10:42:58 -0300244{
Philipp Zabel814c3762014-07-18 07:22:45 -0300245 const struct coda_codec *codecs = dev->devtype->codecs;
Philipp Zabelb96904e2013-05-23 10:42:58 -0300246 int num_codecs = dev->devtype->num_codecs;
247 int k;
248
249 src_fourcc = coda_format_normalize_yuv(src_fourcc);
250 dst_fourcc = coda_format_normalize_yuv(dst_fourcc);
251 if (src_fourcc == dst_fourcc)
252 return NULL;
253
254 for (k = 0; k < num_codecs; k++) {
255 if (codecs[k].src_fourcc == src_fourcc &&
256 codecs[k].dst_fourcc == dst_fourcc)
Javier Martin186b2502012-07-26 05:53:35 -0300257 break;
258 }
259
Philipp Zabelb96904e2013-05-23 10:42:58 -0300260 if (k == num_codecs)
Javier Martin186b2502012-07-26 05:53:35 -0300261 return NULL;
262
Philipp Zabelb96904e2013-05-23 10:42:58 -0300263 return &codecs[k];
Javier Martin186b2502012-07-26 05:53:35 -0300264}
265
Philipp Zabel57625592013-09-30 10:34:51 -0300266static void coda_get_max_dimensions(struct coda_dev *dev,
Philipp Zabel814c3762014-07-18 07:22:45 -0300267 const struct coda_codec *codec,
Philipp Zabel57625592013-09-30 10:34:51 -0300268 int *max_w, int *max_h)
269{
Philipp Zabel814c3762014-07-18 07:22:45 -0300270 const struct coda_codec *codecs = dev->devtype->codecs;
Philipp Zabel57625592013-09-30 10:34:51 -0300271 int num_codecs = dev->devtype->num_codecs;
272 unsigned int w, h;
273 int k;
274
275 if (codec) {
276 w = codec->max_w;
277 h = codec->max_h;
278 } else {
279 for (k = 0, w = 0, h = 0; k < num_codecs; k++) {
280 w = max(w, codecs[k].max_w);
281 h = max(h, codecs[k].max_h);
282 }
283 }
284
285 if (max_w)
286 *max_w = w;
287 if (max_h)
288 *max_h = h;
289}
290
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300291const struct coda_video_device *to_coda_video_device(struct video_device *vdev)
292{
293 struct coda_dev *dev = video_get_drvdata(vdev);
294 unsigned int i = vdev - dev->vfd;
295
296 if (i >= dev->devtype->num_vdevs)
297 return NULL;
298
299 return dev->devtype->vdevs[i];
300}
301
Philipp Zabel79924ca2014-07-23 12:28:45 -0300302const char *coda_product_name(int product)
Philipp Zabel927933f2013-09-30 10:34:48 -0300303{
304 static char buf[9];
305
306 switch (product) {
307 case CODA_DX6:
308 return "CodaDx6";
309 case CODA_7541:
310 return "CODA7541";
Philipp Zabel89548442014-07-11 06:36:17 -0300311 case CODA_960:
312 return "CODA960";
Philipp Zabel927933f2013-09-30 10:34:48 -0300313 default:
314 snprintf(buf, sizeof(buf), "(0x%04x)", product);
315 return buf;
316 }
317}
318
Javier Martin186b2502012-07-26 05:53:35 -0300319/*
320 * V4L2 ioctl() operations.
321 */
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300322static int coda_querycap(struct file *file, void *priv,
323 struct v4l2_capability *cap)
Javier Martin186b2502012-07-26 05:53:35 -0300324{
Philipp Zabel927933f2013-09-30 10:34:48 -0300325 struct coda_ctx *ctx = fh_to_ctx(priv);
326
Javier Martin186b2502012-07-26 05:53:35 -0300327 strlcpy(cap->driver, CODA_NAME, sizeof(cap->driver));
Philipp Zabel927933f2013-09-30 10:34:48 -0300328 strlcpy(cap->card, coda_product_name(ctx->dev->devtype->product),
329 sizeof(cap->card));
Philipp Zabeldad0e1c2013-05-21 04:18:22 -0300330 strlcpy(cap->bus_info, "platform:" CODA_NAME, sizeof(cap->bus_info));
Philipp Zabel3898e7a2014-07-18 07:22:37 -0300331 cap->device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING;
Javier Martin186b2502012-07-26 05:53:35 -0300332 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
333
334 return 0;
335}
336
Philipp Zabel22e244b2014-07-18 07:22:43 -0300337static int coda_enum_fmt(struct file *file, void *priv,
338 struct v4l2_fmtdesc *f)
Javier Martin186b2502012-07-26 05:53:35 -0300339{
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300340 struct video_device *vdev = video_devdata(file);
341 const struct coda_video_device *cvd = to_coda_video_device(vdev);
342 const u32 *formats;
Philipp Zabel22e244b2014-07-18 07:22:43 -0300343
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300344 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
345 formats = cvd->src_formats;
346 else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
347 formats = cvd->dst_formats;
Philipp Zabel22e244b2014-07-18 07:22:43 -0300348 else
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300349 return -EINVAL;
Javier Martin186b2502012-07-26 05:53:35 -0300350
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300351 if (f->index >= CODA_MAX_FORMATS || formats[f->index] == 0)
352 return -EINVAL;
Javier Martin186b2502012-07-26 05:53:35 -0300353
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300354 f->pixelformat = formats[f->index];
Javier Martin186b2502012-07-26 05:53:35 -0300355
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300356 return 0;
Javier Martin186b2502012-07-26 05:53:35 -0300357}
358
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300359static int coda_g_fmt(struct file *file, void *priv,
360 struct v4l2_format *f)
Javier Martin186b2502012-07-26 05:53:35 -0300361{
Javier Martin186b2502012-07-26 05:53:35 -0300362 struct coda_q_data *q_data;
363 struct coda_ctx *ctx = fh_to_ctx(priv);
364
Javier Martin186b2502012-07-26 05:53:35 -0300365 q_data = get_q_data(ctx, f->type);
Philipp Zabelb9736292014-07-11 06:36:18 -0300366 if (!q_data)
367 return -EINVAL;
Javier Martin186b2502012-07-26 05:53:35 -0300368
369 f->fmt.pix.field = V4L2_FIELD_NONE;
Philipp Zabelb96904e2013-05-23 10:42:58 -0300370 f->fmt.pix.pixelformat = q_data->fourcc;
Javier Martin186b2502012-07-26 05:53:35 -0300371 f->fmt.pix.width = q_data->width;
372 f->fmt.pix.height = q_data->height;
Philipp Zabel2fd6a372014-07-11 06:36:36 -0300373 f->fmt.pix.bytesperline = q_data->bytesperline;
Javier Martin186b2502012-07-26 05:53:35 -0300374
375 f->fmt.pix.sizeimage = q_data->sizeimage;
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300376 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_JPEG)
377 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
378 else
379 f->fmt.pix.colorspace = ctx->colorspace;
Javier Martin186b2502012-07-26 05:53:35 -0300380
381 return 0;
382}
383
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300384static int coda_try_pixelformat(struct coda_ctx *ctx, struct v4l2_format *f)
385{
386 struct coda_q_data *q_data;
387 const u32 *formats;
388 int i;
389
390 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
391 formats = ctx->cvd->src_formats;
392 else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
393 formats = ctx->cvd->dst_formats;
394 else
395 return -EINVAL;
396
397 for (i = 0; i < CODA_MAX_FORMATS; i++) {
398 if (formats[i] == f->fmt.pix.pixelformat) {
399 f->fmt.pix.pixelformat = formats[i];
400 return 0;
401 }
402 }
403
404 /* Fall back to currently set pixelformat */
405 q_data = get_q_data(ctx, f->type);
406 f->fmt.pix.pixelformat = q_data->fourcc;
Javier Martin186b2502012-07-26 05:53:35 -0300407
408 return 0;
409}
410
Philipp Zabel8e428d52015-01-23 13:51:29 -0300411static unsigned int coda_estimate_sizeimage(struct coda_ctx *ctx, u32 sizeimage,
412 u32 width, u32 height)
413{
414 /*
415 * This is a rough estimate for sensible compressed buffer
416 * sizes (between 1 and 16 bits per pixel). This could be
417 * improved by better format specific worst case estimates.
418 */
419 return round_up(clamp(sizeimage, width * height / 8,
420 width * height * 2), PAGE_SIZE);
421}
422
Philipp Zabel814c3762014-07-18 07:22:45 -0300423static int coda_try_fmt(struct coda_ctx *ctx, const struct coda_codec *codec,
Philipp Zabel57625592013-09-30 10:34:51 -0300424 struct v4l2_format *f)
Javier Martin186b2502012-07-26 05:53:35 -0300425{
Philipp Zabel57625592013-09-30 10:34:51 -0300426 struct coda_dev *dev = ctx->dev;
Philipp Zabelb96904e2013-05-23 10:42:58 -0300427 unsigned int max_w, max_h;
Javier Martin186b2502012-07-26 05:53:35 -0300428 enum v4l2_field field;
429
430 field = f->fmt.pix.field;
431 if (field == V4L2_FIELD_ANY)
432 field = V4L2_FIELD_NONE;
433 else if (V4L2_FIELD_NONE != field)
434 return -EINVAL;
435
436 /* V4L2 specification suggests the driver corrects the format struct
437 * if any of the dimensions is unsupported */
438 f->fmt.pix.field = field;
439
Philipp Zabel57625592013-09-30 10:34:51 -0300440 coda_get_max_dimensions(dev, codec, &max_w, &max_h);
441 v4l_bound_align_image(&f->fmt.pix.width, MIN_W, max_w, W_ALIGN,
442 &f->fmt.pix.height, MIN_H, max_h, H_ALIGN,
443 S_ALIGN);
Philipp Zabelb96904e2013-05-23 10:42:58 -0300444
Philipp Zabel57625592013-09-30 10:34:51 -0300445 switch (f->fmt.pix.pixelformat) {
446 case V4L2_PIX_FMT_YUV420:
447 case V4L2_PIX_FMT_YVU420:
Philipp Zabel1cb12cf2014-09-29 09:53:47 -0300448 case V4L2_PIX_FMT_NV12:
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300449 /*
450 * Frame stride must be at least multiple of 8,
451 * but multiple of 16 for h.264 or JPEG 4:2:x
452 */
Philipp Zabel451dfe52014-07-11 06:36:39 -0300453 f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 16);
Philipp Zabel47cf0c62013-05-23 10:42:54 -0300454 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline *
Philipp Zabel451d43a2012-07-26 09:18:27 -0300455 f->fmt.pix.height * 3 / 2;
Philipp Zabel57625592013-09-30 10:34:51 -0300456 break;
Philipp Zabel4de69312014-10-02 14:08:26 -0300457 case V4L2_PIX_FMT_YUV422P:
458 f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 16);
459 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline *
460 f->fmt.pix.height * 2;
461 break;
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300462 case V4L2_PIX_FMT_JPEG:
463 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
464 /* fallthrough */
Philipp Zabel57625592013-09-30 10:34:51 -0300465 case V4L2_PIX_FMT_H264:
466 case V4L2_PIX_FMT_MPEG4:
Javier Martin186b2502012-07-26 05:53:35 -0300467 f->fmt.pix.bytesperline = 0;
Philipp Zabel8e428d52015-01-23 13:51:29 -0300468 f->fmt.pix.sizeimage = coda_estimate_sizeimage(ctx,
469 f->fmt.pix.sizeimage,
470 f->fmt.pix.width,
471 f->fmt.pix.height);
Philipp Zabel57625592013-09-30 10:34:51 -0300472 break;
473 default:
474 BUG();
Javier Martin186b2502012-07-26 05:53:35 -0300475 }
476
477 return 0;
478}
479
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300480static int coda_try_fmt_vid_cap(struct file *file, void *priv,
481 struct v4l2_format *f)
Javier Martin186b2502012-07-26 05:53:35 -0300482{
Javier Martin186b2502012-07-26 05:53:35 -0300483 struct coda_ctx *ctx = fh_to_ctx(priv);
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300484 const struct coda_q_data *q_data_src;
485 const struct coda_codec *codec;
Philipp Zabel918c66f2013-06-27 06:59:01 -0300486 struct vb2_queue *src_vq;
487 int ret;
Javier Martin186b2502012-07-26 05:53:35 -0300488
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300489 ret = coda_try_pixelformat(ctx, f);
490 if (ret < 0)
491 return ret;
492
493 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
494
Philipp Zabel918c66f2013-06-27 06:59:01 -0300495 /*
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300496 * If the source format is already fixed, only allow the same output
497 * resolution
Philipp Zabel918c66f2013-06-27 06:59:01 -0300498 */
Philipp Zabel14604e32014-07-11 06:36:22 -0300499 src_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
Philipp Zabel918c66f2013-06-27 06:59:01 -0300500 if (vb2_is_streaming(src_vq)) {
Philipp Zabel91b5841e2014-07-18 07:22:41 -0300501 f->fmt.pix.width = q_data_src->width;
502 f->fmt.pix.height = q_data_src->height;
Philipp Zabel918c66f2013-06-27 06:59:01 -0300503 }
Javier Martin186b2502012-07-26 05:53:35 -0300504
505 f->fmt.pix.colorspace = ctx->colorspace;
506
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300507 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
508 codec = coda_find_codec(ctx->dev, q_data_src->fourcc,
509 f->fmt.pix.pixelformat);
510 if (!codec)
511 return -EINVAL;
512
Philipp Zabel57625592013-09-30 10:34:51 -0300513 ret = coda_try_fmt(ctx, codec, f);
Philipp Zabel918c66f2013-06-27 06:59:01 -0300514 if (ret < 0)
515 return ret;
516
517 /* The h.264 decoder only returns complete 16x16 macroblocks */
518 if (codec && codec->src_fourcc == V4L2_PIX_FMT_H264) {
Philipp Zabel1b0ed7b2014-07-11 06:36:37 -0300519 f->fmt.pix.width = f->fmt.pix.width;
Philipp Zabel918c66f2013-06-27 06:59:01 -0300520 f->fmt.pix.height = round_up(f->fmt.pix.height, 16);
Philipp Zabel1b0ed7b2014-07-11 06:36:37 -0300521 f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 16);
Philipp Zabel918c66f2013-06-27 06:59:01 -0300522 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline *
523 f->fmt.pix.height * 3 / 2;
524 }
525
526 return 0;
Javier Martin186b2502012-07-26 05:53:35 -0300527}
528
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300529static int coda_try_fmt_vid_out(struct file *file, void *priv,
530 struct v4l2_format *f)
Javier Martin186b2502012-07-26 05:53:35 -0300531{
532 struct coda_ctx *ctx = fh_to_ctx(priv);
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300533 struct coda_dev *dev = ctx->dev;
534 const struct coda_q_data *q_data_dst;
535 const struct coda_codec *codec;
536 int ret;
Javier Martin186b2502012-07-26 05:53:35 -0300537
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300538 ret = coda_try_pixelformat(ctx, f);
539 if (ret < 0)
540 return ret;
Javier Martin186b2502012-07-26 05:53:35 -0300541
Philipp Zabel5f9826e2015-01-23 13:51:21 -0300542 switch (f->fmt.pix.colorspace) {
543 case V4L2_COLORSPACE_REC709:
544 case V4L2_COLORSPACE_JPEG:
545 break;
546 default:
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300547 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_JPEG)
548 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
549 else
550 f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709;
Javier Martin186b2502012-07-26 05:53:35 -0300551 }
552
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300553 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
554 codec = coda_find_codec(dev, f->fmt.pix.pixelformat, q_data_dst->fourcc);
Javier Martin186b2502012-07-26 05:53:35 -0300555
556 return coda_try_fmt(ctx, codec, f);
557}
558
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300559static int coda_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f)
Javier Martin186b2502012-07-26 05:53:35 -0300560{
561 struct coda_q_data *q_data;
562 struct vb2_queue *vq;
Javier Martin186b2502012-07-26 05:53:35 -0300563
Philipp Zabel14604e32014-07-11 06:36:22 -0300564 vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
Javier Martin186b2502012-07-26 05:53:35 -0300565 if (!vq)
566 return -EINVAL;
567
568 q_data = get_q_data(ctx, f->type);
569 if (!q_data)
570 return -EINVAL;
571
572 if (vb2_is_busy(vq)) {
573 v4l2_err(&ctx->dev->v4l2_dev, "%s queue busy\n", __func__);
574 return -EBUSY;
575 }
576
Philipp Zabelb96904e2013-05-23 10:42:58 -0300577 q_data->fourcc = f->fmt.pix.pixelformat;
Javier Martin186b2502012-07-26 05:53:35 -0300578 q_data->width = f->fmt.pix.width;
579 q_data->height = f->fmt.pix.height;
Philipp Zabel2fd6a372014-07-11 06:36:36 -0300580 q_data->bytesperline = f->fmt.pix.bytesperline;
Philipp Zabel451d43a2012-07-26 09:18:27 -0300581 q_data->sizeimage = f->fmt.pix.sizeimage;
Philipp Zabel52c41672014-07-11 06:36:19 -0300582 q_data->rect.left = 0;
583 q_data->rect.top = 0;
584 q_data->rect.width = f->fmt.pix.width;
585 q_data->rect.height = f->fmt.pix.height;
Javier Martin186b2502012-07-26 05:53:35 -0300586
587 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
588 "Setting format for type %d, wxh: %dx%d, fmt: %d\n",
Philipp Zabelb96904e2013-05-23 10:42:58 -0300589 f->type, q_data->width, q_data->height, q_data->fourcc);
Javier Martin186b2502012-07-26 05:53:35 -0300590
591 return 0;
592}
593
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300594static int coda_s_fmt_vid_cap(struct file *file, void *priv,
595 struct v4l2_format *f)
Javier Martin186b2502012-07-26 05:53:35 -0300596{
Philipp Zabelb96904e2013-05-23 10:42:58 -0300597 struct coda_ctx *ctx = fh_to_ctx(priv);
Javier Martin186b2502012-07-26 05:53:35 -0300598 int ret;
599
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300600 ret = coda_try_fmt_vid_cap(file, priv, f);
Javier Martin186b2502012-07-26 05:53:35 -0300601 if (ret)
602 return ret;
603
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300604 return coda_s_fmt(ctx, f);
Javier Martin186b2502012-07-26 05:53:35 -0300605}
606
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300607static int coda_s_fmt_vid_out(struct file *file, void *priv,
608 struct v4l2_format *f)
Javier Martin186b2502012-07-26 05:53:35 -0300609{
610 struct coda_ctx *ctx = fh_to_ctx(priv);
Philipp Zabelf95a6ce2014-08-05 14:00:19 -0300611 struct v4l2_format f_cap;
Javier Martin186b2502012-07-26 05:53:35 -0300612 int ret;
613
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300614 ret = coda_try_fmt_vid_out(file, priv, f);
Javier Martin186b2502012-07-26 05:53:35 -0300615 if (ret)
616 return ret;
617
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300618 ret = coda_s_fmt(ctx, f);
Javier Martin186b2502012-07-26 05:53:35 -0300619 if (ret)
Philipp Zabel2dc546d2014-08-05 14:00:18 -0300620 return ret;
621
622 ctx->colorspace = f->fmt.pix.colorspace;
Javier Martin186b2502012-07-26 05:53:35 -0300623
Philipp Zabel1c2f6a92015-01-23 13:51:22 -0300624 memset(&f_cap, 0, sizeof(f_cap));
Philipp Zabelf95a6ce2014-08-05 14:00:19 -0300625 f_cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
626 coda_g_fmt(file, priv, &f_cap);
627 f_cap.fmt.pix.width = f->fmt.pix.width;
628 f_cap.fmt.pix.height = f->fmt.pix.height;
629
630 ret = coda_try_fmt_vid_cap(file, priv, &f_cap);
631 if (ret)
632 return ret;
633
634 return coda_s_fmt(ctx, &f_cap);
Javier Martin186b2502012-07-26 05:53:35 -0300635}
636
Philipp Zabel73751da2015-03-24 14:30:51 -0300637static int coda_reqbufs(struct file *file, void *priv,
638 struct v4l2_requestbuffers *rb)
639{
640 struct coda_ctx *ctx = fh_to_ctx(priv);
641 int ret;
642
643 ret = v4l2_m2m_reqbufs(file, ctx->fh.m2m_ctx, rb);
644 if (ret)
645 return ret;
646
647 /*
648 * Allow to allocate instance specific per-context buffers, such as
649 * bitstream ringbuffer, slice buffer, work buffer, etc. if needed.
650 */
651 if (rb->type == V4L2_BUF_TYPE_VIDEO_OUTPUT && ctx->ops->reqbufs)
652 return ctx->ops->reqbufs(ctx, rb);
653
654 return 0;
655}
656
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300657static int coda_qbuf(struct file *file, void *priv,
658 struct v4l2_buffer *buf)
Javier Martin186b2502012-07-26 05:53:35 -0300659{
660 struct coda_ctx *ctx = fh_to_ctx(priv);
661
Philipp Zabel14604e32014-07-11 06:36:22 -0300662 return v4l2_m2m_qbuf(file, ctx->fh.m2m_ctx, buf);
Javier Martin186b2502012-07-26 05:53:35 -0300663}
664
Philipp Zabel918c66f2013-06-27 06:59:01 -0300665static bool coda_buf_is_end_of_stream(struct coda_ctx *ctx,
Philipp Zabel9f2bfb32015-05-04 07:51:07 -0300666 struct vb2_buffer *buf)
Philipp Zabel918c66f2013-06-27 06:59:01 -0300667{
668 struct vb2_queue *src_vq;
669
Philipp Zabel14604e32014-07-11 06:36:22 -0300670 src_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
Philipp Zabel918c66f2013-06-27 06:59:01 -0300671
672 return ((ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) &&
Philipp Zabel9f2bfb32015-05-04 07:51:07 -0300673 (buf->v4l2_buf.sequence == (ctx->qsequence - 1)));
Philipp Zabel918c66f2013-06-27 06:59:01 -0300674}
675
Philipp Zabel9f2bfb32015-05-04 07:51:07 -0300676void coda_m2m_buf_done(struct coda_ctx *ctx, struct vb2_buffer *buf,
677 enum vb2_buffer_state state)
Javier Martin186b2502012-07-26 05:53:35 -0300678{
Philipp Zabel9f2bfb32015-05-04 07:51:07 -0300679 const struct v4l2_event eos_event = {
680 .type = V4L2_EVENT_EOS
681 };
Javier Martin186b2502012-07-26 05:53:35 -0300682
Philipp Zabel9f2bfb32015-05-04 07:51:07 -0300683 if (coda_buf_is_end_of_stream(ctx, buf)) {
684 buf->v4l2_buf.flags |= V4L2_BUF_FLAG_LAST;
Philipp Zabel918c66f2013-06-27 06:59:01 -0300685
686 v4l2_event_queue_fh(&ctx->fh, &eos_event);
687 }
688
Philipp Zabel9f2bfb32015-05-04 07:51:07 -0300689 v4l2_m2m_buf_done(buf, state);
Javier Martin186b2502012-07-26 05:53:35 -0300690}
691
Philipp Zabel52c41672014-07-11 06:36:19 -0300692static int coda_g_selection(struct file *file, void *fh,
693 struct v4l2_selection *s)
694{
695 struct coda_ctx *ctx = fh_to_ctx(fh);
696 struct coda_q_data *q_data;
697 struct v4l2_rect r, *rsel;
698
699 q_data = get_q_data(ctx, s->type);
700 if (!q_data)
701 return -EINVAL;
702
703 r.left = 0;
704 r.top = 0;
705 r.width = q_data->width;
706 r.height = q_data->height;
707 rsel = &q_data->rect;
708
709 switch (s->target) {
710 case V4L2_SEL_TGT_CROP_DEFAULT:
711 case V4L2_SEL_TGT_CROP_BOUNDS:
712 rsel = &r;
713 /* fallthrough */
714 case V4L2_SEL_TGT_CROP:
715 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
716 return -EINVAL;
717 break;
718 case V4L2_SEL_TGT_COMPOSE_BOUNDS:
719 case V4L2_SEL_TGT_COMPOSE_PADDED:
720 rsel = &r;
721 /* fallthrough */
722 case V4L2_SEL_TGT_COMPOSE:
723 case V4L2_SEL_TGT_COMPOSE_DEFAULT:
724 if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
725 return -EINVAL;
726 break;
727 default:
728 return -EINVAL;
729 }
730
731 s->r = *rsel;
732
733 return 0;
734}
735
Philipp Zabel64ba40a2013-09-30 10:34:52 -0300736static int coda_try_decoder_cmd(struct file *file, void *fh,
737 struct v4l2_decoder_cmd *dc)
Philipp Zabel918c66f2013-06-27 06:59:01 -0300738{
Philipp Zabel918c66f2013-06-27 06:59:01 -0300739 if (dc->cmd != V4L2_DEC_CMD_STOP)
740 return -EINVAL;
741
Philipp Zabel64ba40a2013-09-30 10:34:52 -0300742 if (dc->flags & V4L2_DEC_CMD_STOP_TO_BLACK)
Philipp Zabel918c66f2013-06-27 06:59:01 -0300743 return -EINVAL;
744
Philipp Zabel64ba40a2013-09-30 10:34:52 -0300745 if (!(dc->flags & V4L2_DEC_CMD_STOP_IMMEDIATELY) && (dc->stop.pts != 0))
Philipp Zabel918c66f2013-06-27 06:59:01 -0300746 return -EINVAL;
747
Philipp Zabel64ba40a2013-09-30 10:34:52 -0300748 return 0;
749}
750
751static int coda_decoder_cmd(struct file *file, void *fh,
752 struct v4l2_decoder_cmd *dc)
753{
754 struct coda_ctx *ctx = fh_to_ctx(fh);
755 int ret;
756
757 ret = coda_try_decoder_cmd(file, fh, dc);
758 if (ret < 0)
759 return ret;
760
761 /* Ignore decoder stop command silently in encoder context */
Philipp Zabel918c66f2013-06-27 06:59:01 -0300762 if (ctx->inst_type != CODA_INST_DECODER)
Philipp Zabel64ba40a2013-09-30 10:34:52 -0300763 return 0;
Philipp Zabel918c66f2013-06-27 06:59:01 -0300764
Philipp Zabel347bb7f2014-07-23 12:28:42 -0300765 /* Set the stream-end flag on this context */
766 coda_bit_stream_end_flag(ctx);
Philipp Zabel84e23652014-07-11 06:36:34 -0300767 ctx->hold = false;
Michael Olbrichf3497da2014-07-11 06:36:30 -0300768 v4l2_m2m_try_schedule(ctx->fh.m2m_ctx);
Philipp Zabel89548442014-07-11 06:36:17 -0300769
Philipp Zabel918c66f2013-06-27 06:59:01 -0300770 return 0;
771}
772
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300773static int coda_subscribe_event(struct v4l2_fh *fh,
774 const struct v4l2_event_subscription *sub)
Philipp Zabel918c66f2013-06-27 06:59:01 -0300775{
776 switch (sub->type) {
777 case V4L2_EVENT_EOS:
778 return v4l2_event_subscribe(fh, sub, 0, NULL);
779 default:
780 return v4l2_ctrl_subscribe_event(fh, sub);
781 }
Javier Martin186b2502012-07-26 05:53:35 -0300782}
783
784static const struct v4l2_ioctl_ops coda_ioctl_ops = {
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300785 .vidioc_querycap = coda_querycap,
Javier Martin186b2502012-07-26 05:53:35 -0300786
Philipp Zabel22e244b2014-07-18 07:22:43 -0300787 .vidioc_enum_fmt_vid_cap = coda_enum_fmt,
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300788 .vidioc_g_fmt_vid_cap = coda_g_fmt,
789 .vidioc_try_fmt_vid_cap = coda_try_fmt_vid_cap,
790 .vidioc_s_fmt_vid_cap = coda_s_fmt_vid_cap,
Javier Martin186b2502012-07-26 05:53:35 -0300791
Philipp Zabel22e244b2014-07-18 07:22:43 -0300792 .vidioc_enum_fmt_vid_out = coda_enum_fmt,
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300793 .vidioc_g_fmt_vid_out = coda_g_fmt,
794 .vidioc_try_fmt_vid_out = coda_try_fmt_vid_out,
795 .vidioc_s_fmt_vid_out = coda_s_fmt_vid_out,
Javier Martin186b2502012-07-26 05:53:35 -0300796
Philipp Zabel73751da2015-03-24 14:30:51 -0300797 .vidioc_reqbufs = coda_reqbufs,
Philipp Zabel152ea1c2014-07-11 06:36:21 -0300798 .vidioc_querybuf = v4l2_m2m_ioctl_querybuf,
Javier Martin186b2502012-07-26 05:53:35 -0300799
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300800 .vidioc_qbuf = coda_qbuf,
Philipp Zabel152ea1c2014-07-11 06:36:21 -0300801 .vidioc_expbuf = v4l2_m2m_ioctl_expbuf,
Philipp Zabel9f2bfb32015-05-04 07:51:07 -0300802 .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf,
Philipp Zabel152ea1c2014-07-11 06:36:21 -0300803 .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs,
Javier Martin186b2502012-07-26 05:53:35 -0300804
Philipp Zabel152ea1c2014-07-11 06:36:21 -0300805 .vidioc_streamon = v4l2_m2m_ioctl_streamon,
806 .vidioc_streamoff = v4l2_m2m_ioctl_streamoff,
Philipp Zabel918c66f2013-06-27 06:59:01 -0300807
Philipp Zabel52c41672014-07-11 06:36:19 -0300808 .vidioc_g_selection = coda_g_selection,
809
Philipp Zabel64ba40a2013-09-30 10:34:52 -0300810 .vidioc_try_decoder_cmd = coda_try_decoder_cmd,
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300811 .vidioc_decoder_cmd = coda_decoder_cmd,
Philipp Zabel918c66f2013-06-27 06:59:01 -0300812
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300813 .vidioc_subscribe_event = coda_subscribe_event,
Philipp Zabel918c66f2013-06-27 06:59:01 -0300814 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
Javier Martin186b2502012-07-26 05:53:35 -0300815};
816
Philipp Zabel79924ca2014-07-23 12:28:45 -0300817void coda_set_gdi_regs(struct coda_ctx *ctx)
Philipp Zabel89548442014-07-11 06:36:17 -0300818{
819 struct gdi_tiled_map *tiled_map = &ctx->tiled_map;
820 struct coda_dev *dev = ctx->dev;
821 int i;
822
823 for (i = 0; i < 16; i++)
824 coda_write(dev, tiled_map->xy2ca_map[i],
825 CODA9_GDI_XY2_CAS_0 + 4 * i);
826 for (i = 0; i < 4; i++)
827 coda_write(dev, tiled_map->xy2ba_map[i],
828 CODA9_GDI_XY2_BA_0 + 4 * i);
829 for (i = 0; i < 16; i++)
830 coda_write(dev, tiled_map->xy2ra_map[i],
831 CODA9_GDI_XY2_RAS_0 + 4 * i);
832 coda_write(dev, tiled_map->xy2rbc_config, CODA9_GDI_XY2_RBC_CONFIG);
833 for (i = 0; i < 32; i++)
834 coda_write(dev, tiled_map->rbc2axi_map[i],
835 CODA9_GDI_RBC2_AXI_0 + 4 * i);
836}
837
Javier Martin186b2502012-07-26 05:53:35 -0300838/*
839 * Mem-to-mem operations.
840 */
Philipp Zabel477c1cf2013-06-21 03:55:33 -0300841
842static void coda_device_run(void *m2m_priv)
843{
844 struct coda_ctx *ctx = m2m_priv;
845 struct coda_dev *dev = ctx->dev;
Philipp Zabel32b6f202014-07-11 06:36:20 -0300846
847 queue_work(dev->workqueue, &ctx->pic_run_work);
848}
849
Philipp Zabel32b6f202014-07-11 06:36:20 -0300850static void coda_pic_run_work(struct work_struct *work)
851{
852 struct coda_ctx *ctx = container_of(work, struct coda_ctx, pic_run_work);
853 struct coda_dev *dev = ctx->dev;
Philipp Zabel918c66f2013-06-27 06:59:01 -0300854 int ret;
855
856 mutex_lock(&ctx->buffer_mutex);
Philipp Zabel477c1cf2013-06-21 03:55:33 -0300857 mutex_lock(&dev->coda_mutex);
858
Philipp Zabela1192a12014-07-23 12:28:40 -0300859 ret = ctx->ops->prepare_run(ctx);
860 if (ret < 0 && ctx->inst_type == CODA_INST_DECODER) {
861 mutex_unlock(&dev->coda_mutex);
862 mutex_unlock(&ctx->buffer_mutex);
863 /* job_finish scheduled by prepare_decode */
864 return;
Philipp Zabel10436672012-07-02 09:03:55 -0300865 }
866
Philipp Zabelf23797b2014-08-06 08:02:23 -0300867 if (!wait_for_completion_timeout(&ctx->completion,
868 msecs_to_jiffies(1000))) {
Philipp Zabel32b6f202014-07-11 06:36:20 -0300869 dev_err(&dev->plat_dev->dev, "CODA PIC_RUN timeout\n");
Philipp Zabel84e23652014-07-11 06:36:34 -0300870
871 ctx->hold = true;
Philipp Zabel8f452842014-07-11 06:36:35 -0300872
873 coda_hw_reset(ctx);
Philipp Zabel32b6f202014-07-11 06:36:20 -0300874 } else if (!ctx->aborting) {
Philipp Zabela1192a12014-07-23 12:28:40 -0300875 ctx->ops->finish_run(ctx);
Philipp Zabel32b6f202014-07-11 06:36:20 -0300876 }
877
Philipp Zabel747d7642015-01-23 13:51:31 -0300878 if ((ctx->aborting || (!ctx->streamon_cap && !ctx->streamon_out)) &&
879 ctx->ops->seq_end_work)
Philipp Zabel32b6f202014-07-11 06:36:20 -0300880 queue_work(dev->workqueue, &ctx->seq_end_work);
881
882 mutex_unlock(&dev->coda_mutex);
883 mutex_unlock(&ctx->buffer_mutex);
884
Philipp Zabel14604e32014-07-11 06:36:22 -0300885 v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx);
Javier Martin186b2502012-07-26 05:53:35 -0300886}
887
888static int coda_job_ready(void *m2m_priv)
889{
890 struct coda_ctx *ctx = m2m_priv;
Philipp Zabel2cf251c2015-07-09 07:10:20 -0300891 int src_bufs = v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx);
Javier Martin186b2502012-07-26 05:53:35 -0300892
893 /*
894 * For both 'P' and 'key' frame cases 1 picture
Philipp Zabel9082a7c2013-06-21 03:55:31 -0300895 * and 1 frame are needed. In the decoder case,
896 * the compressed frame can be in the bitstream.
Javier Martin186b2502012-07-26 05:53:35 -0300897 */
Philipp Zabel2cf251c2015-07-09 07:10:20 -0300898 if (!src_bufs && ctx->inst_type != CODA_INST_DECODER) {
Javier Martin186b2502012-07-26 05:53:35 -0300899 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
900 "not ready: not enough video buffers.\n");
901 return 0;
902 }
903
Philipp Zabel14604e32014-07-11 06:36:22 -0300904 if (!v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx)) {
Philipp Zabel9082a7c2013-06-21 03:55:31 -0300905 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
906 "not ready: not enough video capture buffers.\n");
907 return 0;
908 }
909
Philipp Zabela22496c2015-01-23 13:51:33 -0300910 if (ctx->inst_type == CODA_INST_DECODER && ctx->use_bit) {
Philipp Zabel47f3fa62015-07-09 07:10:21 -0300911 bool stream_end = ctx->bit_stream_param &
912 CODA_BIT_STREAM_END_FLAG;
913 int num_metas = ctx->num_metas;
Philipp Zabelf77fd8a2015-01-23 13:51:20 -0300914
Philipp Zabel2cf251c2015-07-09 07:10:20 -0300915 if (ctx->hold && !src_bufs) {
Philipp Zabelf77fd8a2015-01-23 13:51:20 -0300916 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
917 "%d: not ready: on hold for more buffers.\n",
918 ctx->idx);
919 return 0;
920 }
921
Philipp Zabelf77fd8a2015-01-23 13:51:20 -0300922 if (!stream_end && (num_metas + src_bufs) < 2) {
923 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
924 "%d: not ready: need 2 buffers available (%d, %d)\n",
925 ctx->idx, num_metas, src_bufs);
926 return 0;
927 }
928
929
Philipp Zabel2cf251c2015-07-09 07:10:20 -0300930 if (!src_bufs && !stream_end &&
931 (coda_get_bitstream_payload(ctx) < 512)) {
Philipp Zabelf77fd8a2015-01-23 13:51:20 -0300932 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
933 "%d: not ready: not enough bitstream data (%d).\n",
934 ctx->idx, coda_get_bitstream_payload(ctx));
935 return 0;
936 }
Philipp Zabel918c66f2013-06-27 06:59:01 -0300937 }
938
Philipp Zabel3e748262013-05-23 10:43:01 -0300939 if (ctx->aborting) {
940 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
941 "not ready: aborting\n");
942 return 0;
943 }
944
Javier Martin186b2502012-07-26 05:53:35 -0300945 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
946 "job ready\n");
Philipp Zabel47f3fa62015-07-09 07:10:21 -0300947
Javier Martin186b2502012-07-26 05:53:35 -0300948 return 1;
949}
950
951static void coda_job_abort(void *priv)
952{
953 struct coda_ctx *ctx = priv;
Javier Martin186b2502012-07-26 05:53:35 -0300954
955 ctx->aborting = 1;
956
957 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
958 "Aborting task\n");
Javier Martin186b2502012-07-26 05:53:35 -0300959}
960
961static void coda_lock(void *m2m_priv)
962{
963 struct coda_ctx *ctx = m2m_priv;
964 struct coda_dev *pcdev = ctx->dev;
Philipp Zabelf23797b2014-08-06 08:02:23 -0300965
Javier Martin186b2502012-07-26 05:53:35 -0300966 mutex_lock(&pcdev->dev_mutex);
967}
968
969static void coda_unlock(void *m2m_priv)
970{
971 struct coda_ctx *ctx = m2m_priv;
972 struct coda_dev *pcdev = ctx->dev;
Philipp Zabelf23797b2014-08-06 08:02:23 -0300973
Javier Martin186b2502012-07-26 05:53:35 -0300974 mutex_unlock(&pcdev->dev_mutex);
975}
976
Philipp Zabel814c3762014-07-18 07:22:45 -0300977static const struct v4l2_m2m_ops coda_m2m_ops = {
Javier Martin186b2502012-07-26 05:53:35 -0300978 .device_run = coda_device_run,
979 .job_ready = coda_job_ready,
980 .job_abort = coda_job_abort,
981 .lock = coda_lock,
982 .unlock = coda_unlock,
983};
984
Philipp Zabel89548442014-07-11 06:36:17 -0300985static void coda_set_tiled_map_type(struct coda_ctx *ctx, int tiled_map_type)
986{
987 struct gdi_tiled_map *tiled_map = &ctx->tiled_map;
988 int luma_map, chro_map, i;
989
990 memset(tiled_map, 0, sizeof(*tiled_map));
991
992 luma_map = 64;
993 chro_map = 64;
994 tiled_map->map_type = tiled_map_type;
995 for (i = 0; i < 16; i++)
996 tiled_map->xy2ca_map[i] = luma_map << 8 | chro_map;
997 for (i = 0; i < 4; i++)
998 tiled_map->xy2ba_map[i] = luma_map << 8 | chro_map;
999 for (i = 0; i < 16; i++)
1000 tiled_map->xy2ra_map[i] = luma_map << 8 | chro_map;
1001
1002 if (tiled_map_type == GDI_LINEAR_FRAME_MAP) {
1003 tiled_map->xy2rbc_config = 0;
1004 } else {
1005 dev_err(&ctx->dev->plat_dev->dev, "invalid map type: %d\n",
1006 tiled_map_type);
1007 return;
1008 }
1009}
1010
Javier Martin186b2502012-07-26 05:53:35 -03001011static void set_default_params(struct coda_ctx *ctx)
1012{
Philipp Zabel8e428d52015-01-23 13:51:29 -03001013 unsigned int max_w, max_h, usize, csize;
Philipp Zabelb96904e2013-05-23 10:42:58 -03001014
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001015 ctx->codec = coda_find_codec(ctx->dev, ctx->cvd->src_formats[0],
1016 ctx->cvd->dst_formats[0]);
Philipp Zabeld4c6a412014-10-02 14:08:35 -03001017 max_w = min(ctx->codec->max_w, 1920U);
1018 max_h = min(ctx->codec->max_h, 1088U);
Philipp Zabel8e428d52015-01-23 13:51:29 -03001019 usize = max_w * max_h * 3 / 2;
1020 csize = coda_estimate_sizeimage(ctx, usize, max_w, max_h);
Javier Martin186b2502012-07-26 05:53:35 -03001021
Philipp Zabel121cacf2014-07-18 07:22:42 -03001022 ctx->params.codec_mode = ctx->codec->mode;
Javier Martin186b2502012-07-26 05:53:35 -03001023 ctx->colorspace = V4L2_COLORSPACE_REC709;
1024 ctx->params.framerate = 30;
Javier Martin186b2502012-07-26 05:53:35 -03001025
1026 /* Default formats for output and input queues */
Philipp Zabelb96904e2013-05-23 10:42:58 -03001027 ctx->q_data[V4L2_M2M_SRC].fourcc = ctx->codec->src_fourcc;
1028 ctx->q_data[V4L2_M2M_DST].fourcc = ctx->codec->dst_fourcc;
1029 ctx->q_data[V4L2_M2M_SRC].width = max_w;
1030 ctx->q_data[V4L2_M2M_SRC].height = max_h;
Philipp Zabelb96904e2013-05-23 10:42:58 -03001031 ctx->q_data[V4L2_M2M_DST].width = max_w;
1032 ctx->q_data[V4L2_M2M_DST].height = max_h;
Philipp Zabel121cacf2014-07-18 07:22:42 -03001033 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_YUV420) {
1034 ctx->q_data[V4L2_M2M_SRC].bytesperline = max_w;
Philipp Zabel8e428d52015-01-23 13:51:29 -03001035 ctx->q_data[V4L2_M2M_SRC].sizeimage = usize;
Philipp Zabel121cacf2014-07-18 07:22:42 -03001036 ctx->q_data[V4L2_M2M_DST].bytesperline = 0;
Philipp Zabel8e428d52015-01-23 13:51:29 -03001037 ctx->q_data[V4L2_M2M_DST].sizeimage = csize;
Philipp Zabel121cacf2014-07-18 07:22:42 -03001038 } else {
1039 ctx->q_data[V4L2_M2M_SRC].bytesperline = 0;
Philipp Zabel8e428d52015-01-23 13:51:29 -03001040 ctx->q_data[V4L2_M2M_SRC].sizeimage = csize;
Philipp Zabel121cacf2014-07-18 07:22:42 -03001041 ctx->q_data[V4L2_M2M_DST].bytesperline = max_w;
Philipp Zabel8e428d52015-01-23 13:51:29 -03001042 ctx->q_data[V4L2_M2M_DST].sizeimage = usize;
Philipp Zabel121cacf2014-07-18 07:22:42 -03001043 }
Philipp Zabel52c41672014-07-11 06:36:19 -03001044 ctx->q_data[V4L2_M2M_SRC].rect.width = max_w;
1045 ctx->q_data[V4L2_M2M_SRC].rect.height = max_h;
1046 ctx->q_data[V4L2_M2M_DST].rect.width = max_w;
1047 ctx->q_data[V4L2_M2M_DST].rect.height = max_h;
Philipp Zabel89548442014-07-11 06:36:17 -03001048
1049 if (ctx->dev->devtype->product == CODA_960)
1050 coda_set_tiled_map_type(ctx, GDI_LINEAR_FRAME_MAP);
Javier Martin186b2502012-07-26 05:53:35 -03001051}
1052
1053/*
1054 * Queue operations
1055 */
1056static int coda_queue_setup(struct vb2_queue *vq,
1057 const struct v4l2_format *fmt,
1058 unsigned int *nbuffers, unsigned int *nplanes,
1059 unsigned int sizes[], void *alloc_ctxs[])
1060{
1061 struct coda_ctx *ctx = vb2_get_drv_priv(vq);
Philipp Zabele34db062012-08-29 08:22:00 -03001062 struct coda_q_data *q_data;
Javier Martin186b2502012-07-26 05:53:35 -03001063 unsigned int size;
1064
Philipp Zabele34db062012-08-29 08:22:00 -03001065 q_data = get_q_data(ctx, vq->type);
1066 size = q_data->sizeimage;
Javier Martin186b2502012-07-26 05:53:35 -03001067
1068 *nplanes = 1;
1069 sizes[0] = size;
1070
Philipp Zabelbb04aa62015-01-23 13:51:30 -03001071 /* Set to vb2-dma-contig allocator context, ignored by vb2-vmalloc */
Javier Martin186b2502012-07-26 05:53:35 -03001072 alloc_ctxs[0] = ctx->dev->alloc_ctx;
1073
1074 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1075 "get %d buffer(s) of size %d each.\n", *nbuffers, size);
1076
1077 return 0;
1078}
1079
1080static int coda_buf_prepare(struct vb2_buffer *vb)
1081{
1082 struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
1083 struct coda_q_data *q_data;
1084
1085 q_data = get_q_data(ctx, vb->vb2_queue->type);
1086
1087 if (vb2_plane_size(vb, 0) < q_data->sizeimage) {
1088 v4l2_warn(&ctx->dev->v4l2_dev,
1089 "%s data will not fit into plane (%lu < %lu)\n",
1090 __func__, vb2_plane_size(vb, 0),
1091 (long)q_data->sizeimage);
1092 return -EINVAL;
1093 }
1094
Javier Martin186b2502012-07-26 05:53:35 -03001095 return 0;
1096}
1097
1098static void coda_buf_queue(struct vb2_buffer *vb)
1099{
1100 struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
Philipp Zabelcb06b702015-01-23 13:51:35 -03001101 struct vb2_queue *vq = vb->vb2_queue;
Philipp Zabel918c66f2013-06-27 06:59:01 -03001102 struct coda_q_data *q_data;
1103
1104 q_data = get_q_data(ctx, vb->vb2_queue->type);
1105
1106 /*
1107 * In the decoder case, immediately try to copy the buffer into the
1108 * bitstream ringbuffer and mark it as ready to be dequeued.
1109 */
Philipp Zabelcb06b702015-01-23 13:51:35 -03001110 if (ctx->bitstream.size && vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
Philipp Zabel918c66f2013-06-27 06:59:01 -03001111 /*
Jonathan McCrohan39c1cb22013-10-20 21:34:01 -03001112 * For backwards compatibility, queuing an empty buffer marks
Philipp Zabel918c66f2013-06-27 06:59:01 -03001113 * the stream end
1114 */
Philipp Zabel347bb7f2014-07-23 12:28:42 -03001115 if (vb2_get_plane_payload(vb, 0) == 0)
1116 coda_bit_stream_end_flag(ctx);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001117 mutex_lock(&ctx->bitstream_mutex);
Philipp Zabel14604e32014-07-11 06:36:22 -03001118 v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
Michael Olbricheabed932014-07-18 07:22:40 -03001119 if (vb2_is_streaming(vb->vb2_queue))
Philipp Zabel582d88722015-03-24 14:30:57 -03001120 coda_fill_bitstream(ctx, true);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001121 mutex_unlock(&ctx->bitstream_mutex);
1122 } else {
Philipp Zabel14604e32014-07-11 06:36:22 -03001123 v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001124 }
Javier Martin186b2502012-07-26 05:53:35 -03001125}
1126
Philipp Zabel79924ca2014-07-23 12:28:45 -03001127int coda_alloc_aux_buf(struct coda_dev *dev, struct coda_aux_buf *buf,
1128 size_t size, const char *name, struct dentry *parent)
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001129{
1130 buf->vaddr = dma_alloc_coherent(&dev->plat_dev->dev, size, &buf->paddr,
1131 GFP_KERNEL);
Philipp Zabel68fc31c2014-08-05 14:00:16 -03001132 if (!buf->vaddr) {
1133 v4l2_err(&dev->v4l2_dev,
1134 "Failed to allocate %s buffer of size %u\n",
1135 name, size);
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001136 return -ENOMEM;
Philipp Zabel68fc31c2014-08-05 14:00:16 -03001137 }
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001138
1139 buf->size = size;
1140
Philipp Zabelf61c0b12014-07-11 06:36:40 -03001141 if (name && parent) {
1142 buf->blob.data = buf->vaddr;
1143 buf->blob.size = size;
Philipp Zabelf23797b2014-08-06 08:02:23 -03001144 buf->dentry = debugfs_create_blob(name, 0644, parent,
1145 &buf->blob);
Philipp Zabelf61c0b12014-07-11 06:36:40 -03001146 if (!buf->dentry)
1147 dev_warn(&dev->plat_dev->dev,
1148 "failed to create debugfs entry %s\n", name);
1149 }
1150
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001151 return 0;
1152}
1153
Philipp Zabel79924ca2014-07-23 12:28:45 -03001154void coda_free_aux_buf(struct coda_dev *dev,
1155 struct coda_aux_buf *buf)
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001156{
1157 if (buf->vaddr) {
1158 dma_free_coherent(&dev->plat_dev->dev, buf->size,
1159 buf->vaddr, buf->paddr);
1160 buf->vaddr = NULL;
1161 buf->size = 0;
Peter Seidererd446ec82015-03-24 14:30:48 -03001162 debugfs_remove(buf->dentry);
1163 buf->dentry = NULL;
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001164 }
1165}
1166
Javier Martin186b2502012-07-26 05:53:35 -03001167static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
1168{
1169 struct coda_ctx *ctx = vb2_get_drv_priv(q);
1170 struct v4l2_device *v4l2_dev = &ctx->dev->v4l2_dev;
Javier Martin186b2502012-07-26 05:53:35 -03001171 struct coda_q_data *q_data_src, *q_data_dst;
Philipp Zabelb9063522014-08-05 14:00:10 -03001172 struct vb2_buffer *buf;
Philipp Zabeld35167a2013-05-23 10:42:59 -03001173 int ret = 0;
Javier Martin186b2502012-07-26 05:53:35 -03001174
Philipp Zabelb96904e2013-05-23 10:42:58 -03001175 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001176 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
Philipp Zabel58bc7ed2015-07-09 07:10:14 -03001177 if (ctx->inst_type == CODA_INST_DECODER && ctx->use_bit) {
Philipp Zabel582d88722015-03-24 14:30:57 -03001178 /* copy the buffers that were queued before streamon */
Michael Olbricheabed932014-07-18 07:22:40 -03001179 mutex_lock(&ctx->bitstream_mutex);
Philipp Zabel582d88722015-03-24 14:30:57 -03001180 coda_fill_bitstream(ctx, false);
Michael Olbricheabed932014-07-18 07:22:40 -03001181 mutex_unlock(&ctx->bitstream_mutex);
1182
Philipp Zabelb9063522014-08-05 14:00:10 -03001183 if (coda_get_bitstream_payload(ctx) < 512) {
1184 ret = -EINVAL;
1185 goto err;
1186 }
Philipp Zabel918c66f2013-06-27 06:59:01 -03001187 } else {
Philipp Zabelb9063522014-08-05 14:00:10 -03001188 if (count < 1) {
1189 ret = -EINVAL;
1190 goto err;
1191 }
Philipp Zabel918c66f2013-06-27 06:59:01 -03001192 }
1193
1194 ctx->streamon_out = 1;
Philipp Zabel918c66f2013-06-27 06:59:01 -03001195 } else {
Philipp Zabelb9063522014-08-05 14:00:10 -03001196 if (count < 1) {
1197 ret = -EINVAL;
1198 goto err;
1199 }
Philipp Zabel918c66f2013-06-27 06:59:01 -03001200
1201 ctx->streamon_cap = 1;
Philipp Zabelb96904e2013-05-23 10:42:58 -03001202 }
Javier Martin186b2502012-07-26 05:53:35 -03001203
Philipp Zabelb96904e2013-05-23 10:42:58 -03001204 /* Don't start the coda unless both queues are on */
1205 if (!(ctx->streamon_out & ctx->streamon_cap))
1206 return 0;
Javier Martin186b2502012-07-26 05:53:35 -03001207
Philipp Zabel23b6ee52015-03-24 14:30:55 -03001208 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
1209 if ((q_data_src->width != q_data_dst->width &&
1210 round_up(q_data_src->width, 16) != q_data_dst->width) ||
1211 (q_data_src->height != q_data_dst->height &&
1212 round_up(q_data_src->height, 16) != q_data_dst->height)) {
1213 v4l2_err(v4l2_dev, "can't convert %dx%d to %dx%d\n",
1214 q_data_src->width, q_data_src->height,
1215 q_data_dst->width, q_data_dst->height);
1216 ret = -EINVAL;
1217 goto err;
1218 }
1219
Philipp Zabelcb1d3a32014-10-02 14:08:31 -03001220 /* Allow BIT decoder device_run with no new buffers queued */
Philipp Zabela22496c2015-01-23 13:51:33 -03001221 if (ctx->inst_type == CODA_INST_DECODER && ctx->use_bit)
Philipp Zabel14604e32014-07-11 06:36:22 -03001222 v4l2_m2m_set_src_buffered(ctx->fh.m2m_ctx, true);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001223
Philipp Zabelb96904e2013-05-23 10:42:58 -03001224 ctx->gopcounter = ctx->params.gop_size - 1;
Javier Martin186b2502012-07-26 05:53:35 -03001225
Philipp Zabelb96904e2013-05-23 10:42:58 -03001226 ctx->codec = coda_find_codec(ctx->dev, q_data_src->fourcc,
1227 q_data_dst->fourcc);
1228 if (!ctx->codec) {
Javier Martin186b2502012-07-26 05:53:35 -03001229 v4l2_err(v4l2_dev, "couldn't tell instance type.\n");
Philipp Zabelb9063522014-08-05 14:00:10 -03001230 ret = -EINVAL;
1231 goto err;
Javier Martin186b2502012-07-26 05:53:35 -03001232 }
1233
Philipp Zabelcb1d3a32014-10-02 14:08:31 -03001234 if (q_data_dst->fourcc == V4L2_PIX_FMT_JPEG)
1235 ctx->params.gop_size = 1;
1236 ctx->gopcounter = ctx->params.gop_size - 1;
1237
Philipp Zabela1192a12014-07-23 12:28:40 -03001238 ret = ctx->ops->start_streaming(ctx);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001239 if (ctx->inst_type == CODA_INST_DECODER) {
Philipp Zabel89548442014-07-11 06:36:17 -03001240 if (ret == -EAGAIN)
Philipp Zabel918c66f2013-06-27 06:59:01 -03001241 return 0;
Philipp Zabel89548442014-07-11 06:36:17 -03001242 else if (ret < 0)
Philipp Zabelb9063522014-08-05 14:00:10 -03001243 goto err;
Philipp Zabel918c66f2013-06-27 06:59:01 -03001244 }
1245
Philipp Zabel89548442014-07-11 06:36:17 -03001246 return ret;
Philipp Zabelb9063522014-08-05 14:00:10 -03001247
1248err:
1249 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1250 while ((buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx)))
Philipp Zabelb8b1b58c52014-10-21 13:25:52 -03001251 v4l2_m2m_buf_done(buf, VB2_BUF_STATE_QUEUED);
Philipp Zabelb9063522014-08-05 14:00:10 -03001252 } else {
1253 while ((buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx)))
Philipp Zabelb8b1b58c52014-10-21 13:25:52 -03001254 v4l2_m2m_buf_done(buf, VB2_BUF_STATE_QUEUED);
Philipp Zabelb9063522014-08-05 14:00:10 -03001255 }
1256 return ret;
Philipp Zabel89548442014-07-11 06:36:17 -03001257}
1258
Hans Verkuile37559b2014-04-17 02:47:21 -03001259static void coda_stop_streaming(struct vb2_queue *q)
Javier Martin186b2502012-07-26 05:53:35 -03001260{
1261 struct coda_ctx *ctx = vb2_get_drv_priv(q);
Philipp Zabel2fb57f02012-07-25 09:22:07 -03001262 struct coda_dev *dev = ctx->dev;
Philipp Zabel4a31b522014-08-05 14:00:11 -03001263 struct vb2_buffer *buf;
Philipp Zabel47f3fa62015-07-09 07:10:21 -03001264 unsigned long flags;
Philipp Zabel5c76c2c2015-03-24 14:30:56 -03001265 bool stop;
1266
1267 stop = ctx->streamon_out && ctx->streamon_cap;
Javier Martin186b2502012-07-26 05:53:35 -03001268
1269 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
Philipp Zabel918c66f2013-06-27 06:59:01 -03001270 v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
Javier Martin186b2502012-07-26 05:53:35 -03001271 "%s: output\n", __func__);
Philipp Zabelb96904e2013-05-23 10:42:58 -03001272 ctx->streamon_out = 0;
Philipp Zabel918c66f2013-06-27 06:59:01 -03001273
Philipp Zabel347bb7f2014-07-23 12:28:42 -03001274 coda_bit_stream_end_flag(ctx);
Philipp Zabel4a31b522014-08-05 14:00:11 -03001275
Philipp Zabel6dd5ef52015-01-23 13:51:26 -03001276 ctx->qsequence = 0;
Philipp Zabel4a31b522014-08-05 14:00:11 -03001277
1278 while ((buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx)))
1279 v4l2_m2m_buf_done(buf, VB2_BUF_STATE_ERROR);
Javier Martin186b2502012-07-26 05:53:35 -03001280 } else {
Philipp Zabel918c66f2013-06-27 06:59:01 -03001281 v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
Javier Martin186b2502012-07-26 05:53:35 -03001282 "%s: capture\n", __func__);
Philipp Zabelb96904e2013-05-23 10:42:58 -03001283 ctx->streamon_cap = 0;
Philipp Zabel918c66f2013-06-27 06:59:01 -03001284
1285 ctx->osequence = 0;
Philipp Zabelcb2c0282014-07-11 06:36:33 -03001286 ctx->sequence_offset = 0;
Philipp Zabel4a31b522014-08-05 14:00:11 -03001287
1288 while ((buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx)))
1289 v4l2_m2m_buf_done(buf, VB2_BUF_STATE_ERROR);
Javier Martin186b2502012-07-26 05:53:35 -03001290 }
1291
Philipp Zabel5c76c2c2015-03-24 14:30:56 -03001292 if (stop) {
Philipp Zabel7cbb1052014-10-02 14:08:32 -03001293 struct coda_buffer_meta *meta;
Philipp Zabel846ced92014-07-11 06:36:31 -03001294
Philipp Zabelf4706d62015-01-23 13:51:27 -03001295 if (ctx->ops->seq_end_work) {
1296 queue_work(dev->workqueue, &ctx->seq_end_work);
1297 flush_work(&ctx->seq_end_work);
1298 }
Philipp Zabel47f3fa62015-07-09 07:10:21 -03001299 spin_lock_irqsave(&ctx->buffer_meta_lock, flags);
Philipp Zabel7cbb1052014-10-02 14:08:32 -03001300 while (!list_empty(&ctx->buffer_meta_list)) {
1301 meta = list_first_entry(&ctx->buffer_meta_list,
1302 struct coda_buffer_meta, list);
1303 list_del(&meta->list);
1304 kfree(meta);
Philipp Zabel846ced92014-07-11 06:36:31 -03001305 }
Philipp Zabel47f3fa62015-07-09 07:10:21 -03001306 ctx->num_metas = 0;
1307 spin_unlock_irqrestore(&ctx->buffer_meta_lock, flags);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001308 kfifo_init(&ctx->bitstream_fifo,
1309 ctx->bitstream.vaddr, ctx->bitstream.size);
1310 ctx->runcounter = 0;
Philipp Zabelf157cf42014-09-29 09:53:42 -03001311 ctx->aborting = 0;
Philipp Zabel62bed142012-07-25 10:40:39 -03001312 }
Philipp Zabelc1ae0b22015-07-09 07:10:17 -03001313
1314 if (!ctx->streamon_out && !ctx->streamon_cap)
1315 ctx->bit_stream_param &= ~CODA_BIT_STREAM_END_FLAG;
Javier Martin186b2502012-07-26 05:53:35 -03001316}
1317
Philipp Zabel121cacf2014-07-18 07:22:42 -03001318static const struct vb2_ops coda_qops = {
Javier Martin186b2502012-07-26 05:53:35 -03001319 .queue_setup = coda_queue_setup,
1320 .buf_prepare = coda_buf_prepare,
1321 .buf_queue = coda_buf_queue,
Javier Martin186b2502012-07-26 05:53:35 -03001322 .start_streaming = coda_start_streaming,
1323 .stop_streaming = coda_stop_streaming,
Philipp Zabel152ea1c2014-07-11 06:36:21 -03001324 .wait_prepare = vb2_ops_wait_prepare,
1325 .wait_finish = vb2_ops_wait_finish,
Javier Martin186b2502012-07-26 05:53:35 -03001326};
1327
1328static int coda_s_ctrl(struct v4l2_ctrl *ctrl)
1329{
1330 struct coda_ctx *ctx =
1331 container_of(ctrl->handler, struct coda_ctx, ctrls);
1332
1333 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1334 "s_ctrl: id = %d, val = %d\n", ctrl->id, ctrl->val);
1335
1336 switch (ctrl->id) {
Philipp Zabel8f35c7b2012-07-09 04:25:52 -03001337 case V4L2_CID_HFLIP:
1338 if (ctrl->val)
1339 ctx->params.rot_mode |= CODA_MIR_HOR;
1340 else
1341 ctx->params.rot_mode &= ~CODA_MIR_HOR;
1342 break;
1343 case V4L2_CID_VFLIP:
1344 if (ctrl->val)
1345 ctx->params.rot_mode |= CODA_MIR_VER;
1346 else
1347 ctx->params.rot_mode &= ~CODA_MIR_VER;
1348 break;
Javier Martin186b2502012-07-26 05:53:35 -03001349 case V4L2_CID_MPEG_VIDEO_BITRATE:
1350 ctx->params.bitrate = ctrl->val / 1000;
1351 break;
1352 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
1353 ctx->params.gop_size = ctrl->val;
1354 break;
1355 case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP:
1356 ctx->params.h264_intra_qp = ctrl->val;
1357 break;
1358 case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP:
1359 ctx->params.h264_inter_qp = ctrl->val;
1360 break;
Philipp Zabel1a5567e2014-07-11 06:36:26 -03001361 case V4L2_CID_MPEG_VIDEO_H264_MIN_QP:
1362 ctx->params.h264_min_qp = ctrl->val;
1363 break;
1364 case V4L2_CID_MPEG_VIDEO_H264_MAX_QP:
1365 ctx->params.h264_max_qp = ctrl->val;
1366 break;
Philipp Zabelde23b1d2014-07-11 06:36:27 -03001367 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA:
1368 ctx->params.h264_deblk_alpha = ctrl->val;
1369 break;
1370 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA:
1371 ctx->params.h264_deblk_beta = ctrl->val;
1372 break;
1373 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE:
1374 ctx->params.h264_deblk_enabled = (ctrl->val ==
1375 V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED);
1376 break;
Javier Martin186b2502012-07-26 05:53:35 -03001377 case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP:
1378 ctx->params.mpeg4_intra_qp = ctrl->val;
1379 break;
1380 case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP:
1381 ctx->params.mpeg4_inter_qp = ctrl->val;
1382 break;
1383 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:
1384 ctx->params.slice_mode = ctrl->val;
1385 break;
1386 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB:
1387 ctx->params.slice_max_mb = ctrl->val;
1388 break;
Philipp Zabelc566c782012-08-08 11:59:38 -03001389 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES:
1390 ctx->params.slice_max_bits = ctrl->val * 8;
1391 break;
Javier Martin186b2502012-07-26 05:53:35 -03001392 case V4L2_CID_MPEG_VIDEO_HEADER_MODE:
1393 break;
Philipp Zabelf38f79d2014-07-11 06:36:28 -03001394 case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB:
1395 ctx->params.intra_refresh = ctrl->val;
1396 break;
Philipp Zabelcb1d3a32014-10-02 14:08:31 -03001397 case V4L2_CID_JPEG_COMPRESSION_QUALITY:
1398 coda_set_jpeg_compression_quality(ctx, ctrl->val);
1399 break;
1400 case V4L2_CID_JPEG_RESTART_INTERVAL:
1401 ctx->params.jpeg_restart_interval = ctrl->val;
1402 break;
Philipp Zabelda2b3b32015-07-10 10:37:52 -03001403 case V4L2_CID_MPEG_VIDEO_VBV_DELAY:
1404 ctx->params.vbv_delay = ctrl->val;
1405 break;
1406 case V4L2_CID_MPEG_VIDEO_VBV_SIZE:
1407 ctx->params.vbv_size = min(ctrl->val * 8192, 0x7fffffff);
1408 break;
Javier Martin186b2502012-07-26 05:53:35 -03001409 default:
1410 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1411 "Invalid control, id=%d, val=%d\n",
1412 ctrl->id, ctrl->val);
1413 return -EINVAL;
1414 }
1415
1416 return 0;
1417}
1418
Philipp Zabel814c3762014-07-18 07:22:45 -03001419static const struct v4l2_ctrl_ops coda_ctrl_ops = {
Javier Martin186b2502012-07-26 05:53:35 -03001420 .s_ctrl = coda_s_ctrl,
1421};
1422
Philipp Zabelbfc732f2014-10-02 14:08:29 -03001423static void coda_encode_ctrls(struct coda_ctx *ctx)
Javier Martin186b2502012-07-26 05:53:35 -03001424{
Philipp Zabel8f35c7b2012-07-09 04:25:52 -03001425 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
Philipp Zabel92b042e2015-03-18 08:15:36 -03001426 V4L2_CID_MPEG_VIDEO_BITRATE, 0, 32767000, 1000, 0);
Javier Martin186b2502012-07-26 05:53:35 -03001427 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1428 V4L2_CID_MPEG_VIDEO_GOP_SIZE, 1, 60, 1, 16);
1429 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
Philipp Zabel594a7502014-07-11 06:36:14 -03001430 V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP, 0, 51, 1, 25);
Javier Martin186b2502012-07-26 05:53:35 -03001431 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
Philipp Zabel594a7502014-07-11 06:36:14 -03001432 V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP, 0, 51, 1, 25);
Philipp Zabel1a5567e2014-07-11 06:36:26 -03001433 if (ctx->dev->devtype->product != CODA_960) {
1434 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1435 V4L2_CID_MPEG_VIDEO_H264_MIN_QP, 0, 51, 1, 12);
1436 }
1437 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1438 V4L2_CID_MPEG_VIDEO_H264_MAX_QP, 0, 51, 1, 51);
Javier Martin186b2502012-07-26 05:53:35 -03001439 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
Philipp Zabelde23b1d2014-07-11 06:36:27 -03001440 V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA, 0, 15, 1, 0);
1441 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1442 V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA, 0, 15, 1, 0);
1443 v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops,
1444 V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE,
1445 V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED, 0x0,
1446 V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED);
1447 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
Javier Martin186b2502012-07-26 05:53:35 -03001448 V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP, 1, 31, 1, 2);
1449 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1450 V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP, 1, 31, 1, 2);
1451 v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops,
1452 V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE,
Philipp Zabelc566c782012-08-08 11:59:38 -03001453 V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES, 0x0,
1454 V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE);
Javier Martin186b2502012-07-26 05:53:35 -03001455 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1456 V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB, 1, 0x3fffffff, 1, 1);
Philipp Zabelc566c782012-08-08 11:59:38 -03001457 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
Philipp Zabelf23797b2014-08-06 08:02:23 -03001458 V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES, 1, 0x3fffffff, 1,
1459 500);
Javier Martin186b2502012-07-26 05:53:35 -03001460 v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops,
1461 V4L2_CID_MPEG_VIDEO_HEADER_MODE,
1462 V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME,
1463 (1 << V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE),
1464 V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME);
Philipp Zabelf38f79d2014-07-11 06:36:28 -03001465 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
Philipp Zabelf23797b2014-08-06 08:02:23 -03001466 V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB, 0,
1467 1920 * 1088 / 256, 1, 0);
Philipp Zabelda2b3b32015-07-10 10:37:52 -03001468 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1469 V4L2_CID_MPEG_VIDEO_VBV_DELAY, 0, 0x7fff, 1, 0);
1470 /*
1471 * The maximum VBV size value is 0x7fffffff bits,
1472 * one bit less than 262144 KiB
1473 */
1474 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1475 V4L2_CID_MPEG_VIDEO_VBV_SIZE, 0, 262144, 1, 0);
Philipp Zabelbfc732f2014-10-02 14:08:29 -03001476}
1477
Philipp Zabelcb1d3a32014-10-02 14:08:31 -03001478static void coda_jpeg_encode_ctrls(struct coda_ctx *ctx)
1479{
1480 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1481 V4L2_CID_JPEG_COMPRESSION_QUALITY, 5, 100, 1, 50);
1482 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1483 V4L2_CID_JPEG_RESTART_INTERVAL, 0, 100, 1, 0);
1484}
1485
Philipp Zabelbfc732f2014-10-02 14:08:29 -03001486static int coda_ctrls_setup(struct coda_ctx *ctx)
1487{
1488 v4l2_ctrl_handler_init(&ctx->ctrls, 2);
1489
1490 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1491 V4L2_CID_HFLIP, 0, 1, 1, 0);
1492 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1493 V4L2_CID_VFLIP, 0, 1, 1, 0);
Philipp Zabelcb1d3a32014-10-02 14:08:31 -03001494 if (ctx->inst_type == CODA_INST_ENCODER) {
1495 if (ctx->cvd->dst_formats[0] == V4L2_PIX_FMT_JPEG)
1496 coda_jpeg_encode_ctrls(ctx);
1497 else
1498 coda_encode_ctrls(ctx);
1499 }
Javier Martin186b2502012-07-26 05:53:35 -03001500
1501 if (ctx->ctrls.error) {
Philipp Zabelf23797b2014-08-06 08:02:23 -03001502 v4l2_err(&ctx->dev->v4l2_dev,
1503 "control initialization error (%d)",
Javier Martin186b2502012-07-26 05:53:35 -03001504 ctx->ctrls.error);
1505 return -EINVAL;
1506 }
1507
1508 return v4l2_ctrl_handler_setup(&ctx->ctrls);
1509}
1510
Philipp Zabel121cacf2014-07-18 07:22:42 -03001511static int coda_queue_init(struct coda_ctx *ctx, struct vb2_queue *vq)
Javier Martin186b2502012-07-26 05:53:35 -03001512{
Philipp Zabel121cacf2014-07-18 07:22:42 -03001513 vq->drv_priv = ctx;
1514 vq->ops = &coda_qops;
1515 vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
1516 vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
1517 vq->lock = &ctx->dev->dev_mutex;
Kamil Debskie4af23d2015-02-23 09:26:18 -03001518 /* One way to indicate end-of-stream for coda is to set the
1519 * bytesused == 0. However by default videobuf2 handles bytesused
1520 * equal to 0 as a special case and changes its value to the size
1521 * of the buffer. Set the allow_zero_bytesused flag, so
1522 * that videobuf2 will keep the value of bytesused intact.
1523 */
1524 vq->allow_zero_bytesused = 1;
Philipp Zabel121cacf2014-07-18 07:22:42 -03001525
1526 return vb2_queue_init(vq);
1527}
1528
Philipp Zabel79924ca2014-07-23 12:28:45 -03001529int coda_encoder_queue_init(void *priv, struct vb2_queue *src_vq,
1530 struct vb2_queue *dst_vq)
Philipp Zabel121cacf2014-07-18 07:22:42 -03001531{
Javier Martin186b2502012-07-26 05:53:35 -03001532 int ret;
1533
Javier Martin186b2502012-07-26 05:53:35 -03001534 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
Philipp Zabeld29a8cf2014-07-18 07:22:38 -03001535 src_vq->io_modes = VB2_DMABUF | VB2_MMAP;
Javier Martin186b2502012-07-26 05:53:35 -03001536 src_vq->mem_ops = &vb2_dma_contig_memops;
1537
Philipp Zabel121cacf2014-07-18 07:22:42 -03001538 ret = coda_queue_init(priv, src_vq);
Javier Martin186b2502012-07-26 05:53:35 -03001539 if (ret)
1540 return ret;
1541
Javier Martin186b2502012-07-26 05:53:35 -03001542 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
Philipp Zabeld29a8cf2014-07-18 07:22:38 -03001543 dst_vq->io_modes = VB2_DMABUF | VB2_MMAP;
Javier Martin186b2502012-07-26 05:53:35 -03001544 dst_vq->mem_ops = &vb2_dma_contig_memops;
1545
Philipp Zabel121cacf2014-07-18 07:22:42 -03001546 return coda_queue_init(priv, dst_vq);
1547}
1548
Philipp Zabel79924ca2014-07-23 12:28:45 -03001549int coda_decoder_queue_init(void *priv, struct vb2_queue *src_vq,
1550 struct vb2_queue *dst_vq)
Philipp Zabel121cacf2014-07-18 07:22:42 -03001551{
1552 int ret;
1553
1554 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
Philipp Zabelbb04aa62015-01-23 13:51:30 -03001555 src_vq->io_modes = VB2_DMABUF | VB2_MMAP | VB2_USERPTR;
1556 src_vq->mem_ops = &vb2_vmalloc_memops;
Philipp Zabel121cacf2014-07-18 07:22:42 -03001557
1558 ret = coda_queue_init(priv, src_vq);
1559 if (ret)
1560 return ret;
1561
1562 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1563 dst_vq->io_modes = VB2_DMABUF | VB2_MMAP;
1564 dst_vq->mem_ops = &vb2_dma_contig_memops;
1565
1566 return coda_queue_init(priv, dst_vq);
Javier Martin186b2502012-07-26 05:53:35 -03001567}
1568
Philipp Zabele11f3e62012-07-25 09:16:58 -03001569static int coda_next_free_instance(struct coda_dev *dev)
1570{
Philipp Zabel0cddc7e2013-09-30 10:34:44 -03001571 int idx = ffz(dev->instance_mask);
1572
1573 if ((idx < 0) ||
1574 (dev->devtype->product == CODA_DX6 && idx > CODADX6_MAX_INSTANCES))
1575 return -EBUSY;
1576
1577 return idx;
Philipp Zabele11f3e62012-07-25 09:16:58 -03001578}
1579
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001580/*
1581 * File operations
1582 */
1583
1584static int coda_open(struct file *file)
Javier Martin186b2502012-07-26 05:53:35 -03001585{
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001586 struct video_device *vdev = video_devdata(file);
1587 struct coda_dev *dev = video_get_drvdata(vdev);
Javier Martin186b2502012-07-26 05:53:35 -03001588 struct coda_ctx *ctx = NULL;
Philipp Zabelf61c0b12014-07-11 06:36:40 -03001589 char *name;
Philipp Zabel918c66f2013-06-27 06:59:01 -03001590 int ret;
Philipp Zabele11f3e62012-07-25 09:16:58 -03001591 int idx;
Javier Martin186b2502012-07-26 05:53:35 -03001592
Philipp Zabelf23797b2014-08-06 08:02:23 -03001593 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
Javier Martin186b2502012-07-26 05:53:35 -03001594 if (!ctx)
1595 return -ENOMEM;
1596
Fabio Estevamf82bc202013-08-21 11:14:16 -03001597 idx = coda_next_free_instance(dev);
Philipp Zabel0cddc7e2013-09-30 10:34:44 -03001598 if (idx < 0) {
1599 ret = idx;
Fabio Estevamf82bc202013-08-21 11:14:16 -03001600 goto err_coda_max;
1601 }
1602 set_bit(idx, &dev->instance_mask);
1603
Philipp Zabelf61c0b12014-07-11 06:36:40 -03001604 name = kasprintf(GFP_KERNEL, "context%d", idx);
Peter Seiderera7f933a2015-03-24 14:30:47 -03001605 if (!name) {
1606 ret = -ENOMEM;
1607 goto err_coda_name_init;
1608 }
1609
Philipp Zabelf61c0b12014-07-11 06:36:40 -03001610 ctx->debugfs_entry = debugfs_create_dir(name, dev->debugfs_root);
1611 kfree(name);
1612
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001613 ctx->cvd = to_coda_video_device(vdev);
1614 ctx->inst_type = ctx->cvd->type;
1615 ctx->ops = ctx->cvd->ops;
Philipp Zabela22496c2015-01-23 13:51:33 -03001616 ctx->use_bit = !ctx->cvd->direct;
Philipp Zabel32b6f202014-07-11 06:36:20 -03001617 init_completion(&ctx->completion);
1618 INIT_WORK(&ctx->pic_run_work, coda_pic_run_work);
Philipp Zabel747d7642015-01-23 13:51:31 -03001619 if (ctx->ops->seq_end_work)
1620 INIT_WORK(&ctx->seq_end_work, ctx->ops->seq_end_work);
Javier Martin186b2502012-07-26 05:53:35 -03001621 v4l2_fh_init(&ctx->fh, video_devdata(file));
1622 file->private_data = &ctx->fh;
1623 v4l2_fh_add(&ctx->fh);
1624 ctx->dev = dev;
Philipp Zabele11f3e62012-07-25 09:16:58 -03001625 ctx->idx = idx;
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001626 switch (dev->devtype->product) {
Philipp Zabel89548442014-07-11 06:36:17 -03001627 case CODA_960:
Philipp Zabel2bf299c2014-09-29 09:53:46 -03001628 ctx->frame_mem_ctrl = 1 << 12;
1629 /* fallthrough */
1630 case CODA_7541:
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001631 ctx->reg_idx = 0;
1632 break;
1633 default:
1634 ctx->reg_idx = idx;
1635 }
Fabio Estevamf82bc202013-08-21 11:14:16 -03001636
Philipp Zabel1e172732014-07-11 06:36:23 -03001637 /* Power up and upload firmware if necessary */
1638 ret = pm_runtime_get_sync(&dev->plat_dev->dev);
1639 if (ret < 0) {
1640 v4l2_err(&dev->v4l2_dev, "failed to power up: %d\n", ret);
1641 goto err_pm_get;
1642 }
1643
Fabio Estevam79830db2013-08-21 11:14:17 -03001644 ret = clk_prepare_enable(dev->clk_per);
1645 if (ret)
1646 goto err_clk_per;
1647
1648 ret = clk_prepare_enable(dev->clk_ahb);
1649 if (ret)
1650 goto err_clk_ahb;
1651
Javier Martin186b2502012-07-26 05:53:35 -03001652 set_default_params(ctx);
Philipp Zabela1192a12014-07-23 12:28:40 -03001653 ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx,
1654 ctx->ops->queue_init);
Philipp Zabel14604e32014-07-11 06:36:22 -03001655 if (IS_ERR(ctx->fh.m2m_ctx)) {
1656 ret = PTR_ERR(ctx->fh.m2m_ctx);
Javier Martin186b2502012-07-26 05:53:35 -03001657
1658 v4l2_err(&dev->v4l2_dev, "%s return error (%d)\n",
1659 __func__, ret);
Fabio Estevamf82bc202013-08-21 11:14:16 -03001660 goto err_ctx_init;
Javier Martin186b2502012-07-26 05:53:35 -03001661 }
Philipp Zabel152ea1c2014-07-11 06:36:21 -03001662
Javier Martin186b2502012-07-26 05:53:35 -03001663 ret = coda_ctrls_setup(ctx);
1664 if (ret) {
1665 v4l2_err(&dev->v4l2_dev, "failed to setup coda controls\n");
Fabio Estevamf82bc202013-08-21 11:14:16 -03001666 goto err_ctrls_setup;
Javier Martin186b2502012-07-26 05:53:35 -03001667 }
1668
1669 ctx->fh.ctrl_handler = &ctx->ctrls;
1670
Philipp Zabel9082a7c2013-06-21 03:55:31 -03001671 mutex_init(&ctx->bitstream_mutex);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001672 mutex_init(&ctx->buffer_mutex);
Philipp Zabel7cbb1052014-10-02 14:08:32 -03001673 INIT_LIST_HEAD(&ctx->buffer_meta_list);
Philipp Zabel47f3fa62015-07-09 07:10:21 -03001674 spin_lock_init(&ctx->buffer_meta_lock);
Philipp Zabel9082a7c2013-06-21 03:55:31 -03001675
Javier Martin186b2502012-07-26 05:53:35 -03001676 coda_lock(ctx);
Philipp Zabele11f3e62012-07-25 09:16:58 -03001677 list_add(&ctx->list, &dev->instances);
Javier Martin186b2502012-07-26 05:53:35 -03001678 coda_unlock(ctx);
1679
Javier Martin186b2502012-07-26 05:53:35 -03001680 v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Created instance %d (%p)\n",
1681 ctx->idx, ctx);
1682
1683 return 0;
1684
Fabio Estevamf82bc202013-08-21 11:14:16 -03001685err_ctrls_setup:
Philipp Zabel14604e32014-07-11 06:36:22 -03001686 v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
Fabio Estevamf82bc202013-08-21 11:14:16 -03001687err_ctx_init:
1688 clk_disable_unprepare(dev->clk_ahb);
Fabio Estevam79830db2013-08-21 11:14:17 -03001689err_clk_ahb:
Fabio Estevamf82bc202013-08-21 11:14:16 -03001690 clk_disable_unprepare(dev->clk_per);
Fabio Estevam79830db2013-08-21 11:14:17 -03001691err_clk_per:
Philipp Zabel1e172732014-07-11 06:36:23 -03001692 pm_runtime_put_sync(&dev->plat_dev->dev);
1693err_pm_get:
Javier Martin186b2502012-07-26 05:53:35 -03001694 v4l2_fh_del(&ctx->fh);
1695 v4l2_fh_exit(&ctx->fh);
Fabio Estevamf82bc202013-08-21 11:14:16 -03001696 clear_bit(ctx->idx, &dev->instance_mask);
Peter Seiderera7f933a2015-03-24 14:30:47 -03001697err_coda_name_init:
Fabio Estevamf82bc202013-08-21 11:14:16 -03001698err_coda_max:
Javier Martin186b2502012-07-26 05:53:35 -03001699 kfree(ctx);
1700 return ret;
1701}
1702
1703static int coda_release(struct file *file)
1704{
1705 struct coda_dev *dev = video_drvdata(file);
1706 struct coda_ctx *ctx = fh_to_ctx(file->private_data);
1707
1708 v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Releasing instance %p\n",
1709 ctx);
1710
Philipp Zabela22496c2015-01-23 13:51:33 -03001711 if (ctx->inst_type == CODA_INST_DECODER && ctx->use_bit)
Philipp Zabeld4bb75f2014-10-08 13:09:11 -03001712 coda_bit_stream_end_flag(ctx);
1713
Philipp Zabel918c66f2013-06-27 06:59:01 -03001714 /* If this instance is running, call .job_abort and wait for it to end */
Philipp Zabel14604e32014-07-11 06:36:22 -03001715 v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001716
1717 /* In case the instance was not running, we still need to call SEQ_END */
Philipp Zabel5c718bb2015-07-09 07:10:16 -03001718 if (ctx->ops->seq_end_work) {
Philipp Zabel32b6f202014-07-11 06:36:20 -03001719 queue_work(dev->workqueue, &ctx->seq_end_work);
1720 flush_work(&ctx->seq_end_work);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001721 }
Philipp Zabel918c66f2013-06-27 06:59:01 -03001722
Javier Martin186b2502012-07-26 05:53:35 -03001723 coda_lock(ctx);
Philipp Zabele11f3e62012-07-25 09:16:58 -03001724 list_del(&ctx->list);
Javier Martin186b2502012-07-26 05:53:35 -03001725 coda_unlock(ctx);
1726
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001727 if (ctx->dev->devtype->product == CODA_DX6)
1728 coda_free_aux_buf(dev, &ctx->workbuf);
1729
Javier Martin186b2502012-07-26 05:53:35 -03001730 v4l2_ctrl_handler_free(&ctx->ctrls);
Javier Martin186b2502012-07-26 05:53:35 -03001731 clk_disable_unprepare(dev->clk_ahb);
Fabio Estevamf82bc202013-08-21 11:14:16 -03001732 clk_disable_unprepare(dev->clk_per);
Philipp Zabel1e172732014-07-11 06:36:23 -03001733 pm_runtime_put_sync(&dev->plat_dev->dev);
Javier Martin186b2502012-07-26 05:53:35 -03001734 v4l2_fh_del(&ctx->fh);
1735 v4l2_fh_exit(&ctx->fh);
Philipp Zabele11f3e62012-07-25 09:16:58 -03001736 clear_bit(ctx->idx, &dev->instance_mask);
Philipp Zabel58b76772014-07-23 12:28:43 -03001737 if (ctx->ops->release)
1738 ctx->ops->release(ctx);
Philipp Zabele1519e82015-01-23 13:51:17 -03001739 debugfs_remove_recursive(ctx->debugfs_entry);
Javier Martin186b2502012-07-26 05:53:35 -03001740 kfree(ctx);
1741
1742 return 0;
1743}
1744
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001745static const struct v4l2_file_operations coda_fops = {
Javier Martin186b2502012-07-26 05:53:35 -03001746 .owner = THIS_MODULE,
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001747 .open = coda_open,
Javier Martin186b2502012-07-26 05:53:35 -03001748 .release = coda_release,
Philipp Zabel152ea1c2014-07-11 06:36:21 -03001749 .poll = v4l2_m2m_fop_poll,
Javier Martin186b2502012-07-26 05:53:35 -03001750 .unlocked_ioctl = video_ioctl2,
Philipp Zabel152ea1c2014-07-11 06:36:21 -03001751 .mmap = v4l2_m2m_fop_mmap,
Javier Martin186b2502012-07-26 05:53:35 -03001752};
1753
Philipp Zabel87048bb2012-07-02 07:03:43 -03001754static int coda_hw_init(struct coda_dev *dev)
Javier Martin186b2502012-07-26 05:53:35 -03001755{
Javier Martin186b2502012-07-26 05:53:35 -03001756 u32 data;
1757 u16 *p;
Fabio Estevam79830db2013-08-21 11:14:17 -03001758 int i, ret;
Javier Martin186b2502012-07-26 05:53:35 -03001759
Fabio Estevam79830db2013-08-21 11:14:17 -03001760 ret = clk_prepare_enable(dev->clk_per);
1761 if (ret)
Philipp Zabel1e172732014-07-11 06:36:23 -03001762 goto err_clk_per;
Fabio Estevam79830db2013-08-21 11:14:17 -03001763
1764 ret = clk_prepare_enable(dev->clk_ahb);
1765 if (ret)
1766 goto err_clk_ahb;
Javier Martin186b2502012-07-26 05:53:35 -03001767
Philipp Zabel8f452842014-07-11 06:36:35 -03001768 if (dev->rstc)
1769 reset_control_reset(dev->rstc);
1770
Javier Martin186b2502012-07-26 05:53:35 -03001771 /*
1772 * Copy the first CODA_ISRAM_SIZE in the internal SRAM.
Philipp Zabel87048bb2012-07-02 07:03:43 -03001773 * The 16-bit chars in the code buffer are in memory access
1774 * order, re-sort them to CODA order for register download.
Javier Martin186b2502012-07-26 05:53:35 -03001775 * Data in this SRAM survives a reboot.
1776 */
Philipp Zabel87048bb2012-07-02 07:03:43 -03001777 p = (u16 *)dev->codebuf.vaddr;
1778 if (dev->devtype->product == CODA_DX6) {
1779 for (i = 0; i < (CODA_ISRAM_SIZE / 2); i++) {
1780 data = CODA_DOWN_ADDRESS_SET(i) |
1781 CODA_DOWN_DATA_SET(p[i ^ 1]);
1782 coda_write(dev, data, CODA_REG_BIT_CODE_DOWN);
1783 }
1784 } else {
1785 for (i = 0; i < (CODA_ISRAM_SIZE / 2); i++) {
1786 data = CODA_DOWN_ADDRESS_SET(i) |
1787 CODA_DOWN_DATA_SET(p[round_down(i, 4) +
1788 3 - (i % 4)]);
1789 coda_write(dev, data, CODA_REG_BIT_CODE_DOWN);
1790 }
Javier Martin186b2502012-07-26 05:53:35 -03001791 }
Javier Martin186b2502012-07-26 05:53:35 -03001792
Philipp Zabel9acf7692013-05-23 10:42:56 -03001793 /* Clear registers */
1794 for (i = 0; i < 64; i++)
1795 coda_write(dev, 0, CODA_REG_BIT_CODE_BUF_ADDR + i * 4);
1796
Javier Martin186b2502012-07-26 05:53:35 -03001797 /* Tell the BIT where to find everything it needs */
Philipp Zabel89548442014-07-11 06:36:17 -03001798 if (dev->devtype->product == CODA_960 ||
1799 dev->devtype->product == CODA_7541) {
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001800 coda_write(dev, dev->tempbuf.paddr,
1801 CODA_REG_BIT_TEMP_BUF_ADDR);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001802 coda_write(dev, 0, CODA_REG_BIT_BIT_STREAM_PARAM);
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001803 } else {
1804 coda_write(dev, dev->workbuf.paddr,
1805 CODA_REG_BIT_WORK_BUF_ADDR);
1806 }
Javier Martin186b2502012-07-26 05:53:35 -03001807 coda_write(dev, dev->codebuf.paddr,
1808 CODA_REG_BIT_CODE_BUF_ADDR);
1809 coda_write(dev, 0, CODA_REG_BIT_CODE_RUN);
1810
1811 /* Set default values */
1812 switch (dev->devtype->product) {
1813 case CODA_DX6:
Philipp Zabelf23797b2014-08-06 08:02:23 -03001814 coda_write(dev, CODADX6_STREAM_BUF_PIC_FLUSH,
1815 CODA_REG_BIT_STREAM_CTRL);
Javier Martin186b2502012-07-26 05:53:35 -03001816 break;
1817 default:
Philipp Zabelf23797b2014-08-06 08:02:23 -03001818 coda_write(dev, CODA7_STREAM_BUF_PIC_FLUSH,
1819 CODA_REG_BIT_STREAM_CTRL);
Javier Martin186b2502012-07-26 05:53:35 -03001820 }
Philipp Zabel89548442014-07-11 06:36:17 -03001821 if (dev->devtype->product == CODA_960)
1822 coda_write(dev, 1 << 12, CODA_REG_BIT_FRAME_MEM_CTRL);
1823 else
1824 coda_write(dev, 0, CODA_REG_BIT_FRAME_MEM_CTRL);
Philipp Zabel10436672012-07-02 09:03:55 -03001825
1826 if (dev->devtype->product != CODA_DX6)
1827 coda_write(dev, 0, CODA7_REG_BIT_AXI_SRAM_USE);
1828
Javier Martin186b2502012-07-26 05:53:35 -03001829 coda_write(dev, CODA_INT_INTERRUPT_ENABLE,
1830 CODA_REG_BIT_INT_ENABLE);
1831
1832 /* Reset VPU and start processor */
1833 data = coda_read(dev, CODA_REG_BIT_CODE_RESET);
1834 data |= CODA_REG_RESET_ENABLE;
1835 coda_write(dev, data, CODA_REG_BIT_CODE_RESET);
1836 udelay(10);
1837 data &= ~CODA_REG_RESET_ENABLE;
1838 coda_write(dev, data, CODA_REG_BIT_CODE_RESET);
1839 coda_write(dev, CODA_REG_RUN_ENABLE, CODA_REG_BIT_CODE_RUN);
1840
Philipp Zabelfe7554e2014-07-11 06:36:24 -03001841 clk_disable_unprepare(dev->clk_ahb);
1842 clk_disable_unprepare(dev->clk_per);
1843
1844 return 0;
1845
1846err_clk_ahb:
1847 clk_disable_unprepare(dev->clk_per);
1848err_clk_per:
1849 return ret;
1850}
1851
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001852static int coda_register_device(struct coda_dev *dev, int i)
Philipp Zabel121cacf2014-07-18 07:22:42 -03001853{
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001854 struct video_device *vfd = &dev->vfd[i];
1855
Dan Carpenter88ca3af2015-01-08 07:07:08 -03001856 if (i >= dev->devtype->num_vdevs)
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001857 return -EINVAL;
1858
Philipp Zabelbf249da2015-03-24 14:30:50 -03001859 strlcpy(vfd->name, dev->devtype->vdevs[i]->name, sizeof(vfd->name));
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001860 vfd->fops = &coda_fops;
1861 vfd->ioctl_ops = &coda_ioctl_ops;
Philipp Zabel121cacf2014-07-18 07:22:42 -03001862 vfd->release = video_device_release_empty,
1863 vfd->lock = &dev->dev_mutex;
1864 vfd->v4l2_dev = &dev->v4l2_dev;
1865 vfd->vfl_dir = VFL_DIR_M2M;
1866 video_set_drvdata(vfd, dev);
1867
Philipp Zabela188a662014-08-05 14:00:20 -03001868 /* Not applicable, use the selection API instead */
1869 v4l2_disable_ioctl(vfd, VIDIOC_CROPCAP);
1870 v4l2_disable_ioctl(vfd, VIDIOC_G_CROP);
1871 v4l2_disable_ioctl(vfd, VIDIOC_S_CROP);
1872
Philipp Zabel121cacf2014-07-18 07:22:42 -03001873 return video_register_device(vfd, VFL_TYPE_GRABBER, 0);
1874}
1875
Javier Martin186b2502012-07-26 05:53:35 -03001876static void coda_fw_callback(const struct firmware *fw, void *context)
1877{
1878 struct coda_dev *dev = context;
1879 struct platform_device *pdev = dev->plat_dev;
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001880 int i, ret;
Javier Martin186b2502012-07-26 05:53:35 -03001881
1882 if (!fw) {
1883 v4l2_err(&dev->v4l2_dev, "firmware request failed\n");
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03001884 goto put_pm;
Javier Martin186b2502012-07-26 05:53:35 -03001885 }
1886
1887 /* allocate auxiliary per-device code buffer for the BIT processor */
Philipp Zabelf61c0b12014-07-11 06:36:40 -03001888 ret = coda_alloc_aux_buf(dev, &dev->codebuf, fw->size, "codebuf",
1889 dev->debugfs_root);
Philipp Zabel6ba53b82015-03-24 14:30:54 -03001890 if (ret < 0)
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03001891 goto put_pm;
Javier Martin186b2502012-07-26 05:53:35 -03001892
Philipp Zabel87048bb2012-07-02 07:03:43 -03001893 /* Copy the whole firmware image to the code buffer */
1894 memcpy(dev->codebuf.vaddr, fw->data, fw->size);
1895 release_firmware(fw);
1896
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03001897 ret = coda_hw_init(dev);
1898 if (ret < 0) {
1899 v4l2_err(&dev->v4l2_dev, "HW initialization failed\n");
1900 goto put_pm;
Javier Martin186b2502012-07-26 05:53:35 -03001901 }
1902
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03001903 ret = coda_check_firmware(dev);
1904 if (ret < 0)
1905 goto put_pm;
1906
Javier Martin186b2502012-07-26 05:53:35 -03001907 dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
1908 if (IS_ERR(dev->alloc_ctx)) {
1909 v4l2_err(&dev->v4l2_dev, "Failed to alloc vb2 context\n");
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03001910 goto put_pm;
Javier Martin186b2502012-07-26 05:53:35 -03001911 }
1912
1913 dev->m2m_dev = v4l2_m2m_init(&coda_m2m_ops);
1914 if (IS_ERR(dev->m2m_dev)) {
1915 v4l2_err(&dev->v4l2_dev, "Failed to init mem2mem device\n");
1916 goto rel_ctx;
1917 }
1918
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001919 for (i = 0; i < dev->devtype->num_vdevs; i++) {
1920 ret = coda_register_device(dev, i);
1921 if (ret) {
1922 v4l2_err(&dev->v4l2_dev,
1923 "Failed to register %s video device: %d\n",
1924 dev->devtype->vdevs[i]->name, ret);
1925 goto rel_vfd;
1926 }
Philipp Zabel121cacf2014-07-18 07:22:42 -03001927 }
1928
1929 v4l2_info(&dev->v4l2_dev, "codec registered as /dev/video[%d-%d]\n",
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001930 dev->vfd[0].num, dev->vfd[i - 1].num);
Javier Martin186b2502012-07-26 05:53:35 -03001931
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03001932 pm_runtime_put_sync(&pdev->dev);
Javier Martin186b2502012-07-26 05:53:35 -03001933 return;
1934
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001935rel_vfd:
1936 while (--i >= 0)
1937 video_unregister_device(&dev->vfd[i]);
Javier Martin186b2502012-07-26 05:53:35 -03001938 v4l2_m2m_release(dev->m2m_dev);
1939rel_ctx:
1940 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx);
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03001941put_pm:
1942 pm_runtime_put_sync(&pdev->dev);
Javier Martin186b2502012-07-26 05:53:35 -03001943}
1944
1945static int coda_firmware_request(struct coda_dev *dev)
1946{
1947 char *fw = dev->devtype->firmware;
1948
1949 dev_dbg(&dev->plat_dev->dev, "requesting firmware '%s' for %s\n", fw,
1950 coda_product_name(dev->devtype->product));
1951
1952 return request_firmware_nowait(THIS_MODULE, true,
1953 fw, &dev->plat_dev->dev, GFP_KERNEL, dev, coda_fw_callback);
1954}
1955
1956enum coda_platform {
1957 CODA_IMX27,
Philipp Zabeldf1e74c2012-07-02 06:07:10 -03001958 CODA_IMX53,
Philipp Zabel89548442014-07-11 06:36:17 -03001959 CODA_IMX6Q,
1960 CODA_IMX6DL,
Javier Martin186b2502012-07-26 05:53:35 -03001961};
1962
Emil Goodec06d8752012-08-14 17:44:42 -03001963static const struct coda_devtype coda_devdata[] = {
Javier Martin186b2502012-07-26 05:53:35 -03001964 [CODA_IMX27] = {
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03001965 .firmware = "v4l-codadx6-imx27.bin",
1966 .product = CODA_DX6,
1967 .codecs = codadx6_codecs,
1968 .num_codecs = ARRAY_SIZE(codadx6_codecs),
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001969 .vdevs = codadx6_video_devices,
1970 .num_vdevs = ARRAY_SIZE(codadx6_video_devices),
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03001971 .workbuf_size = 288 * 1024 + FMO_SLICE_SAVE_BUF_SIZE * 8 * 1024,
Philipp Zabel401e9722014-07-11 06:36:43 -03001972 .iram_size = 0xb000,
Javier Martin186b2502012-07-26 05:53:35 -03001973 },
Philipp Zabeldf1e74c2012-07-02 06:07:10 -03001974 [CODA_IMX53] = {
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03001975 .firmware = "v4l-coda7541-imx53.bin",
1976 .product = CODA_7541,
1977 .codecs = coda7_codecs,
1978 .num_codecs = ARRAY_SIZE(coda7_codecs),
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001979 .vdevs = coda7_video_devices,
1980 .num_vdevs = ARRAY_SIZE(coda7_video_devices),
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03001981 .workbuf_size = 128 * 1024,
Philipp Zabel5d73fad2014-07-11 06:36:42 -03001982 .tempbuf_size = 304 * 1024,
Philipp Zabel401e9722014-07-11 06:36:43 -03001983 .iram_size = 0x14000,
Philipp Zabeldf1e74c2012-07-02 06:07:10 -03001984 },
Philipp Zabel89548442014-07-11 06:36:17 -03001985 [CODA_IMX6Q] = {
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03001986 .firmware = "v4l-coda960-imx6q.bin",
1987 .product = CODA_960,
1988 .codecs = coda9_codecs,
1989 .num_codecs = ARRAY_SIZE(coda9_codecs),
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001990 .vdevs = coda9_video_devices,
1991 .num_vdevs = ARRAY_SIZE(coda9_video_devices),
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03001992 .workbuf_size = 80 * 1024,
Philipp Zabel5d73fad2014-07-11 06:36:42 -03001993 .tempbuf_size = 204 * 1024,
Philipp Zabel401e9722014-07-11 06:36:43 -03001994 .iram_size = 0x21000,
Philipp Zabel89548442014-07-11 06:36:17 -03001995 },
1996 [CODA_IMX6DL] = {
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03001997 .firmware = "v4l-coda960-imx6dl.bin",
1998 .product = CODA_960,
1999 .codecs = coda9_codecs,
2000 .num_codecs = ARRAY_SIZE(coda9_codecs),
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03002001 .vdevs = coda9_video_devices,
2002 .num_vdevs = ARRAY_SIZE(coda9_video_devices),
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03002003 .workbuf_size = 80 * 1024,
Philipp Zabel5d73fad2014-07-11 06:36:42 -03002004 .tempbuf_size = 204 * 1024,
Philipp Zabel401e9722014-07-11 06:36:43 -03002005 .iram_size = 0x20000,
Philipp Zabel89548442014-07-11 06:36:17 -03002006 },
Javier Martin186b2502012-07-26 05:53:35 -03002007};
2008
2009static struct platform_device_id coda_platform_ids[] = {
2010 { .name = "coda-imx27", .driver_data = CODA_IMX27 },
2011 { /* sentinel */ }
2012};
2013MODULE_DEVICE_TABLE(platform, coda_platform_ids);
2014
2015#ifdef CONFIG_OF
2016static const struct of_device_id coda_dt_ids[] = {
Alexander Shiyan7b0dd9e2013-06-15 08:09:57 -03002017 { .compatible = "fsl,imx27-vpu", .data = &coda_devdata[CODA_IMX27] },
Philipp Zabeldf1e74c2012-07-02 06:07:10 -03002018 { .compatible = "fsl,imx53-vpu", .data = &coda_devdata[CODA_IMX53] },
Philipp Zabel89548442014-07-11 06:36:17 -03002019 { .compatible = "fsl,imx6q-vpu", .data = &coda_devdata[CODA_IMX6Q] },
2020 { .compatible = "fsl,imx6dl-vpu", .data = &coda_devdata[CODA_IMX6DL] },
Javier Martin186b2502012-07-26 05:53:35 -03002021 { /* sentinel */ }
2022};
2023MODULE_DEVICE_TABLE(of, coda_dt_ids);
2024#endif
2025
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08002026static int coda_probe(struct platform_device *pdev)
Javier Martin186b2502012-07-26 05:53:35 -03002027{
2028 const struct of_device_id *of_id =
2029 of_match_device(of_match_ptr(coda_dt_ids), &pdev->dev);
2030 const struct platform_device_id *pdev_id;
Philipp Zabel657eee72013-04-29 16:17:14 -07002031 struct coda_platform_data *pdata = pdev->dev.platform_data;
2032 struct device_node *np = pdev->dev.of_node;
2033 struct gen_pool *pool;
Javier Martin186b2502012-07-26 05:53:35 -03002034 struct coda_dev *dev;
2035 struct resource *res;
2036 int ret, irq;
2037
Philipp Zabelf23797b2014-08-06 08:02:23 -03002038 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
Philipp Zabel6da999d2014-09-29 09:53:43 -03002039 if (!dev)
Javier Martin186b2502012-07-26 05:53:35 -03002040 return -ENOMEM;
Javier Martin186b2502012-07-26 05:53:35 -03002041
Philipp Zabelb2f91ae2014-10-02 14:08:27 -03002042 pdev_id = of_id ? of_id->data : platform_get_device_id(pdev);
2043
Fabio Estevamb7bd6602014-10-04 16:40:50 -03002044 if (of_id) {
Philipp Zabelb2f91ae2014-10-02 14:08:27 -03002045 dev->devtype = of_id->data;
Fabio Estevamb7bd6602014-10-04 16:40:50 -03002046 } else if (pdev_id) {
Philipp Zabelb2f91ae2014-10-02 14:08:27 -03002047 dev->devtype = &coda_devdata[pdev_id->driver_data];
Fabio Estevamb7bd6602014-10-04 16:40:50 -03002048 } else {
2049 ret = -EINVAL;
2050 goto err_v4l2_register;
Javier Martin186b2502012-07-26 05:53:35 -03002051 }
2052
2053 spin_lock_init(&dev->irqlock);
Philipp Zabele11f3e62012-07-25 09:16:58 -03002054 INIT_LIST_HEAD(&dev->instances);
Javier Martin186b2502012-07-26 05:53:35 -03002055
2056 dev->plat_dev = pdev;
2057 dev->clk_per = devm_clk_get(&pdev->dev, "per");
2058 if (IS_ERR(dev->clk_per)) {
2059 dev_err(&pdev->dev, "Could not get per clock\n");
2060 return PTR_ERR(dev->clk_per);
2061 }
2062
2063 dev->clk_ahb = devm_clk_get(&pdev->dev, "ahb");
2064 if (IS_ERR(dev->clk_ahb)) {
2065 dev_err(&pdev->dev, "Could not get ahb clock\n");
2066 return PTR_ERR(dev->clk_ahb);
2067 }
2068
2069 /* Get memory for physical registers */
2070 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Philipp Zabel611cbbf2013-05-21 04:19:27 -03002071 dev->regs_base = devm_ioremap_resource(&pdev->dev, res);
2072 if (IS_ERR(dev->regs_base))
2073 return PTR_ERR(dev->regs_base);
Javier Martin186b2502012-07-26 05:53:35 -03002074
2075 /* IRQ */
Philipp Zabel540b72e2014-08-05 14:00:09 -03002076 irq = platform_get_irq_byname(pdev, "bit");
2077 if (irq < 0)
2078 irq = platform_get_irq(pdev, 0);
Javier Martin186b2502012-07-26 05:53:35 -03002079 if (irq < 0) {
2080 dev_err(&pdev->dev, "failed to get irq resource\n");
Fabio Estevam7d377432014-06-04 15:46:23 -03002081 return irq;
Javier Martin186b2502012-07-26 05:53:35 -03002082 }
2083
Fabio Estevam08c8d142014-06-04 15:46:24 -03002084 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, coda_irq_handler,
2085 IRQF_ONESHOT, dev_name(&pdev->dev), dev);
2086 if (ret < 0) {
2087 dev_err(&pdev->dev, "failed to request irq: %d\n", ret);
2088 return ret;
Javier Martin186b2502012-07-26 05:53:35 -03002089 }
2090
Philipp Zabelee27aa92014-07-24 16:50:03 -03002091 dev->rstc = devm_reset_control_get_optional(&pdev->dev, NULL);
Philipp Zabel8f452842014-07-11 06:36:35 -03002092 if (IS_ERR(dev->rstc)) {
2093 ret = PTR_ERR(dev->rstc);
Philipp Zabelee27aa92014-07-24 16:50:03 -03002094 if (ret == -ENOENT || ret == -ENOSYS) {
Philipp Zabel8f452842014-07-11 06:36:35 -03002095 dev->rstc = NULL;
2096 } else {
Philipp Zabelf23797b2014-08-06 08:02:23 -03002097 dev_err(&pdev->dev, "failed get reset control: %d\n",
2098 ret);
Philipp Zabel8f452842014-07-11 06:36:35 -03002099 return ret;
2100 }
2101 }
2102
Philipp Zabel657eee72013-04-29 16:17:14 -07002103 /* Get IRAM pool from device tree or platform data */
Vladimir Zapolskiyabdd4a72015-06-30 15:00:07 -07002104 pool = of_gen_pool_get(np, "iram", 0);
Philipp Zabel657eee72013-04-29 16:17:14 -07002105 if (!pool && pdata)
Vladimir Zapolskiy0030edf2015-06-30 15:00:03 -07002106 pool = gen_pool_get(pdata->iram_dev);
Philipp Zabel657eee72013-04-29 16:17:14 -07002107 if (!pool) {
2108 dev_err(&pdev->dev, "iram pool not available\n");
2109 return -ENOMEM;
2110 }
2111 dev->iram_pool = pool;
2112
Javier Martin186b2502012-07-26 05:53:35 -03002113 ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
2114 if (ret)
2115 return ret;
2116
2117 mutex_init(&dev->dev_mutex);
Philipp Zabelfcb62822013-05-23 10:43:00 -03002118 mutex_init(&dev->coda_mutex);
Javier Martin186b2502012-07-26 05:53:35 -03002119
Philipp Zabelf61c0b12014-07-11 06:36:40 -03002120 dev->debugfs_root = debugfs_create_dir("coda", NULL);
2121 if (!dev->debugfs_root)
2122 dev_warn(&pdev->dev, "failed to create debugfs root\n");
2123
Javier Martin186b2502012-07-26 05:53:35 -03002124 /* allocate auxiliary per-device buffers for the BIT processor */
Philipp Zabel5d73fad2014-07-11 06:36:42 -03002125 if (dev->devtype->product == CODA_DX6) {
Philipp Zabel5677e3b2013-06-21 03:55:30 -03002126 ret = coda_alloc_aux_buf(dev, &dev->workbuf,
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03002127 dev->devtype->workbuf_size, "workbuf",
Philipp Zabelf61c0b12014-07-11 06:36:40 -03002128 dev->debugfs_root);
Philipp Zabel6ba53b82015-03-24 14:30:54 -03002129 if (ret < 0)
Fabio Estevamb7bd6602014-10-04 16:40:50 -03002130 goto err_v4l2_register;
Javier Martin186b2502012-07-26 05:53:35 -03002131 }
Philipp Zabel5d73fad2014-07-11 06:36:42 -03002132
2133 if (dev->devtype->tempbuf_size) {
Philipp Zabel5677e3b2013-06-21 03:55:30 -03002134 ret = coda_alloc_aux_buf(dev, &dev->tempbuf,
Philipp Zabel5d73fad2014-07-11 06:36:42 -03002135 dev->devtype->tempbuf_size, "tempbuf",
Philipp Zabelf61c0b12014-07-11 06:36:40 -03002136 dev->debugfs_root);
Philipp Zabel6ba53b82015-03-24 14:30:54 -03002137 if (ret < 0)
Fabio Estevamb7bd6602014-10-04 16:40:50 -03002138 goto err_v4l2_register;
Javier Martin186b2502012-07-26 05:53:35 -03002139 }
2140
Philipp Zabel401e9722014-07-11 06:36:43 -03002141 dev->iram.size = dev->devtype->iram_size;
Philipp Zabelb313bcc2014-07-11 06:36:16 -03002142 dev->iram.vaddr = gen_pool_dma_alloc(dev->iram_pool, dev->iram.size,
2143 &dev->iram.paddr);
2144 if (!dev->iram.vaddr) {
Philipp Zabel8be31c82014-08-05 14:00:13 -03002145 dev_warn(&pdev->dev, "unable to alloc iram\n");
2146 } else {
Philipp Zabel811a6932015-01-23 13:51:23 -03002147 memset(dev->iram.vaddr, 0, dev->iram.size);
Philipp Zabel8be31c82014-08-05 14:00:13 -03002148 dev->iram.blob.data = dev->iram.vaddr;
2149 dev->iram.blob.size = dev->iram.size;
2150 dev->iram.dentry = debugfs_create_blob("iram", 0644,
2151 dev->debugfs_root,
2152 &dev->iram.blob);
Philipp Zabel10436672012-07-02 09:03:55 -03002153 }
2154
Philipp Zabel32b6f202014-07-11 06:36:20 -03002155 dev->workqueue = alloc_workqueue("coda", WQ_UNBOUND | WQ_MEM_RECLAIM, 1);
2156 if (!dev->workqueue) {
2157 dev_err(&pdev->dev, "unable to alloc workqueue\n");
Fabio Estevam74d08d52014-10-04 16:40:51 -03002158 ret = -ENOMEM;
2159 goto err_v4l2_register;
Philipp Zabel32b6f202014-07-11 06:36:20 -03002160 }
2161
Javier Martin186b2502012-07-26 05:53:35 -03002162 platform_set_drvdata(pdev, dev);
2163
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03002164 /*
2165 * Start activated so we can directly call coda_hw_init in
Rafael J. Wysockie243c7c2014-12-04 01:10:10 +01002166 * coda_fw_callback regardless of whether CONFIG_PM is
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03002167 * enabled or whether the device is associated with a PM domain.
2168 */
2169 pm_runtime_get_noresume(&pdev->dev);
2170 pm_runtime_set_active(&pdev->dev);
Philipp Zabel1e172732014-07-11 06:36:23 -03002171 pm_runtime_enable(&pdev->dev);
2172
Javier Martin186b2502012-07-26 05:53:35 -03002173 return coda_firmware_request(dev);
Fabio Estevamb7bd6602014-10-04 16:40:50 -03002174
2175err_v4l2_register:
2176 v4l2_device_unregister(&dev->v4l2_dev);
2177 return ret;
Javier Martin186b2502012-07-26 05:53:35 -03002178}
2179
2180static int coda_remove(struct platform_device *pdev)
2181{
2182 struct coda_dev *dev = platform_get_drvdata(pdev);
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03002183 int i;
Javier Martin186b2502012-07-26 05:53:35 -03002184
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03002185 for (i = 0; i < ARRAY_SIZE(dev->vfd); i++) {
2186 if (video_get_drvdata(&dev->vfd[i]))
2187 video_unregister_device(&dev->vfd[i]);
2188 }
Javier Martin186b2502012-07-26 05:53:35 -03002189 if (dev->m2m_dev)
2190 v4l2_m2m_release(dev->m2m_dev);
Philipp Zabel1e172732014-07-11 06:36:23 -03002191 pm_runtime_disable(&pdev->dev);
Javier Martin186b2502012-07-26 05:53:35 -03002192 if (dev->alloc_ctx)
2193 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx);
2194 v4l2_device_unregister(&dev->v4l2_dev);
Philipp Zabel32b6f202014-07-11 06:36:20 -03002195 destroy_workqueue(dev->workqueue);
Philipp Zabelb313bcc2014-07-11 06:36:16 -03002196 if (dev->iram.vaddr)
2197 gen_pool_free(dev->iram_pool, (unsigned long)dev->iram.vaddr,
2198 dev->iram.size);
Philipp Zabel5677e3b2013-06-21 03:55:30 -03002199 coda_free_aux_buf(dev, &dev->codebuf);
2200 coda_free_aux_buf(dev, &dev->tempbuf);
2201 coda_free_aux_buf(dev, &dev->workbuf);
Philipp Zabelf61c0b12014-07-11 06:36:40 -03002202 debugfs_remove_recursive(dev->debugfs_root);
Javier Martin186b2502012-07-26 05:53:35 -03002203 return 0;
2204}
2205
Rafael J. Wysockie243c7c2014-12-04 01:10:10 +01002206#ifdef CONFIG_PM
Philipp Zabel1e172732014-07-11 06:36:23 -03002207static int coda_runtime_resume(struct device *dev)
2208{
2209 struct coda_dev *cdev = dev_get_drvdata(dev);
2210 int ret = 0;
2211
Philipp Zabel65919e62014-07-18 07:22:36 -03002212 if (dev->pm_domain && cdev->codebuf.vaddr) {
Philipp Zabel1e172732014-07-11 06:36:23 -03002213 ret = coda_hw_init(cdev);
2214 if (ret)
2215 v4l2_err(&cdev->v4l2_dev, "HW initialization failed\n");
2216 }
2217
2218 return ret;
2219}
2220#endif
2221
2222static const struct dev_pm_ops coda_pm_ops = {
2223 SET_RUNTIME_PM_OPS(NULL, coda_runtime_resume, NULL)
2224};
2225
Javier Martin186b2502012-07-26 05:53:35 -03002226static struct platform_driver coda_driver = {
2227 .probe = coda_probe,
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08002228 .remove = coda_remove,
Javier Martin186b2502012-07-26 05:53:35 -03002229 .driver = {
2230 .name = CODA_NAME,
Javier Martin186b2502012-07-26 05:53:35 -03002231 .of_match_table = of_match_ptr(coda_dt_ids),
Philipp Zabel1e172732014-07-11 06:36:23 -03002232 .pm = &coda_pm_ops,
Javier Martin186b2502012-07-26 05:53:35 -03002233 },
2234 .id_table = coda_platform_ids,
2235};
2236
2237module_platform_driver(coda_driver);
2238
2239MODULE_LICENSE("GPL");
2240MODULE_AUTHOR("Javier Martin <javier.martin@vista-silicon.com>");
2241MODULE_DESCRIPTION("Coda multi-standard codec V4L2 driver");