blob: 490b933ad616438eb16d948da4a9688b88b2ee36 [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>
40
Philipp Zabela2b3e462014-07-23 12:28:39 -030041#include "coda.h"
Javier Martin186b2502012-07-26 05:53:35 -030042
43#define CODA_NAME "coda"
44
Philipp Zabel0cddc7e2013-09-30 10:34:44 -030045#define CODADX6_MAX_INSTANCES 4
Philipp Zabel2c11d1b2014-10-02 14:08:28 -030046#define CODA_MAX_FORMATS 4
Javier Martin186b2502012-07-26 05:53:35 -030047
Javier Martin186b2502012-07-26 05:53:35 -030048#define CODA_PARA_BUF_SIZE (10 * 1024)
49#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
Javier Martin186b2502012-07-26 05:53:35 -030064struct coda_fmt {
65 char *name;
66 u32 fourcc;
Philipp Zabelb96904e2013-05-23 10:42:58 -030067};
68
Philipp Zabela2b3e462014-07-23 12:28:39 -030069void coda_write(struct coda_dev *dev, u32 data, u32 reg)
Javier Martin186b2502012-07-26 05:53:35 -030070{
Philipp Zabeld60b18b2014-08-05 14:00:15 -030071 v4l2_dbg(2, coda_debug, &dev->v4l2_dev,
Javier Martin186b2502012-07-26 05:53:35 -030072 "%s: data=0x%x, reg=0x%x\n", __func__, data, reg);
73 writel(data, dev->regs_base + reg);
74}
75
Philipp Zabela2b3e462014-07-23 12:28:39 -030076unsigned int coda_read(struct coda_dev *dev, u32 reg)
Javier Martin186b2502012-07-26 05:53:35 -030077{
78 u32 data;
Philipp Zabelf23797b2014-08-06 08:02:23 -030079
Javier Martin186b2502012-07-26 05:53:35 -030080 data = readl(dev->regs_base + reg);
Philipp Zabeld60b18b2014-08-05 14:00:15 -030081 v4l2_dbg(2, coda_debug, &dev->v4l2_dev,
Javier Martin186b2502012-07-26 05:53:35 -030082 "%s: data=0x%x, reg=0x%x\n", __func__, data, reg);
83 return data;
84}
85
Philipp Zabel856d7d92014-09-29 09:53:44 -030086void coda_write_base(struct coda_ctx *ctx, struct coda_q_data *q_data,
87 struct vb2_buffer *buf, unsigned int reg_y)
88{
89 u32 base_y = vb2_dma_contig_plane_dma_addr(buf, 0);
90 u32 base_cb, base_cr;
91
92 switch (q_data->fourcc) {
93 case V4L2_PIX_FMT_YVU420:
94 /* Switch Cb and Cr for YVU420 format */
95 base_cr = base_y + q_data->bytesperline * q_data->height;
96 base_cb = base_cr + q_data->bytesperline * q_data->height / 4;
97 break;
98 case V4L2_PIX_FMT_YUV420:
Philipp Zabel1cb12cf2014-09-29 09:53:47 -030099 case V4L2_PIX_FMT_NV12:
Philipp Zabel856d7d92014-09-29 09:53:44 -0300100 default:
101 base_cb = base_y + q_data->bytesperline * q_data->height;
102 base_cr = base_cb + q_data->bytesperline * q_data->height / 4;
103 break;
Philipp Zabel4de69312014-10-02 14:08:26 -0300104 case V4L2_PIX_FMT_YUV422P:
105 base_cb = base_y + q_data->bytesperline * q_data->height;
106 base_cr = base_cb + q_data->bytesperline * q_data->height / 2;
Philipp Zabel856d7d92014-09-29 09:53:44 -0300107 }
108
109 coda_write(ctx->dev, base_y, reg_y);
110 coda_write(ctx->dev, base_cb, reg_y + 4);
111 coda_write(ctx->dev, base_cr, reg_y + 8);
112}
113
Javier Martin186b2502012-07-26 05:53:35 -0300114/*
Philipp Zabelb96904e2013-05-23 10:42:58 -0300115 * Array of all formats supported by any version of Coda:
Javier Martin186b2502012-07-26 05:53:35 -0300116 */
Philipp Zabel814c3762014-07-18 07:22:45 -0300117static const struct coda_fmt coda_formats[] = {
Javier Martin186b2502012-07-26 05:53:35 -0300118 {
Philipp Zabelb96904e2013-05-23 10:42:58 -0300119 .name = "YUV 4:2:0 Planar, YCbCr",
Javier Martin186b2502012-07-26 05:53:35 -0300120 .fourcc = V4L2_PIX_FMT_YUV420,
Philipp Zabelb96904e2013-05-23 10:42:58 -0300121 },
122 {
123 .name = "YUV 4:2:0 Planar, YCrCb",
124 .fourcc = V4L2_PIX_FMT_YVU420,
Javier Martin186b2502012-07-26 05:53:35 -0300125 },
126 {
Philipp Zabel1cb12cf2014-09-29 09:53:47 -0300127 .name = "YUV 4:2:0 Partial interleaved Y/CbCr",
128 .fourcc = V4L2_PIX_FMT_NV12,
129 },
130 {
Philipp Zabel4de69312014-10-02 14:08:26 -0300131 .name = "YUV 4:2:2 Planar, YCbCr",
132 .fourcc = V4L2_PIX_FMT_YUV422P,
133 },
134 {
Javier Martin186b2502012-07-26 05:53:35 -0300135 .name = "H264 Encoded Stream",
136 .fourcc = V4L2_PIX_FMT_H264,
Javier Martin186b2502012-07-26 05:53:35 -0300137 },
138 {
139 .name = "MPEG4 Encoded Stream",
140 .fourcc = V4L2_PIX_FMT_MPEG4,
Javier Martin186b2502012-07-26 05:53:35 -0300141 },
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300142 {
143 .name = "JPEG Encoded Images",
144 .fourcc = V4L2_PIX_FMT_JPEG,
145 },
Javier Martin186b2502012-07-26 05:53:35 -0300146};
147
Philipp Zabelb96904e2013-05-23 10:42:58 -0300148#define CODA_CODEC(mode, src_fourcc, dst_fourcc, max_w, max_h) \
149 { mode, src_fourcc, dst_fourcc, max_w, max_h }
150
151/*
152 * Arrays of codecs supported by each given version of Coda:
153 * i.MX27 -> codadx6
154 * i.MX5x -> coda7
155 * i.MX6 -> coda960
156 * Use V4L2_PIX_FMT_YUV420 as placeholder for all supported YUV 4:2:0 variants
157 */
Philipp Zabel814c3762014-07-18 07:22:45 -0300158static const struct coda_codec codadx6_codecs[] = {
Philipp Zabelb96904e2013-05-23 10:42:58 -0300159 CODA_CODEC(CODADX6_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 720, 576),
160 CODA_CODEC(CODADX6_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 720, 576),
Philipp Zabeldf1e74c2012-07-02 06:07:10 -0300161};
162
Philipp Zabel814c3762014-07-18 07:22:45 -0300163static const struct coda_codec coda7_codecs[] = {
Philipp Zabelb96904e2013-05-23 10:42:58 -0300164 CODA_CODEC(CODA7_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 1280, 720),
165 CODA_CODEC(CODA7_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 1280, 720),
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300166 CODA_CODEC(CODA7_MODE_ENCODE_MJPG, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_JPEG, 8192, 8192),
Philipp Zabelb0ed05b2014-08-05 14:00:14 -0300167 CODA_CODEC(CODA7_MODE_DECODE_H264, V4L2_PIX_FMT_H264, V4L2_PIX_FMT_YUV420, 1920, 1088),
168 CODA_CODEC(CODA7_MODE_DECODE_MP4, V4L2_PIX_FMT_MPEG4, V4L2_PIX_FMT_YUV420, 1920, 1088),
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300169 CODA_CODEC(CODA7_MODE_DECODE_MJPG, V4L2_PIX_FMT_JPEG, V4L2_PIX_FMT_YUV420, 8192, 8192),
Philipp Zabelb96904e2013-05-23 10:42:58 -0300170};
171
Philipp Zabel814c3762014-07-18 07:22:45 -0300172static const struct coda_codec coda9_codecs[] = {
Philipp Zabelb0ed05b2014-08-05 14:00:14 -0300173 CODA_CODEC(CODA9_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 1920, 1088),
174 CODA_CODEC(CODA9_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 1920, 1088),
175 CODA_CODEC(CODA9_MODE_DECODE_H264, V4L2_PIX_FMT_H264, V4L2_PIX_FMT_YUV420, 1920, 1088),
176 CODA_CODEC(CODA9_MODE_DECODE_MP4, V4L2_PIX_FMT_MPEG4, V4L2_PIX_FMT_YUV420, 1920, 1088),
Philipp Zabel89548442014-07-11 06:36:17 -0300177};
178
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300179struct coda_video_device {
180 const char *name;
181 enum coda_inst_type type;
182 const struct coda_context_ops *ops;
183 u32 src_formats[CODA_MAX_FORMATS];
184 u32 dst_formats[CODA_MAX_FORMATS];
185};
186
187static const struct coda_video_device coda_bit_encoder = {
188 .name = "coda-encoder",
189 .type = CODA_INST_ENCODER,
190 .ops = &coda_bit_encode_ops,
191 .src_formats = {
192 V4L2_PIX_FMT_YUV420,
193 V4L2_PIX_FMT_YVU420,
194 V4L2_PIX_FMT_NV12,
195 },
196 .dst_formats = {
197 V4L2_PIX_FMT_H264,
198 V4L2_PIX_FMT_MPEG4,
199 },
200};
201
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300202static const struct coda_video_device coda_bit_jpeg_encoder = {
203 .name = "coda-jpeg-encoder",
204 .type = CODA_INST_ENCODER,
205 .ops = &coda_bit_encode_ops,
206 .src_formats = {
207 V4L2_PIX_FMT_YUV420,
208 V4L2_PIX_FMT_YVU420,
209 V4L2_PIX_FMT_NV12,
210 V4L2_PIX_FMT_YUV422P,
211 },
212 .dst_formats = {
213 V4L2_PIX_FMT_JPEG,
214 },
215};
216
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300217static const struct coda_video_device coda_bit_decoder = {
218 .name = "coda-decoder",
219 .type = CODA_INST_DECODER,
220 .ops = &coda_bit_decode_ops,
221 .src_formats = {
222 V4L2_PIX_FMT_H264,
223 V4L2_PIX_FMT_MPEG4,
224 },
225 .dst_formats = {
226 V4L2_PIX_FMT_YUV420,
227 V4L2_PIX_FMT_YVU420,
228 V4L2_PIX_FMT_NV12,
229 },
230};
231
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300232static const struct coda_video_device coda_bit_jpeg_decoder = {
233 .name = "coda-jpeg-decoder",
234 .type = CODA_INST_DECODER,
235 .ops = &coda_bit_decode_ops,
236 .src_formats = {
237 V4L2_PIX_FMT_JPEG,
238 },
239 .dst_formats = {
240 V4L2_PIX_FMT_YUV420,
241 V4L2_PIX_FMT_YVU420,
242 V4L2_PIX_FMT_NV12,
243 V4L2_PIX_FMT_YUV422P,
244 },
245};
246
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300247static const struct coda_video_device *codadx6_video_devices[] = {
248 &coda_bit_encoder,
249};
250
251static const struct coda_video_device *coda7_video_devices[] = {
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300252 &coda_bit_jpeg_encoder,
253 &coda_bit_jpeg_decoder,
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300254 &coda_bit_encoder,
255 &coda_bit_decoder,
256};
257
258static const struct coda_video_device *coda9_video_devices[] = {
259 &coda_bit_encoder,
260 &coda_bit_decoder,
261};
262
Philipp Zabelb96904e2013-05-23 10:42:58 -0300263static bool coda_format_is_yuv(u32 fourcc)
Javier Martin186b2502012-07-26 05:53:35 -0300264{
Philipp Zabelb96904e2013-05-23 10:42:58 -0300265 switch (fourcc) {
266 case V4L2_PIX_FMT_YUV420:
267 case V4L2_PIX_FMT_YVU420:
Philipp Zabel1cb12cf2014-09-29 09:53:47 -0300268 case V4L2_PIX_FMT_NV12:
Philipp Zabel4de69312014-10-02 14:08:26 -0300269 case V4L2_PIX_FMT_YUV422P:
Philipp Zabelb96904e2013-05-23 10:42:58 -0300270 return true;
271 default:
272 return false;
273 }
274}
Javier Martin186b2502012-07-26 05:53:35 -0300275
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300276static const char *coda_format_name(u32 fourcc)
277{
278 int i;
279
280 for (i = 0; i < ARRAY_SIZE(coda_formats); i++) {
281 if (coda_formats[i].fourcc == fourcc)
282 return coda_formats[i].name;
283 }
284
285 return NULL;
286}
287
Philipp Zabelb96904e2013-05-23 10:42:58 -0300288/*
289 * Normalize all supported YUV 4:2:0 formats to the value used in the codec
290 * tables.
291 */
292static u32 coda_format_normalize_yuv(u32 fourcc)
293{
294 return coda_format_is_yuv(fourcc) ? V4L2_PIX_FMT_YUV420 : fourcc;
295}
296
Philipp Zabel814c3762014-07-18 07:22:45 -0300297static const struct coda_codec *coda_find_codec(struct coda_dev *dev,
298 int src_fourcc, int dst_fourcc)
Philipp Zabelb96904e2013-05-23 10:42:58 -0300299{
Philipp Zabel814c3762014-07-18 07:22:45 -0300300 const struct coda_codec *codecs = dev->devtype->codecs;
Philipp Zabelb96904e2013-05-23 10:42:58 -0300301 int num_codecs = dev->devtype->num_codecs;
302 int k;
303
304 src_fourcc = coda_format_normalize_yuv(src_fourcc);
305 dst_fourcc = coda_format_normalize_yuv(dst_fourcc);
306 if (src_fourcc == dst_fourcc)
307 return NULL;
308
309 for (k = 0; k < num_codecs; k++) {
310 if (codecs[k].src_fourcc == src_fourcc &&
311 codecs[k].dst_fourcc == dst_fourcc)
Javier Martin186b2502012-07-26 05:53:35 -0300312 break;
313 }
314
Philipp Zabelb96904e2013-05-23 10:42:58 -0300315 if (k == num_codecs)
Javier Martin186b2502012-07-26 05:53:35 -0300316 return NULL;
317
Philipp Zabelb96904e2013-05-23 10:42:58 -0300318 return &codecs[k];
Javier Martin186b2502012-07-26 05:53:35 -0300319}
320
Philipp Zabel57625592013-09-30 10:34:51 -0300321static void coda_get_max_dimensions(struct coda_dev *dev,
Philipp Zabel814c3762014-07-18 07:22:45 -0300322 const struct coda_codec *codec,
Philipp Zabel57625592013-09-30 10:34:51 -0300323 int *max_w, int *max_h)
324{
Philipp Zabel814c3762014-07-18 07:22:45 -0300325 const struct coda_codec *codecs = dev->devtype->codecs;
Philipp Zabel57625592013-09-30 10:34:51 -0300326 int num_codecs = dev->devtype->num_codecs;
327 unsigned int w, h;
328 int k;
329
330 if (codec) {
331 w = codec->max_w;
332 h = codec->max_h;
333 } else {
334 for (k = 0, w = 0, h = 0; k < num_codecs; k++) {
335 w = max(w, codecs[k].max_w);
336 h = max(h, codecs[k].max_h);
337 }
338 }
339
340 if (max_w)
341 *max_w = w;
342 if (max_h)
343 *max_h = h;
344}
345
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300346const struct coda_video_device *to_coda_video_device(struct video_device *vdev)
347{
348 struct coda_dev *dev = video_get_drvdata(vdev);
349 unsigned int i = vdev - dev->vfd;
350
351 if (i >= dev->devtype->num_vdevs)
352 return NULL;
353
354 return dev->devtype->vdevs[i];
355}
356
Philipp Zabel79924ca2014-07-23 12:28:45 -0300357const char *coda_product_name(int product)
Philipp Zabel927933f2013-09-30 10:34:48 -0300358{
359 static char buf[9];
360
361 switch (product) {
362 case CODA_DX6:
363 return "CodaDx6";
364 case CODA_7541:
365 return "CODA7541";
Philipp Zabel89548442014-07-11 06:36:17 -0300366 case CODA_960:
367 return "CODA960";
Philipp Zabel927933f2013-09-30 10:34:48 -0300368 default:
369 snprintf(buf, sizeof(buf), "(0x%04x)", product);
370 return buf;
371 }
372}
373
Javier Martin186b2502012-07-26 05:53:35 -0300374/*
375 * V4L2 ioctl() operations.
376 */
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300377static int coda_querycap(struct file *file, void *priv,
378 struct v4l2_capability *cap)
Javier Martin186b2502012-07-26 05:53:35 -0300379{
Philipp Zabel927933f2013-09-30 10:34:48 -0300380 struct coda_ctx *ctx = fh_to_ctx(priv);
381
Javier Martin186b2502012-07-26 05:53:35 -0300382 strlcpy(cap->driver, CODA_NAME, sizeof(cap->driver));
Philipp Zabel927933f2013-09-30 10:34:48 -0300383 strlcpy(cap->card, coda_product_name(ctx->dev->devtype->product),
384 sizeof(cap->card));
Philipp Zabeldad0e1c2013-05-21 04:18:22 -0300385 strlcpy(cap->bus_info, "platform:" CODA_NAME, sizeof(cap->bus_info));
Philipp Zabel3898e7a2014-07-18 07:22:37 -0300386 cap->device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING;
Javier Martin186b2502012-07-26 05:53:35 -0300387 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
388
389 return 0;
390}
391
Philipp Zabel22e244b2014-07-18 07:22:43 -0300392static int coda_enum_fmt(struct file *file, void *priv,
393 struct v4l2_fmtdesc *f)
Javier Martin186b2502012-07-26 05:53:35 -0300394{
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300395 struct video_device *vdev = video_devdata(file);
396 const struct coda_video_device *cvd = to_coda_video_device(vdev);
397 const u32 *formats;
398 const char *name;
Philipp Zabel22e244b2014-07-18 07:22:43 -0300399
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300400 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
401 formats = cvd->src_formats;
402 else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
403 formats = cvd->dst_formats;
Philipp Zabel22e244b2014-07-18 07:22:43 -0300404 else
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300405 return -EINVAL;
Javier Martin186b2502012-07-26 05:53:35 -0300406
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300407 if (f->index >= CODA_MAX_FORMATS || formats[f->index] == 0)
408 return -EINVAL;
Javier Martin186b2502012-07-26 05:53:35 -0300409
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300410 name = coda_format_name(formats[f->index]);
411 strlcpy(f->description, name, sizeof(f->description));
412 f->pixelformat = formats[f->index];
413 if (!coda_format_is_yuv(formats[f->index]))
414 f->flags |= V4L2_FMT_FLAG_COMPRESSED;
Javier Martin186b2502012-07-26 05:53:35 -0300415
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300416 return 0;
Javier Martin186b2502012-07-26 05:53:35 -0300417}
418
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300419static int coda_g_fmt(struct file *file, void *priv,
420 struct v4l2_format *f)
Javier Martin186b2502012-07-26 05:53:35 -0300421{
Javier Martin186b2502012-07-26 05:53:35 -0300422 struct coda_q_data *q_data;
423 struct coda_ctx *ctx = fh_to_ctx(priv);
424
Javier Martin186b2502012-07-26 05:53:35 -0300425 q_data = get_q_data(ctx, f->type);
Philipp Zabelb9736292014-07-11 06:36:18 -0300426 if (!q_data)
427 return -EINVAL;
Javier Martin186b2502012-07-26 05:53:35 -0300428
429 f->fmt.pix.field = V4L2_FIELD_NONE;
Philipp Zabelb96904e2013-05-23 10:42:58 -0300430 f->fmt.pix.pixelformat = q_data->fourcc;
Javier Martin186b2502012-07-26 05:53:35 -0300431 f->fmt.pix.width = q_data->width;
432 f->fmt.pix.height = q_data->height;
Philipp Zabel2fd6a372014-07-11 06:36:36 -0300433 f->fmt.pix.bytesperline = q_data->bytesperline;
Javier Martin186b2502012-07-26 05:53:35 -0300434
435 f->fmt.pix.sizeimage = q_data->sizeimage;
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300436 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_JPEG)
437 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
438 else
439 f->fmt.pix.colorspace = ctx->colorspace;
Javier Martin186b2502012-07-26 05:53:35 -0300440
441 return 0;
442}
443
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300444static int coda_try_pixelformat(struct coda_ctx *ctx, struct v4l2_format *f)
445{
446 struct coda_q_data *q_data;
447 const u32 *formats;
448 int i;
449
450 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
451 formats = ctx->cvd->src_formats;
452 else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
453 formats = ctx->cvd->dst_formats;
454 else
455 return -EINVAL;
456
457 for (i = 0; i < CODA_MAX_FORMATS; i++) {
458 if (formats[i] == f->fmt.pix.pixelformat) {
459 f->fmt.pix.pixelformat = formats[i];
460 return 0;
461 }
462 }
463
464 /* Fall back to currently set pixelformat */
465 q_data = get_q_data(ctx, f->type);
466 f->fmt.pix.pixelformat = q_data->fourcc;
Javier Martin186b2502012-07-26 05:53:35 -0300467
468 return 0;
469}
470
Philipp Zabel814c3762014-07-18 07:22:45 -0300471static int coda_try_fmt(struct coda_ctx *ctx, const struct coda_codec *codec,
Philipp Zabel57625592013-09-30 10:34:51 -0300472 struct v4l2_format *f)
Javier Martin186b2502012-07-26 05:53:35 -0300473{
Philipp Zabel57625592013-09-30 10:34:51 -0300474 struct coda_dev *dev = ctx->dev;
Philipp Zabelb96904e2013-05-23 10:42:58 -0300475 unsigned int max_w, max_h;
Javier Martin186b2502012-07-26 05:53:35 -0300476 enum v4l2_field field;
477
478 field = f->fmt.pix.field;
479 if (field == V4L2_FIELD_ANY)
480 field = V4L2_FIELD_NONE;
481 else if (V4L2_FIELD_NONE != field)
482 return -EINVAL;
483
484 /* V4L2 specification suggests the driver corrects the format struct
485 * if any of the dimensions is unsupported */
486 f->fmt.pix.field = field;
487
Philipp Zabel57625592013-09-30 10:34:51 -0300488 coda_get_max_dimensions(dev, codec, &max_w, &max_h);
489 v4l_bound_align_image(&f->fmt.pix.width, MIN_W, max_w, W_ALIGN,
490 &f->fmt.pix.height, MIN_H, max_h, H_ALIGN,
491 S_ALIGN);
Philipp Zabelb96904e2013-05-23 10:42:58 -0300492
Philipp Zabel57625592013-09-30 10:34:51 -0300493 switch (f->fmt.pix.pixelformat) {
494 case V4L2_PIX_FMT_YUV420:
495 case V4L2_PIX_FMT_YVU420:
Philipp Zabel1cb12cf2014-09-29 09:53:47 -0300496 case V4L2_PIX_FMT_NV12:
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300497 /*
498 * Frame stride must be at least multiple of 8,
499 * but multiple of 16 for h.264 or JPEG 4:2:x
500 */
Philipp Zabel451dfe52014-07-11 06:36:39 -0300501 f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 16);
Philipp Zabel47cf0c62013-05-23 10:42:54 -0300502 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline *
Philipp Zabel451d43a2012-07-26 09:18:27 -0300503 f->fmt.pix.height * 3 / 2;
Philipp Zabel57625592013-09-30 10:34:51 -0300504 break;
Philipp Zabel4de69312014-10-02 14:08:26 -0300505 case V4L2_PIX_FMT_YUV422P:
506 f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 16);
507 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline *
508 f->fmt.pix.height * 2;
509 break;
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300510 case V4L2_PIX_FMT_JPEG:
511 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
512 /* fallthrough */
Philipp Zabel57625592013-09-30 10:34:51 -0300513 case V4L2_PIX_FMT_H264:
514 case V4L2_PIX_FMT_MPEG4:
Javier Martin186b2502012-07-26 05:53:35 -0300515 f->fmt.pix.bytesperline = 0;
Philipp Zabeld4c6a412014-10-02 14:08:35 -0300516 /*
517 * This is a rough estimate for sensible compressed buffer
518 * sizes (between 1 and 16 bits per pixel). This could be
519 * improved by better format specific worst case estimates.
520 */
521 f->fmt.pix.sizeimage = round_up(clamp(f->fmt.pix.sizeimage,
522 f->fmt.pix.width * f->fmt.pix.height / 8,
523 f->fmt.pix.width * f->fmt.pix.height * 2),
524 PAGE_SIZE);
Philipp Zabel57625592013-09-30 10:34:51 -0300525 break;
526 default:
527 BUG();
Javier Martin186b2502012-07-26 05:53:35 -0300528 }
529
530 return 0;
531}
532
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300533static int coda_try_fmt_vid_cap(struct file *file, void *priv,
534 struct v4l2_format *f)
Javier Martin186b2502012-07-26 05:53:35 -0300535{
Javier Martin186b2502012-07-26 05:53:35 -0300536 struct coda_ctx *ctx = fh_to_ctx(priv);
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300537 const struct coda_q_data *q_data_src;
538 const struct coda_codec *codec;
Philipp Zabel918c66f2013-06-27 06:59:01 -0300539 struct vb2_queue *src_vq;
540 int ret;
Javier Martin186b2502012-07-26 05:53:35 -0300541
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300542 ret = coda_try_pixelformat(ctx, f);
543 if (ret < 0)
544 return ret;
545
546 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
547
Philipp Zabel918c66f2013-06-27 06:59:01 -0300548 /*
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300549 * If the source format is already fixed, only allow the same output
550 * resolution
Philipp Zabel918c66f2013-06-27 06:59:01 -0300551 */
Philipp Zabel14604e32014-07-11 06:36:22 -0300552 src_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
Philipp Zabel918c66f2013-06-27 06:59:01 -0300553 if (vb2_is_streaming(src_vq)) {
Philipp Zabel91b5841e2014-07-18 07:22:41 -0300554 f->fmt.pix.width = q_data_src->width;
555 f->fmt.pix.height = q_data_src->height;
Philipp Zabel918c66f2013-06-27 06:59:01 -0300556 }
Javier Martin186b2502012-07-26 05:53:35 -0300557
558 f->fmt.pix.colorspace = ctx->colorspace;
559
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300560 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
561 codec = coda_find_codec(ctx->dev, q_data_src->fourcc,
562 f->fmt.pix.pixelformat);
563 if (!codec)
564 return -EINVAL;
565
Philipp Zabel57625592013-09-30 10:34:51 -0300566 ret = coda_try_fmt(ctx, codec, f);
Philipp Zabel918c66f2013-06-27 06:59:01 -0300567 if (ret < 0)
568 return ret;
569
570 /* The h.264 decoder only returns complete 16x16 macroblocks */
571 if (codec && codec->src_fourcc == V4L2_PIX_FMT_H264) {
Philipp Zabel1b0ed7b2014-07-11 06:36:37 -0300572 f->fmt.pix.width = f->fmt.pix.width;
Philipp Zabel918c66f2013-06-27 06:59:01 -0300573 f->fmt.pix.height = round_up(f->fmt.pix.height, 16);
Philipp Zabel1b0ed7b2014-07-11 06:36:37 -0300574 f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 16);
Philipp Zabel918c66f2013-06-27 06:59:01 -0300575 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline *
576 f->fmt.pix.height * 3 / 2;
577 }
578
579 return 0;
Javier Martin186b2502012-07-26 05:53:35 -0300580}
581
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300582static int coda_try_fmt_vid_out(struct file *file, void *priv,
583 struct v4l2_format *f)
Javier Martin186b2502012-07-26 05:53:35 -0300584{
585 struct coda_ctx *ctx = fh_to_ctx(priv);
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300586 struct coda_dev *dev = ctx->dev;
587 const struct coda_q_data *q_data_dst;
588 const struct coda_codec *codec;
589 int ret;
Javier Martin186b2502012-07-26 05:53:35 -0300590
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300591 ret = coda_try_pixelformat(ctx, f);
592 if (ret < 0)
593 return ret;
Javier Martin186b2502012-07-26 05:53:35 -0300594
Philipp Zabel5f9826e2015-01-23 13:51:21 -0300595 switch (f->fmt.pix.colorspace) {
596 case V4L2_COLORSPACE_REC709:
597 case V4L2_COLORSPACE_JPEG:
598 break;
599 default:
Philipp Zabelcb1d3a32014-10-02 14:08:31 -0300600 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_JPEG)
601 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
602 else
603 f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709;
Javier Martin186b2502012-07-26 05:53:35 -0300604 }
605
Philipp Zabel2c11d1b2014-10-02 14:08:28 -0300606 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
607 codec = coda_find_codec(dev, f->fmt.pix.pixelformat, q_data_dst->fourcc);
Javier Martin186b2502012-07-26 05:53:35 -0300608
609 return coda_try_fmt(ctx, codec, f);
610}
611
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300612static int coda_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f)
Javier Martin186b2502012-07-26 05:53:35 -0300613{
614 struct coda_q_data *q_data;
615 struct vb2_queue *vq;
Javier Martin186b2502012-07-26 05:53:35 -0300616
Philipp Zabel14604e32014-07-11 06:36:22 -0300617 vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
Javier Martin186b2502012-07-26 05:53:35 -0300618 if (!vq)
619 return -EINVAL;
620
621 q_data = get_q_data(ctx, f->type);
622 if (!q_data)
623 return -EINVAL;
624
625 if (vb2_is_busy(vq)) {
626 v4l2_err(&ctx->dev->v4l2_dev, "%s queue busy\n", __func__);
627 return -EBUSY;
628 }
629
Philipp Zabelb96904e2013-05-23 10:42:58 -0300630 q_data->fourcc = f->fmt.pix.pixelformat;
Javier Martin186b2502012-07-26 05:53:35 -0300631 q_data->width = f->fmt.pix.width;
632 q_data->height = f->fmt.pix.height;
Philipp Zabel2fd6a372014-07-11 06:36:36 -0300633 q_data->bytesperline = f->fmt.pix.bytesperline;
Philipp Zabel451d43a2012-07-26 09:18:27 -0300634 q_data->sizeimage = f->fmt.pix.sizeimage;
Philipp Zabel52c41672014-07-11 06:36:19 -0300635 q_data->rect.left = 0;
636 q_data->rect.top = 0;
637 q_data->rect.width = f->fmt.pix.width;
638 q_data->rect.height = f->fmt.pix.height;
Javier Martin186b2502012-07-26 05:53:35 -0300639
640 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
641 "Setting format for type %d, wxh: %dx%d, fmt: %d\n",
Philipp Zabelb96904e2013-05-23 10:42:58 -0300642 f->type, q_data->width, q_data->height, q_data->fourcc);
Javier Martin186b2502012-07-26 05:53:35 -0300643
644 return 0;
645}
646
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300647static int coda_s_fmt_vid_cap(struct file *file, void *priv,
648 struct v4l2_format *f)
Javier Martin186b2502012-07-26 05:53:35 -0300649{
Philipp Zabelb96904e2013-05-23 10:42:58 -0300650 struct coda_ctx *ctx = fh_to_ctx(priv);
Javier Martin186b2502012-07-26 05:53:35 -0300651 int ret;
652
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300653 ret = coda_try_fmt_vid_cap(file, priv, f);
Javier Martin186b2502012-07-26 05:53:35 -0300654 if (ret)
655 return ret;
656
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300657 return coda_s_fmt(ctx, f);
Javier Martin186b2502012-07-26 05:53:35 -0300658}
659
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300660static int coda_s_fmt_vid_out(struct file *file, void *priv,
661 struct v4l2_format *f)
Javier Martin186b2502012-07-26 05:53:35 -0300662{
663 struct coda_ctx *ctx = fh_to_ctx(priv);
Philipp Zabelf95a6ce2014-08-05 14:00:19 -0300664 struct v4l2_format f_cap;
Javier Martin186b2502012-07-26 05:53:35 -0300665 int ret;
666
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300667 ret = coda_try_fmt_vid_out(file, priv, f);
Javier Martin186b2502012-07-26 05:53:35 -0300668 if (ret)
669 return ret;
670
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300671 ret = coda_s_fmt(ctx, f);
Javier Martin186b2502012-07-26 05:53:35 -0300672 if (ret)
Philipp Zabel2dc546d2014-08-05 14:00:18 -0300673 return ret;
674
675 ctx->colorspace = f->fmt.pix.colorspace;
Javier Martin186b2502012-07-26 05:53:35 -0300676
Philipp Zabel1c2f6a92015-01-23 13:51:22 -0300677 memset(&f_cap, 0, sizeof(f_cap));
Philipp Zabelf95a6ce2014-08-05 14:00:19 -0300678 f_cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
679 coda_g_fmt(file, priv, &f_cap);
680 f_cap.fmt.pix.width = f->fmt.pix.width;
681 f_cap.fmt.pix.height = f->fmt.pix.height;
682
683 ret = coda_try_fmt_vid_cap(file, priv, &f_cap);
684 if (ret)
685 return ret;
686
687 return coda_s_fmt(ctx, &f_cap);
Javier Martin186b2502012-07-26 05:53:35 -0300688}
689
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300690static int coda_qbuf(struct file *file, void *priv,
691 struct v4l2_buffer *buf)
Javier Martin186b2502012-07-26 05:53:35 -0300692{
693 struct coda_ctx *ctx = fh_to_ctx(priv);
694
Philipp Zabel14604e32014-07-11 06:36:22 -0300695 return v4l2_m2m_qbuf(file, ctx->fh.m2m_ctx, buf);
Javier Martin186b2502012-07-26 05:53:35 -0300696}
697
Philipp Zabel918c66f2013-06-27 06:59:01 -0300698static bool coda_buf_is_end_of_stream(struct coda_ctx *ctx,
699 struct v4l2_buffer *buf)
700{
701 struct vb2_queue *src_vq;
702
Philipp Zabel14604e32014-07-11 06:36:22 -0300703 src_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
Philipp Zabel918c66f2013-06-27 06:59:01 -0300704
705 return ((ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) &&
706 (buf->sequence == (ctx->qsequence - 1)));
707}
708
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300709static int coda_dqbuf(struct file *file, void *priv,
710 struct v4l2_buffer *buf)
Javier Martin186b2502012-07-26 05:53:35 -0300711{
712 struct coda_ctx *ctx = fh_to_ctx(priv);
Philipp Zabel918c66f2013-06-27 06:59:01 -0300713 int ret;
Javier Martin186b2502012-07-26 05:53:35 -0300714
Philipp Zabel14604e32014-07-11 06:36:22 -0300715 ret = v4l2_m2m_dqbuf(file, ctx->fh.m2m_ctx, buf);
Philipp Zabel918c66f2013-06-27 06:59:01 -0300716
717 /* If this is the last capture buffer, emit an end-of-stream event */
718 if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE &&
719 coda_buf_is_end_of_stream(ctx, buf)) {
720 const struct v4l2_event eos_event = {
721 .type = V4L2_EVENT_EOS
722 };
723
724 v4l2_event_queue_fh(&ctx->fh, &eos_event);
725 }
726
727 return ret;
Javier Martin186b2502012-07-26 05:53:35 -0300728}
729
Philipp Zabel52c41672014-07-11 06:36:19 -0300730static int coda_g_selection(struct file *file, void *fh,
731 struct v4l2_selection *s)
732{
733 struct coda_ctx *ctx = fh_to_ctx(fh);
734 struct coda_q_data *q_data;
735 struct v4l2_rect r, *rsel;
736
737 q_data = get_q_data(ctx, s->type);
738 if (!q_data)
739 return -EINVAL;
740
741 r.left = 0;
742 r.top = 0;
743 r.width = q_data->width;
744 r.height = q_data->height;
745 rsel = &q_data->rect;
746
747 switch (s->target) {
748 case V4L2_SEL_TGT_CROP_DEFAULT:
749 case V4L2_SEL_TGT_CROP_BOUNDS:
750 rsel = &r;
751 /* fallthrough */
752 case V4L2_SEL_TGT_CROP:
753 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
754 return -EINVAL;
755 break;
756 case V4L2_SEL_TGT_COMPOSE_BOUNDS:
757 case V4L2_SEL_TGT_COMPOSE_PADDED:
758 rsel = &r;
759 /* fallthrough */
760 case V4L2_SEL_TGT_COMPOSE:
761 case V4L2_SEL_TGT_COMPOSE_DEFAULT:
762 if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
763 return -EINVAL;
764 break;
765 default:
766 return -EINVAL;
767 }
768
769 s->r = *rsel;
770
771 return 0;
772}
773
Philipp Zabel64ba40a2013-09-30 10:34:52 -0300774static int coda_try_decoder_cmd(struct file *file, void *fh,
775 struct v4l2_decoder_cmd *dc)
Philipp Zabel918c66f2013-06-27 06:59:01 -0300776{
Philipp Zabel918c66f2013-06-27 06:59:01 -0300777 if (dc->cmd != V4L2_DEC_CMD_STOP)
778 return -EINVAL;
779
Philipp Zabel64ba40a2013-09-30 10:34:52 -0300780 if (dc->flags & V4L2_DEC_CMD_STOP_TO_BLACK)
Philipp Zabel918c66f2013-06-27 06:59:01 -0300781 return -EINVAL;
782
Philipp Zabel64ba40a2013-09-30 10:34:52 -0300783 if (!(dc->flags & V4L2_DEC_CMD_STOP_IMMEDIATELY) && (dc->stop.pts != 0))
Philipp Zabel918c66f2013-06-27 06:59:01 -0300784 return -EINVAL;
785
Philipp Zabel64ba40a2013-09-30 10:34:52 -0300786 return 0;
787}
788
789static int coda_decoder_cmd(struct file *file, void *fh,
790 struct v4l2_decoder_cmd *dc)
791{
792 struct coda_ctx *ctx = fh_to_ctx(fh);
793 int ret;
794
795 ret = coda_try_decoder_cmd(file, fh, dc);
796 if (ret < 0)
797 return ret;
798
799 /* Ignore decoder stop command silently in encoder context */
Philipp Zabel918c66f2013-06-27 06:59:01 -0300800 if (ctx->inst_type != CODA_INST_DECODER)
Philipp Zabel64ba40a2013-09-30 10:34:52 -0300801 return 0;
Philipp Zabel918c66f2013-06-27 06:59:01 -0300802
Philipp Zabel347bb7f2014-07-23 12:28:42 -0300803 /* Set the stream-end flag on this context */
804 coda_bit_stream_end_flag(ctx);
Philipp Zabel84e23652014-07-11 06:36:34 -0300805 ctx->hold = false;
Michael Olbrichf3497da2014-07-11 06:36:30 -0300806 v4l2_m2m_try_schedule(ctx->fh.m2m_ctx);
Philipp Zabel89548442014-07-11 06:36:17 -0300807
Philipp Zabel918c66f2013-06-27 06:59:01 -0300808 return 0;
809}
810
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300811static int coda_subscribe_event(struct v4l2_fh *fh,
812 const struct v4l2_event_subscription *sub)
Philipp Zabel918c66f2013-06-27 06:59:01 -0300813{
814 switch (sub->type) {
815 case V4L2_EVENT_EOS:
816 return v4l2_event_subscribe(fh, sub, 0, NULL);
817 default:
818 return v4l2_ctrl_subscribe_event(fh, sub);
819 }
Javier Martin186b2502012-07-26 05:53:35 -0300820}
821
822static const struct v4l2_ioctl_ops coda_ioctl_ops = {
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300823 .vidioc_querycap = coda_querycap,
Javier Martin186b2502012-07-26 05:53:35 -0300824
Philipp Zabel22e244b2014-07-18 07:22:43 -0300825 .vidioc_enum_fmt_vid_cap = coda_enum_fmt,
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300826 .vidioc_g_fmt_vid_cap = coda_g_fmt,
827 .vidioc_try_fmt_vid_cap = coda_try_fmt_vid_cap,
828 .vidioc_s_fmt_vid_cap = coda_s_fmt_vid_cap,
Javier Martin186b2502012-07-26 05:53:35 -0300829
Philipp Zabel22e244b2014-07-18 07:22:43 -0300830 .vidioc_enum_fmt_vid_out = coda_enum_fmt,
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300831 .vidioc_g_fmt_vid_out = coda_g_fmt,
832 .vidioc_try_fmt_vid_out = coda_try_fmt_vid_out,
833 .vidioc_s_fmt_vid_out = coda_s_fmt_vid_out,
Javier Martin186b2502012-07-26 05:53:35 -0300834
Philipp Zabel152ea1c2014-07-11 06:36:21 -0300835 .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs,
836 .vidioc_querybuf = v4l2_m2m_ioctl_querybuf,
Javier Martin186b2502012-07-26 05:53:35 -0300837
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300838 .vidioc_qbuf = coda_qbuf,
Philipp Zabel152ea1c2014-07-11 06:36:21 -0300839 .vidioc_expbuf = v4l2_m2m_ioctl_expbuf,
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300840 .vidioc_dqbuf = coda_dqbuf,
Philipp Zabel152ea1c2014-07-11 06:36:21 -0300841 .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs,
Javier Martin186b2502012-07-26 05:53:35 -0300842
Philipp Zabel152ea1c2014-07-11 06:36:21 -0300843 .vidioc_streamon = v4l2_m2m_ioctl_streamon,
844 .vidioc_streamoff = v4l2_m2m_ioctl_streamoff,
Philipp Zabel918c66f2013-06-27 06:59:01 -0300845
Philipp Zabel52c41672014-07-11 06:36:19 -0300846 .vidioc_g_selection = coda_g_selection,
847
Philipp Zabel64ba40a2013-09-30 10:34:52 -0300848 .vidioc_try_decoder_cmd = coda_try_decoder_cmd,
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300849 .vidioc_decoder_cmd = coda_decoder_cmd,
Philipp Zabel918c66f2013-06-27 06:59:01 -0300850
Philipp Zabel2e9e4f12013-09-30 10:34:50 -0300851 .vidioc_subscribe_event = coda_subscribe_event,
Philipp Zabel918c66f2013-06-27 06:59:01 -0300852 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
Javier Martin186b2502012-07-26 05:53:35 -0300853};
854
Philipp Zabel79924ca2014-07-23 12:28:45 -0300855void coda_set_gdi_regs(struct coda_ctx *ctx)
Philipp Zabel89548442014-07-11 06:36:17 -0300856{
857 struct gdi_tiled_map *tiled_map = &ctx->tiled_map;
858 struct coda_dev *dev = ctx->dev;
859 int i;
860
861 for (i = 0; i < 16; i++)
862 coda_write(dev, tiled_map->xy2ca_map[i],
863 CODA9_GDI_XY2_CAS_0 + 4 * i);
864 for (i = 0; i < 4; i++)
865 coda_write(dev, tiled_map->xy2ba_map[i],
866 CODA9_GDI_XY2_BA_0 + 4 * i);
867 for (i = 0; i < 16; i++)
868 coda_write(dev, tiled_map->xy2ra_map[i],
869 CODA9_GDI_XY2_RAS_0 + 4 * i);
870 coda_write(dev, tiled_map->xy2rbc_config, CODA9_GDI_XY2_RBC_CONFIG);
871 for (i = 0; i < 32; i++)
872 coda_write(dev, tiled_map->rbc2axi_map[i],
873 CODA9_GDI_RBC2_AXI_0 + 4 * i);
874}
875
Javier Martin186b2502012-07-26 05:53:35 -0300876/*
877 * Mem-to-mem operations.
878 */
Philipp Zabel477c1cf2013-06-21 03:55:33 -0300879
880static void coda_device_run(void *m2m_priv)
881{
882 struct coda_ctx *ctx = m2m_priv;
883 struct coda_dev *dev = ctx->dev;
Philipp Zabel32b6f202014-07-11 06:36:20 -0300884
885 queue_work(dev->workqueue, &ctx->pic_run_work);
886}
887
Philipp Zabel32b6f202014-07-11 06:36:20 -0300888static void coda_pic_run_work(struct work_struct *work)
889{
890 struct coda_ctx *ctx = container_of(work, struct coda_ctx, pic_run_work);
891 struct coda_dev *dev = ctx->dev;
Philipp Zabel918c66f2013-06-27 06:59:01 -0300892 int ret;
893
894 mutex_lock(&ctx->buffer_mutex);
Philipp Zabel477c1cf2013-06-21 03:55:33 -0300895 mutex_lock(&dev->coda_mutex);
896
Philipp Zabela1192a12014-07-23 12:28:40 -0300897 ret = ctx->ops->prepare_run(ctx);
898 if (ret < 0 && ctx->inst_type == CODA_INST_DECODER) {
899 mutex_unlock(&dev->coda_mutex);
900 mutex_unlock(&ctx->buffer_mutex);
901 /* job_finish scheduled by prepare_decode */
902 return;
Philipp Zabel10436672012-07-02 09:03:55 -0300903 }
904
Philipp Zabelf23797b2014-08-06 08:02:23 -0300905 if (!wait_for_completion_timeout(&ctx->completion,
906 msecs_to_jiffies(1000))) {
Philipp Zabel32b6f202014-07-11 06:36:20 -0300907 dev_err(&dev->plat_dev->dev, "CODA PIC_RUN timeout\n");
Philipp Zabel84e23652014-07-11 06:36:34 -0300908
909 ctx->hold = true;
Philipp Zabel8f452842014-07-11 06:36:35 -0300910
911 coda_hw_reset(ctx);
Philipp Zabel32b6f202014-07-11 06:36:20 -0300912 } else if (!ctx->aborting) {
Philipp Zabela1192a12014-07-23 12:28:40 -0300913 ctx->ops->finish_run(ctx);
Philipp Zabel32b6f202014-07-11 06:36:20 -0300914 }
915
916 if (ctx->aborting || (!ctx->streamon_cap && !ctx->streamon_out))
917 queue_work(dev->workqueue, &ctx->seq_end_work);
918
919 mutex_unlock(&dev->coda_mutex);
920 mutex_unlock(&ctx->buffer_mutex);
921
Philipp Zabel14604e32014-07-11 06:36:22 -0300922 v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx);
Javier Martin186b2502012-07-26 05:53:35 -0300923}
924
925static int coda_job_ready(void *m2m_priv)
926{
927 struct coda_ctx *ctx = m2m_priv;
928
929 /*
930 * For both 'P' and 'key' frame cases 1 picture
Philipp Zabel9082a7c2013-06-21 03:55:31 -0300931 * and 1 frame are needed. In the decoder case,
932 * the compressed frame can be in the bitstream.
Javier Martin186b2502012-07-26 05:53:35 -0300933 */
Philipp Zabel14604e32014-07-11 06:36:22 -0300934 if (!v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) &&
Philipp Zabel9082a7c2013-06-21 03:55:31 -0300935 ctx->inst_type != CODA_INST_DECODER) {
Javier Martin186b2502012-07-26 05:53:35 -0300936 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
937 "not ready: not enough video buffers.\n");
938 return 0;
939 }
940
Philipp Zabel14604e32014-07-11 06:36:22 -0300941 if (!v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx)) {
Philipp Zabel9082a7c2013-06-21 03:55:31 -0300942 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
943 "not ready: not enough video capture buffers.\n");
944 return 0;
945 }
946
Philipp Zabelf77fd8a2015-01-23 13:51:20 -0300947 if (ctx->inst_type == CODA_INST_DECODER) {
948 struct list_head *meta;
949 bool stream_end;
950 int num_metas;
951 int src_bufs;
952
953 if (ctx->hold && !v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx)) {
954 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
955 "%d: not ready: on hold for more buffers.\n",
956 ctx->idx);
957 return 0;
958 }
959
960 stream_end = ctx->bit_stream_param &
961 CODA_BIT_STREAM_END_FLAG;
962
963 num_metas = 0;
964 list_for_each(meta, &ctx->buffer_meta_list)
965 num_metas++;
966
967 src_bufs = v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx);
968
969 if (!stream_end && (num_metas + src_bufs) < 2) {
970 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
971 "%d: not ready: need 2 buffers available (%d, %d)\n",
972 ctx->idx, num_metas, src_bufs);
973 return 0;
974 }
975
976
977 if (!v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) &&
978 !stream_end && (coda_get_bitstream_payload(ctx) < 512)) {
979 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
980 "%d: not ready: not enough bitstream data (%d).\n",
981 ctx->idx, coda_get_bitstream_payload(ctx));
982 return 0;
983 }
Philipp Zabel918c66f2013-06-27 06:59:01 -0300984 }
985
Philipp Zabel3e748262013-05-23 10:43:01 -0300986 if (ctx->aborting) {
987 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
988 "not ready: aborting\n");
989 return 0;
990 }
991
Javier Martin186b2502012-07-26 05:53:35 -0300992 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
993 "job ready\n");
994 return 1;
995}
996
997static void coda_job_abort(void *priv)
998{
999 struct coda_ctx *ctx = priv;
Javier Martin186b2502012-07-26 05:53:35 -03001000
1001 ctx->aborting = 1;
1002
1003 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1004 "Aborting task\n");
Javier Martin186b2502012-07-26 05:53:35 -03001005}
1006
1007static void coda_lock(void *m2m_priv)
1008{
1009 struct coda_ctx *ctx = m2m_priv;
1010 struct coda_dev *pcdev = ctx->dev;
Philipp Zabelf23797b2014-08-06 08:02:23 -03001011
Javier Martin186b2502012-07-26 05:53:35 -03001012 mutex_lock(&pcdev->dev_mutex);
1013}
1014
1015static void coda_unlock(void *m2m_priv)
1016{
1017 struct coda_ctx *ctx = m2m_priv;
1018 struct coda_dev *pcdev = ctx->dev;
Philipp Zabelf23797b2014-08-06 08:02:23 -03001019
Javier Martin186b2502012-07-26 05:53:35 -03001020 mutex_unlock(&pcdev->dev_mutex);
1021}
1022
Philipp Zabel814c3762014-07-18 07:22:45 -03001023static const struct v4l2_m2m_ops coda_m2m_ops = {
Javier Martin186b2502012-07-26 05:53:35 -03001024 .device_run = coda_device_run,
1025 .job_ready = coda_job_ready,
1026 .job_abort = coda_job_abort,
1027 .lock = coda_lock,
1028 .unlock = coda_unlock,
1029};
1030
Philipp Zabel89548442014-07-11 06:36:17 -03001031static void coda_set_tiled_map_type(struct coda_ctx *ctx, int tiled_map_type)
1032{
1033 struct gdi_tiled_map *tiled_map = &ctx->tiled_map;
1034 int luma_map, chro_map, i;
1035
1036 memset(tiled_map, 0, sizeof(*tiled_map));
1037
1038 luma_map = 64;
1039 chro_map = 64;
1040 tiled_map->map_type = tiled_map_type;
1041 for (i = 0; i < 16; i++)
1042 tiled_map->xy2ca_map[i] = luma_map << 8 | chro_map;
1043 for (i = 0; i < 4; i++)
1044 tiled_map->xy2ba_map[i] = luma_map << 8 | chro_map;
1045 for (i = 0; i < 16; i++)
1046 tiled_map->xy2ra_map[i] = luma_map << 8 | chro_map;
1047
1048 if (tiled_map_type == GDI_LINEAR_FRAME_MAP) {
1049 tiled_map->xy2rbc_config = 0;
1050 } else {
1051 dev_err(&ctx->dev->plat_dev->dev, "invalid map type: %d\n",
1052 tiled_map_type);
1053 return;
1054 }
1055}
1056
Javier Martin186b2502012-07-26 05:53:35 -03001057static void set_default_params(struct coda_ctx *ctx)
1058{
Philipp Zabeld4c6a412014-10-02 14:08:35 -03001059 unsigned int max_w, max_h, size;
Philipp Zabelb96904e2013-05-23 10:42:58 -03001060
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001061 ctx->codec = coda_find_codec(ctx->dev, ctx->cvd->src_formats[0],
1062 ctx->cvd->dst_formats[0]);
Philipp Zabeld4c6a412014-10-02 14:08:35 -03001063 max_w = min(ctx->codec->max_w, 1920U);
1064 max_h = min(ctx->codec->max_h, 1088U);
1065 size = max_w * max_h * 3 / 2;
Javier Martin186b2502012-07-26 05:53:35 -03001066
Philipp Zabel121cacf2014-07-18 07:22:42 -03001067 ctx->params.codec_mode = ctx->codec->mode;
Javier Martin186b2502012-07-26 05:53:35 -03001068 ctx->colorspace = V4L2_COLORSPACE_REC709;
1069 ctx->params.framerate = 30;
Javier Martin186b2502012-07-26 05:53:35 -03001070
1071 /* Default formats for output and input queues */
Philipp Zabelb96904e2013-05-23 10:42:58 -03001072 ctx->q_data[V4L2_M2M_SRC].fourcc = ctx->codec->src_fourcc;
1073 ctx->q_data[V4L2_M2M_DST].fourcc = ctx->codec->dst_fourcc;
1074 ctx->q_data[V4L2_M2M_SRC].width = max_w;
1075 ctx->q_data[V4L2_M2M_SRC].height = max_h;
Philipp Zabelb96904e2013-05-23 10:42:58 -03001076 ctx->q_data[V4L2_M2M_DST].width = max_w;
1077 ctx->q_data[V4L2_M2M_DST].height = max_h;
Philipp Zabel121cacf2014-07-18 07:22:42 -03001078 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_YUV420) {
1079 ctx->q_data[V4L2_M2M_SRC].bytesperline = max_w;
Philipp Zabeld4c6a412014-10-02 14:08:35 -03001080 ctx->q_data[V4L2_M2M_SRC].sizeimage = size;
Philipp Zabel121cacf2014-07-18 07:22:42 -03001081 ctx->q_data[V4L2_M2M_DST].bytesperline = 0;
Philipp Zabeld4c6a412014-10-02 14:08:35 -03001082 ctx->q_data[V4L2_M2M_DST].sizeimage = round_up(size, PAGE_SIZE);
Philipp Zabel121cacf2014-07-18 07:22:42 -03001083 } else {
1084 ctx->q_data[V4L2_M2M_SRC].bytesperline = 0;
Philipp Zabeld4c6a412014-10-02 14:08:35 -03001085 ctx->q_data[V4L2_M2M_SRC].sizeimage = round_up(size, PAGE_SIZE);
Philipp Zabel121cacf2014-07-18 07:22:42 -03001086 ctx->q_data[V4L2_M2M_DST].bytesperline = max_w;
Philipp Zabeld4c6a412014-10-02 14:08:35 -03001087 ctx->q_data[V4L2_M2M_DST].sizeimage = size;
Philipp Zabel121cacf2014-07-18 07:22:42 -03001088 }
Philipp Zabel52c41672014-07-11 06:36:19 -03001089 ctx->q_data[V4L2_M2M_SRC].rect.width = max_w;
1090 ctx->q_data[V4L2_M2M_SRC].rect.height = max_h;
1091 ctx->q_data[V4L2_M2M_DST].rect.width = max_w;
1092 ctx->q_data[V4L2_M2M_DST].rect.height = max_h;
Philipp Zabel89548442014-07-11 06:36:17 -03001093
1094 if (ctx->dev->devtype->product == CODA_960)
1095 coda_set_tiled_map_type(ctx, GDI_LINEAR_FRAME_MAP);
Javier Martin186b2502012-07-26 05:53:35 -03001096}
1097
1098/*
1099 * Queue operations
1100 */
1101static int coda_queue_setup(struct vb2_queue *vq,
1102 const struct v4l2_format *fmt,
1103 unsigned int *nbuffers, unsigned int *nplanes,
1104 unsigned int sizes[], void *alloc_ctxs[])
1105{
1106 struct coda_ctx *ctx = vb2_get_drv_priv(vq);
Philipp Zabele34db062012-08-29 08:22:00 -03001107 struct coda_q_data *q_data;
Javier Martin186b2502012-07-26 05:53:35 -03001108 unsigned int size;
1109
Philipp Zabele34db062012-08-29 08:22:00 -03001110 q_data = get_q_data(ctx, vq->type);
1111 size = q_data->sizeimage;
Javier Martin186b2502012-07-26 05:53:35 -03001112
1113 *nplanes = 1;
1114 sizes[0] = size;
1115
1116 alloc_ctxs[0] = ctx->dev->alloc_ctx;
1117
1118 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1119 "get %d buffer(s) of size %d each.\n", *nbuffers, size);
1120
1121 return 0;
1122}
1123
1124static int coda_buf_prepare(struct vb2_buffer *vb)
1125{
1126 struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
1127 struct coda_q_data *q_data;
1128
1129 q_data = get_q_data(ctx, vb->vb2_queue->type);
1130
1131 if (vb2_plane_size(vb, 0) < q_data->sizeimage) {
1132 v4l2_warn(&ctx->dev->v4l2_dev,
1133 "%s data will not fit into plane (%lu < %lu)\n",
1134 __func__, vb2_plane_size(vb, 0),
1135 (long)q_data->sizeimage);
1136 return -EINVAL;
1137 }
1138
Javier Martin186b2502012-07-26 05:53:35 -03001139 return 0;
1140}
1141
1142static void coda_buf_queue(struct vb2_buffer *vb)
1143{
1144 struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001145 struct coda_q_data *q_data;
1146
1147 q_data = get_q_data(ctx, vb->vb2_queue->type);
1148
1149 /*
1150 * In the decoder case, immediately try to copy the buffer into the
1151 * bitstream ringbuffer and mark it as ready to be dequeued.
1152 */
Philipp Zabelcb1d3a32014-10-02 14:08:31 -03001153 if (ctx->inst_type == CODA_INST_DECODER &&
Philipp Zabel918c66f2013-06-27 06:59:01 -03001154 vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1155 /*
Jonathan McCrohan39c1cb22013-10-20 21:34:01 -03001156 * For backwards compatibility, queuing an empty buffer marks
Philipp Zabel918c66f2013-06-27 06:59:01 -03001157 * the stream end
1158 */
Philipp Zabel347bb7f2014-07-23 12:28:42 -03001159 if (vb2_get_plane_payload(vb, 0) == 0)
1160 coda_bit_stream_end_flag(ctx);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001161 mutex_lock(&ctx->bitstream_mutex);
Philipp Zabel14604e32014-07-11 06:36:22 -03001162 v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
Michael Olbricheabed932014-07-18 07:22:40 -03001163 if (vb2_is_streaming(vb->vb2_queue))
1164 coda_fill_bitstream(ctx);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001165 mutex_unlock(&ctx->bitstream_mutex);
1166 } else {
Philipp Zabel14604e32014-07-11 06:36:22 -03001167 v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001168 }
Javier Martin186b2502012-07-26 05:53:35 -03001169}
1170
Philipp Zabel79924ca2014-07-23 12:28:45 -03001171int coda_alloc_aux_buf(struct coda_dev *dev, struct coda_aux_buf *buf,
1172 size_t size, const char *name, struct dentry *parent)
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001173{
1174 buf->vaddr = dma_alloc_coherent(&dev->plat_dev->dev, size, &buf->paddr,
1175 GFP_KERNEL);
Philipp Zabel68fc31c2014-08-05 14:00:16 -03001176 if (!buf->vaddr) {
1177 v4l2_err(&dev->v4l2_dev,
1178 "Failed to allocate %s buffer of size %u\n",
1179 name, size);
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001180 return -ENOMEM;
Philipp Zabel68fc31c2014-08-05 14:00:16 -03001181 }
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001182
1183 buf->size = size;
1184
Philipp Zabelf61c0b12014-07-11 06:36:40 -03001185 if (name && parent) {
1186 buf->blob.data = buf->vaddr;
1187 buf->blob.size = size;
Philipp Zabelf23797b2014-08-06 08:02:23 -03001188 buf->dentry = debugfs_create_blob(name, 0644, parent,
1189 &buf->blob);
Philipp Zabelf61c0b12014-07-11 06:36:40 -03001190 if (!buf->dentry)
1191 dev_warn(&dev->plat_dev->dev,
1192 "failed to create debugfs entry %s\n", name);
1193 }
1194
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001195 return 0;
1196}
1197
Philipp Zabel79924ca2014-07-23 12:28:45 -03001198void coda_free_aux_buf(struct coda_dev *dev,
1199 struct coda_aux_buf *buf)
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001200{
1201 if (buf->vaddr) {
1202 dma_free_coherent(&dev->plat_dev->dev, buf->size,
1203 buf->vaddr, buf->paddr);
1204 buf->vaddr = NULL;
1205 buf->size = 0;
1206 }
Philipp Zabelf61c0b12014-07-11 06:36:40 -03001207 debugfs_remove(buf->dentry);
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001208}
1209
Javier Martin186b2502012-07-26 05:53:35 -03001210static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
1211{
1212 struct coda_ctx *ctx = vb2_get_drv_priv(q);
1213 struct v4l2_device *v4l2_dev = &ctx->dev->v4l2_dev;
Javier Martin186b2502012-07-26 05:53:35 -03001214 struct coda_q_data *q_data_src, *q_data_dst;
Philipp Zabelb9063522014-08-05 14:00:10 -03001215 struct vb2_buffer *buf;
Philipp Zabeld35167a2013-05-23 10:42:59 -03001216 int ret = 0;
Javier Martin186b2502012-07-26 05:53:35 -03001217
Philipp Zabelb96904e2013-05-23 10:42:58 -03001218 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001219 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
Philipp Zabelcb1d3a32014-10-02 14:08:31 -03001220 if (q_data_src->fourcc == V4L2_PIX_FMT_H264 ||
1221 (q_data_src->fourcc == V4L2_PIX_FMT_JPEG &&
1222 ctx->dev->devtype->product == CODA_7541)) {
Michael Olbricheabed932014-07-18 07:22:40 -03001223 /* copy the buffers that where queued before streamon */
1224 mutex_lock(&ctx->bitstream_mutex);
1225 coda_fill_bitstream(ctx);
1226 mutex_unlock(&ctx->bitstream_mutex);
1227
Philipp Zabelb9063522014-08-05 14:00:10 -03001228 if (coda_get_bitstream_payload(ctx) < 512) {
1229 ret = -EINVAL;
1230 goto err;
1231 }
Philipp Zabel918c66f2013-06-27 06:59:01 -03001232 } else {
Philipp Zabelb9063522014-08-05 14:00:10 -03001233 if (count < 1) {
1234 ret = -EINVAL;
1235 goto err;
1236 }
Philipp Zabel918c66f2013-06-27 06:59:01 -03001237 }
1238
1239 ctx->streamon_out = 1;
Philipp Zabel918c66f2013-06-27 06:59:01 -03001240 } else {
Philipp Zabelb9063522014-08-05 14:00:10 -03001241 if (count < 1) {
1242 ret = -EINVAL;
1243 goto err;
1244 }
Philipp Zabel918c66f2013-06-27 06:59:01 -03001245
1246 ctx->streamon_cap = 1;
Philipp Zabelb96904e2013-05-23 10:42:58 -03001247 }
Javier Martin186b2502012-07-26 05:53:35 -03001248
Philipp Zabelb96904e2013-05-23 10:42:58 -03001249 /* Don't start the coda unless both queues are on */
1250 if (!(ctx->streamon_out & ctx->streamon_cap))
1251 return 0;
Javier Martin186b2502012-07-26 05:53:35 -03001252
Philipp Zabelcb1d3a32014-10-02 14:08:31 -03001253 /* Allow BIT decoder device_run with no new buffers queued */
Philipp Zabeleb107512013-09-30 10:34:45 -03001254 if (ctx->inst_type == CODA_INST_DECODER)
Philipp Zabel14604e32014-07-11 06:36:22 -03001255 v4l2_m2m_set_src_buffered(ctx->fh.m2m_ctx, true);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001256
Philipp Zabelb96904e2013-05-23 10:42:58 -03001257 ctx->gopcounter = ctx->params.gop_size - 1;
Javier Martin186b2502012-07-26 05:53:35 -03001258 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
Javier Martin186b2502012-07-26 05:53:35 -03001259
Philipp Zabelb96904e2013-05-23 10:42:58 -03001260 ctx->codec = coda_find_codec(ctx->dev, q_data_src->fourcc,
1261 q_data_dst->fourcc);
1262 if (!ctx->codec) {
Javier Martin186b2502012-07-26 05:53:35 -03001263 v4l2_err(v4l2_dev, "couldn't tell instance type.\n");
Philipp Zabelb9063522014-08-05 14:00:10 -03001264 ret = -EINVAL;
1265 goto err;
Javier Martin186b2502012-07-26 05:53:35 -03001266 }
1267
Philipp Zabelcb1d3a32014-10-02 14:08:31 -03001268 if (q_data_dst->fourcc == V4L2_PIX_FMT_JPEG)
1269 ctx->params.gop_size = 1;
1270 ctx->gopcounter = ctx->params.gop_size - 1;
1271
Philipp Zabela1192a12014-07-23 12:28:40 -03001272 ret = ctx->ops->start_streaming(ctx);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001273 if (ctx->inst_type == CODA_INST_DECODER) {
Philipp Zabel89548442014-07-11 06:36:17 -03001274 if (ret == -EAGAIN)
Philipp Zabel918c66f2013-06-27 06:59:01 -03001275 return 0;
Philipp Zabel89548442014-07-11 06:36:17 -03001276 else if (ret < 0)
Philipp Zabelb9063522014-08-05 14:00:10 -03001277 goto err;
Philipp Zabel918c66f2013-06-27 06:59:01 -03001278 }
1279
Philipp Zabel89548442014-07-11 06:36:17 -03001280 ctx->initialized = 1;
1281 return ret;
Philipp Zabelb9063522014-08-05 14:00:10 -03001282
1283err:
1284 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1285 while ((buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx)))
Philipp Zabelb8b1b58c52014-10-21 13:25:52 -03001286 v4l2_m2m_buf_done(buf, VB2_BUF_STATE_QUEUED);
Philipp Zabelb9063522014-08-05 14:00:10 -03001287 } else {
1288 while ((buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx)))
Philipp Zabelb8b1b58c52014-10-21 13:25:52 -03001289 v4l2_m2m_buf_done(buf, VB2_BUF_STATE_QUEUED);
Philipp Zabelb9063522014-08-05 14:00:10 -03001290 }
1291 return ret;
Philipp Zabel89548442014-07-11 06:36:17 -03001292}
1293
Hans Verkuile37559b2014-04-17 02:47:21 -03001294static void coda_stop_streaming(struct vb2_queue *q)
Javier Martin186b2502012-07-26 05:53:35 -03001295{
1296 struct coda_ctx *ctx = vb2_get_drv_priv(q);
Philipp Zabel2fb57f02012-07-25 09:22:07 -03001297 struct coda_dev *dev = ctx->dev;
Philipp Zabel4a31b522014-08-05 14:00:11 -03001298 struct vb2_buffer *buf;
Javier Martin186b2502012-07-26 05:53:35 -03001299
1300 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
Philipp Zabel918c66f2013-06-27 06:59:01 -03001301 v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
Javier Martin186b2502012-07-26 05:53:35 -03001302 "%s: output\n", __func__);
Philipp Zabelb96904e2013-05-23 10:42:58 -03001303 ctx->streamon_out = 0;
Philipp Zabel918c66f2013-06-27 06:59:01 -03001304
Philipp Zabel347bb7f2014-07-23 12:28:42 -03001305 coda_bit_stream_end_flag(ctx);
Philipp Zabel4a31b522014-08-05 14:00:11 -03001306
Philipp Zabel6dd5ef52015-01-23 13:51:26 -03001307 ctx->qsequence = 0;
Philipp Zabel4a31b522014-08-05 14:00:11 -03001308
1309 while ((buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx)))
1310 v4l2_m2m_buf_done(buf, VB2_BUF_STATE_ERROR);
Javier Martin186b2502012-07-26 05:53:35 -03001311 } else {
Philipp Zabel918c66f2013-06-27 06:59:01 -03001312 v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
Javier Martin186b2502012-07-26 05:53:35 -03001313 "%s: capture\n", __func__);
Philipp Zabelb96904e2013-05-23 10:42:58 -03001314 ctx->streamon_cap = 0;
Philipp Zabel918c66f2013-06-27 06:59:01 -03001315
1316 ctx->osequence = 0;
Philipp Zabelcb2c0282014-07-11 06:36:33 -03001317 ctx->sequence_offset = 0;
Philipp Zabel4a31b522014-08-05 14:00:11 -03001318
1319 while ((buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx)))
1320 v4l2_m2m_buf_done(buf, VB2_BUF_STATE_ERROR);
Javier Martin186b2502012-07-26 05:53:35 -03001321 }
1322
Philipp Zabel918c66f2013-06-27 06:59:01 -03001323 if (!ctx->streamon_out && !ctx->streamon_cap) {
Philipp Zabel7cbb1052014-10-02 14:08:32 -03001324 struct coda_buffer_meta *meta;
Philipp Zabel846ced92014-07-11 06:36:31 -03001325
Philipp Zabelf4706d62015-01-23 13:51:27 -03001326 if (ctx->ops->seq_end_work) {
1327 queue_work(dev->workqueue, &ctx->seq_end_work);
1328 flush_work(&ctx->seq_end_work);
1329 }
Philipp Zabel18fd0cc2014-08-05 14:00:17 -03001330 mutex_lock(&ctx->bitstream_mutex);
Philipp Zabel7cbb1052014-10-02 14:08:32 -03001331 while (!list_empty(&ctx->buffer_meta_list)) {
1332 meta = list_first_entry(&ctx->buffer_meta_list,
1333 struct coda_buffer_meta, list);
1334 list_del(&meta->list);
1335 kfree(meta);
Philipp Zabel846ced92014-07-11 06:36:31 -03001336 }
Philipp Zabel18fd0cc2014-08-05 14:00:17 -03001337 mutex_unlock(&ctx->bitstream_mutex);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001338 kfifo_init(&ctx->bitstream_fifo,
1339 ctx->bitstream.vaddr, ctx->bitstream.size);
Philipp Zabelf4706d62015-01-23 13:51:27 -03001340 ctx->initialized = 0;
Philipp Zabel918c66f2013-06-27 06:59:01 -03001341 ctx->runcounter = 0;
Philipp Zabelf157cf42014-09-29 09:53:42 -03001342 ctx->aborting = 0;
Philipp Zabel62bed142012-07-25 10:40:39 -03001343 }
Javier Martin186b2502012-07-26 05:53:35 -03001344}
1345
Philipp Zabel121cacf2014-07-18 07:22:42 -03001346static const struct vb2_ops coda_qops = {
Javier Martin186b2502012-07-26 05:53:35 -03001347 .queue_setup = coda_queue_setup,
1348 .buf_prepare = coda_buf_prepare,
1349 .buf_queue = coda_buf_queue,
Javier Martin186b2502012-07-26 05:53:35 -03001350 .start_streaming = coda_start_streaming,
1351 .stop_streaming = coda_stop_streaming,
Philipp Zabel152ea1c2014-07-11 06:36:21 -03001352 .wait_prepare = vb2_ops_wait_prepare,
1353 .wait_finish = vb2_ops_wait_finish,
Javier Martin186b2502012-07-26 05:53:35 -03001354};
1355
1356static int coda_s_ctrl(struct v4l2_ctrl *ctrl)
1357{
1358 struct coda_ctx *ctx =
1359 container_of(ctrl->handler, struct coda_ctx, ctrls);
1360
1361 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1362 "s_ctrl: id = %d, val = %d\n", ctrl->id, ctrl->val);
1363
1364 switch (ctrl->id) {
Philipp Zabel8f35c7b2012-07-09 04:25:52 -03001365 case V4L2_CID_HFLIP:
1366 if (ctrl->val)
1367 ctx->params.rot_mode |= CODA_MIR_HOR;
1368 else
1369 ctx->params.rot_mode &= ~CODA_MIR_HOR;
1370 break;
1371 case V4L2_CID_VFLIP:
1372 if (ctrl->val)
1373 ctx->params.rot_mode |= CODA_MIR_VER;
1374 else
1375 ctx->params.rot_mode &= ~CODA_MIR_VER;
1376 break;
Javier Martin186b2502012-07-26 05:53:35 -03001377 case V4L2_CID_MPEG_VIDEO_BITRATE:
1378 ctx->params.bitrate = ctrl->val / 1000;
1379 break;
1380 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
1381 ctx->params.gop_size = ctrl->val;
1382 break;
1383 case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP:
1384 ctx->params.h264_intra_qp = ctrl->val;
1385 break;
1386 case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP:
1387 ctx->params.h264_inter_qp = ctrl->val;
1388 break;
Philipp Zabel1a5567e2014-07-11 06:36:26 -03001389 case V4L2_CID_MPEG_VIDEO_H264_MIN_QP:
1390 ctx->params.h264_min_qp = ctrl->val;
1391 break;
1392 case V4L2_CID_MPEG_VIDEO_H264_MAX_QP:
1393 ctx->params.h264_max_qp = ctrl->val;
1394 break;
Philipp Zabelde23b1d2014-07-11 06:36:27 -03001395 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA:
1396 ctx->params.h264_deblk_alpha = ctrl->val;
1397 break;
1398 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA:
1399 ctx->params.h264_deblk_beta = ctrl->val;
1400 break;
1401 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE:
1402 ctx->params.h264_deblk_enabled = (ctrl->val ==
1403 V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED);
1404 break;
Javier Martin186b2502012-07-26 05:53:35 -03001405 case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP:
1406 ctx->params.mpeg4_intra_qp = ctrl->val;
1407 break;
1408 case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP:
1409 ctx->params.mpeg4_inter_qp = ctrl->val;
1410 break;
1411 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:
1412 ctx->params.slice_mode = ctrl->val;
1413 break;
1414 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB:
1415 ctx->params.slice_max_mb = ctrl->val;
1416 break;
Philipp Zabelc566c782012-08-08 11:59:38 -03001417 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES:
1418 ctx->params.slice_max_bits = ctrl->val * 8;
1419 break;
Javier Martin186b2502012-07-26 05:53:35 -03001420 case V4L2_CID_MPEG_VIDEO_HEADER_MODE:
1421 break;
Philipp Zabelf38f79d2014-07-11 06:36:28 -03001422 case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB:
1423 ctx->params.intra_refresh = ctrl->val;
1424 break;
Philipp Zabelcb1d3a32014-10-02 14:08:31 -03001425 case V4L2_CID_JPEG_COMPRESSION_QUALITY:
1426 coda_set_jpeg_compression_quality(ctx, ctrl->val);
1427 break;
1428 case V4L2_CID_JPEG_RESTART_INTERVAL:
1429 ctx->params.jpeg_restart_interval = ctrl->val;
1430 break;
Javier Martin186b2502012-07-26 05:53:35 -03001431 default:
1432 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1433 "Invalid control, id=%d, val=%d\n",
1434 ctrl->id, ctrl->val);
1435 return -EINVAL;
1436 }
1437
1438 return 0;
1439}
1440
Philipp Zabel814c3762014-07-18 07:22:45 -03001441static const struct v4l2_ctrl_ops coda_ctrl_ops = {
Javier Martin186b2502012-07-26 05:53:35 -03001442 .s_ctrl = coda_s_ctrl,
1443};
1444
Philipp Zabelbfc732f2014-10-02 14:08:29 -03001445static void coda_encode_ctrls(struct coda_ctx *ctx)
Javier Martin186b2502012-07-26 05:53:35 -03001446{
Philipp Zabel8f35c7b2012-07-09 04:25:52 -03001447 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
Javier Martin186b2502012-07-26 05:53:35 -03001448 V4L2_CID_MPEG_VIDEO_BITRATE, 0, 32767000, 1, 0);
1449 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1450 V4L2_CID_MPEG_VIDEO_GOP_SIZE, 1, 60, 1, 16);
1451 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
Philipp Zabel594a7502014-07-11 06:36:14 -03001452 V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP, 0, 51, 1, 25);
Javier Martin186b2502012-07-26 05:53:35 -03001453 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
Philipp Zabel594a7502014-07-11 06:36:14 -03001454 V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP, 0, 51, 1, 25);
Philipp Zabel1a5567e2014-07-11 06:36:26 -03001455 if (ctx->dev->devtype->product != CODA_960) {
1456 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1457 V4L2_CID_MPEG_VIDEO_H264_MIN_QP, 0, 51, 1, 12);
1458 }
1459 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1460 V4L2_CID_MPEG_VIDEO_H264_MAX_QP, 0, 51, 1, 51);
Javier Martin186b2502012-07-26 05:53:35 -03001461 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
Philipp Zabelde23b1d2014-07-11 06:36:27 -03001462 V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA, 0, 15, 1, 0);
1463 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1464 V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA, 0, 15, 1, 0);
1465 v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops,
1466 V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE,
1467 V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED, 0x0,
1468 V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED);
1469 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
Javier Martin186b2502012-07-26 05:53:35 -03001470 V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP, 1, 31, 1, 2);
1471 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1472 V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP, 1, 31, 1, 2);
1473 v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops,
1474 V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE,
Philipp Zabelc566c782012-08-08 11:59:38 -03001475 V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES, 0x0,
1476 V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE);
Javier Martin186b2502012-07-26 05:53:35 -03001477 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1478 V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB, 1, 0x3fffffff, 1, 1);
Philipp Zabelc566c782012-08-08 11:59:38 -03001479 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
Philipp Zabelf23797b2014-08-06 08:02:23 -03001480 V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES, 1, 0x3fffffff, 1,
1481 500);
Javier Martin186b2502012-07-26 05:53:35 -03001482 v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops,
1483 V4L2_CID_MPEG_VIDEO_HEADER_MODE,
1484 V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME,
1485 (1 << V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE),
1486 V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME);
Philipp Zabelf38f79d2014-07-11 06:36:28 -03001487 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
Philipp Zabelf23797b2014-08-06 08:02:23 -03001488 V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB, 0,
1489 1920 * 1088 / 256, 1, 0);
Philipp Zabelbfc732f2014-10-02 14:08:29 -03001490}
1491
Philipp Zabelcb1d3a32014-10-02 14:08:31 -03001492static void coda_jpeg_encode_ctrls(struct coda_ctx *ctx)
1493{
1494 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1495 V4L2_CID_JPEG_COMPRESSION_QUALITY, 5, 100, 1, 50);
1496 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1497 V4L2_CID_JPEG_RESTART_INTERVAL, 0, 100, 1, 0);
1498}
1499
Philipp Zabelbfc732f2014-10-02 14:08:29 -03001500static int coda_ctrls_setup(struct coda_ctx *ctx)
1501{
1502 v4l2_ctrl_handler_init(&ctx->ctrls, 2);
1503
1504 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1505 V4L2_CID_HFLIP, 0, 1, 1, 0);
1506 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
1507 V4L2_CID_VFLIP, 0, 1, 1, 0);
Philipp Zabelcb1d3a32014-10-02 14:08:31 -03001508 if (ctx->inst_type == CODA_INST_ENCODER) {
1509 if (ctx->cvd->dst_formats[0] == V4L2_PIX_FMT_JPEG)
1510 coda_jpeg_encode_ctrls(ctx);
1511 else
1512 coda_encode_ctrls(ctx);
1513 }
Javier Martin186b2502012-07-26 05:53:35 -03001514
1515 if (ctx->ctrls.error) {
Philipp Zabelf23797b2014-08-06 08:02:23 -03001516 v4l2_err(&ctx->dev->v4l2_dev,
1517 "control initialization error (%d)",
Javier Martin186b2502012-07-26 05:53:35 -03001518 ctx->ctrls.error);
1519 return -EINVAL;
1520 }
1521
1522 return v4l2_ctrl_handler_setup(&ctx->ctrls);
1523}
1524
Philipp Zabel121cacf2014-07-18 07:22:42 -03001525static int coda_queue_init(struct coda_ctx *ctx, struct vb2_queue *vq)
Javier Martin186b2502012-07-26 05:53:35 -03001526{
Philipp Zabel121cacf2014-07-18 07:22:42 -03001527 vq->drv_priv = ctx;
1528 vq->ops = &coda_qops;
1529 vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
1530 vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
1531 vq->lock = &ctx->dev->dev_mutex;
1532
1533 return vb2_queue_init(vq);
1534}
1535
Philipp Zabel79924ca2014-07-23 12:28:45 -03001536int coda_encoder_queue_init(void *priv, struct vb2_queue *src_vq,
1537 struct vb2_queue *dst_vq)
Philipp Zabel121cacf2014-07-18 07:22:42 -03001538{
Javier Martin186b2502012-07-26 05:53:35 -03001539 int ret;
1540
Javier Martin186b2502012-07-26 05:53:35 -03001541 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
Philipp Zabeld29a8cf2014-07-18 07:22:38 -03001542 src_vq->io_modes = VB2_DMABUF | VB2_MMAP;
Javier Martin186b2502012-07-26 05:53:35 -03001543 src_vq->mem_ops = &vb2_dma_contig_memops;
1544
Philipp Zabel121cacf2014-07-18 07:22:42 -03001545 ret = coda_queue_init(priv, src_vq);
Javier Martin186b2502012-07-26 05:53:35 -03001546 if (ret)
1547 return ret;
1548
Javier Martin186b2502012-07-26 05:53:35 -03001549 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
Philipp Zabeld29a8cf2014-07-18 07:22:38 -03001550 dst_vq->io_modes = VB2_DMABUF | VB2_MMAP;
Javier Martin186b2502012-07-26 05:53:35 -03001551 dst_vq->mem_ops = &vb2_dma_contig_memops;
1552
Philipp Zabel121cacf2014-07-18 07:22:42 -03001553 return coda_queue_init(priv, dst_vq);
1554}
1555
Philipp Zabel79924ca2014-07-23 12:28:45 -03001556int coda_decoder_queue_init(void *priv, struct vb2_queue *src_vq,
1557 struct vb2_queue *dst_vq)
Philipp Zabel121cacf2014-07-18 07:22:42 -03001558{
1559 int ret;
1560
1561 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
1562 src_vq->io_modes = VB2_DMABUF | VB2_MMAP;
1563 src_vq->mem_ops = &vb2_dma_contig_memops;
1564
1565 ret = coda_queue_init(priv, src_vq);
1566 if (ret)
1567 return ret;
1568
1569 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1570 dst_vq->io_modes = VB2_DMABUF | VB2_MMAP;
1571 dst_vq->mem_ops = &vb2_dma_contig_memops;
1572
1573 return coda_queue_init(priv, dst_vq);
Javier Martin186b2502012-07-26 05:53:35 -03001574}
1575
Philipp Zabele11f3e62012-07-25 09:16:58 -03001576static int coda_next_free_instance(struct coda_dev *dev)
1577{
Philipp Zabel0cddc7e2013-09-30 10:34:44 -03001578 int idx = ffz(dev->instance_mask);
1579
1580 if ((idx < 0) ||
1581 (dev->devtype->product == CODA_DX6 && idx > CODADX6_MAX_INSTANCES))
1582 return -EBUSY;
1583
1584 return idx;
Philipp Zabele11f3e62012-07-25 09:16:58 -03001585}
1586
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001587/*
1588 * File operations
1589 */
1590
1591static int coda_open(struct file *file)
Javier Martin186b2502012-07-26 05:53:35 -03001592{
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001593 struct video_device *vdev = video_devdata(file);
1594 struct coda_dev *dev = video_get_drvdata(vdev);
Javier Martin186b2502012-07-26 05:53:35 -03001595 struct coda_ctx *ctx = NULL;
Philipp Zabelf61c0b12014-07-11 06:36:40 -03001596 char *name;
Philipp Zabel918c66f2013-06-27 06:59:01 -03001597 int ret;
Philipp Zabele11f3e62012-07-25 09:16:58 -03001598 int idx;
Javier Martin186b2502012-07-26 05:53:35 -03001599
Philipp Zabelf23797b2014-08-06 08:02:23 -03001600 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
Javier Martin186b2502012-07-26 05:53:35 -03001601 if (!ctx)
1602 return -ENOMEM;
1603
Fabio Estevamf82bc202013-08-21 11:14:16 -03001604 idx = coda_next_free_instance(dev);
Philipp Zabel0cddc7e2013-09-30 10:34:44 -03001605 if (idx < 0) {
1606 ret = idx;
Fabio Estevamf82bc202013-08-21 11:14:16 -03001607 goto err_coda_max;
1608 }
1609 set_bit(idx, &dev->instance_mask);
1610
Philipp Zabelf61c0b12014-07-11 06:36:40 -03001611 name = kasprintf(GFP_KERNEL, "context%d", idx);
1612 ctx->debugfs_entry = debugfs_create_dir(name, dev->debugfs_root);
1613 kfree(name);
1614
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001615 ctx->cvd = to_coda_video_device(vdev);
1616 ctx->inst_type = ctx->cvd->type;
1617 ctx->ops = ctx->cvd->ops;
Philipp Zabel32b6f202014-07-11 06:36:20 -03001618 init_completion(&ctx->completion);
1619 INIT_WORK(&ctx->pic_run_work, coda_pic_run_work);
Philipp Zabela1192a12014-07-23 12:28:40 -03001620 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 Zabelcb1d3a32014-10-02 14:08:31 -03001671 ret = coda_alloc_context_buf(ctx, &ctx->parabuf,
1672 CODA_PARA_BUF_SIZE, "parabuf");
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001673 if (ret < 0) {
Javier Martin186b2502012-07-26 05:53:35 -03001674 v4l2_err(&dev->v4l2_dev, "failed to allocate parabuf");
Fabio Estevamf82bc202013-08-21 11:14:16 -03001675 goto err_dma_alloc;
Javier Martin186b2502012-07-26 05:53:35 -03001676 }
1677
Philipp Zabel9082a7c2013-06-21 03:55:31 -03001678 ctx->bitstream.size = CODA_MAX_FRAME_SIZE;
Philipp Zabelcb1d3a32014-10-02 14:08:31 -03001679 ctx->bitstream.vaddr = dma_alloc_writecombine(
1680 &dev->plat_dev->dev, ctx->bitstream.size,
1681 &ctx->bitstream.paddr, GFP_KERNEL);
Philipp Zabel9082a7c2013-06-21 03:55:31 -03001682 if (!ctx->bitstream.vaddr) {
Philipp Zabelf23797b2014-08-06 08:02:23 -03001683 v4l2_err(&dev->v4l2_dev,
1684 "failed to allocate bitstream ringbuffer");
Philipp Zabel9082a7c2013-06-21 03:55:31 -03001685 ret = -ENOMEM;
Fabio Estevamf82bc202013-08-21 11:14:16 -03001686 goto err_dma_writecombine;
Philipp Zabel9082a7c2013-06-21 03:55:31 -03001687 }
1688 kfifo_init(&ctx->bitstream_fifo,
1689 ctx->bitstream.vaddr, ctx->bitstream.size);
1690 mutex_init(&ctx->bitstream_mutex);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001691 mutex_init(&ctx->buffer_mutex);
Philipp Zabel7cbb1052014-10-02 14:08:32 -03001692 INIT_LIST_HEAD(&ctx->buffer_meta_list);
Philipp Zabel9082a7c2013-06-21 03:55:31 -03001693
Javier Martin186b2502012-07-26 05:53:35 -03001694 coda_lock(ctx);
Philipp Zabele11f3e62012-07-25 09:16:58 -03001695 list_add(&ctx->list, &dev->instances);
Javier Martin186b2502012-07-26 05:53:35 -03001696 coda_unlock(ctx);
1697
Javier Martin186b2502012-07-26 05:53:35 -03001698 v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Created instance %d (%p)\n",
1699 ctx->idx, ctx);
1700
1701 return 0;
1702
Fabio Estevamf82bc202013-08-21 11:14:16 -03001703err_dma_writecombine:
Fabio Estevamf82bc202013-08-21 11:14:16 -03001704 if (ctx->dev->devtype->product == CODA_DX6)
1705 coda_free_aux_buf(dev, &ctx->workbuf);
1706 coda_free_aux_buf(dev, &ctx->parabuf);
1707err_dma_alloc:
1708 v4l2_ctrl_handler_free(&ctx->ctrls);
1709err_ctrls_setup:
Philipp Zabel14604e32014-07-11 06:36:22 -03001710 v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
Fabio Estevamf82bc202013-08-21 11:14:16 -03001711err_ctx_init:
1712 clk_disable_unprepare(dev->clk_ahb);
Fabio Estevam79830db2013-08-21 11:14:17 -03001713err_clk_ahb:
Fabio Estevamf82bc202013-08-21 11:14:16 -03001714 clk_disable_unprepare(dev->clk_per);
Fabio Estevam79830db2013-08-21 11:14:17 -03001715err_clk_per:
Philipp Zabel1e172732014-07-11 06:36:23 -03001716 pm_runtime_put_sync(&dev->plat_dev->dev);
1717err_pm_get:
Javier Martin186b2502012-07-26 05:53:35 -03001718 v4l2_fh_del(&ctx->fh);
1719 v4l2_fh_exit(&ctx->fh);
Fabio Estevamf82bc202013-08-21 11:14:16 -03001720 clear_bit(ctx->idx, &dev->instance_mask);
1721err_coda_max:
Javier Martin186b2502012-07-26 05:53:35 -03001722 kfree(ctx);
1723 return ret;
1724}
1725
1726static int coda_release(struct file *file)
1727{
1728 struct coda_dev *dev = video_drvdata(file);
1729 struct coda_ctx *ctx = fh_to_ctx(file->private_data);
1730
1731 v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Releasing instance %p\n",
1732 ctx);
1733
Philipp Zabeld4bb75f2014-10-08 13:09:11 -03001734 if (ctx->inst_type == CODA_INST_DECODER)
1735 coda_bit_stream_end_flag(ctx);
1736
Philipp Zabel918c66f2013-06-27 06:59:01 -03001737 /* If this instance is running, call .job_abort and wait for it to end */
Philipp Zabel14604e32014-07-11 06:36:22 -03001738 v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001739
1740 /* In case the instance was not running, we still need to call SEQ_END */
Philipp Zabel32b6f202014-07-11 06:36:20 -03001741 if (ctx->initialized) {
1742 queue_work(dev->workqueue, &ctx->seq_end_work);
1743 flush_work(&ctx->seq_end_work);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001744 }
Philipp Zabel918c66f2013-06-27 06:59:01 -03001745
Javier Martin186b2502012-07-26 05:53:35 -03001746 coda_lock(ctx);
Philipp Zabele11f3e62012-07-25 09:16:58 -03001747 list_del(&ctx->list);
Javier Martin186b2502012-07-26 05:53:35 -03001748 coda_unlock(ctx);
1749
Philipp Zabelcb1d3a32014-10-02 14:08:31 -03001750 if (ctx->bitstream.vaddr) {
1751 dma_free_writecombine(&dev->plat_dev->dev, ctx->bitstream.size,
1752 ctx->bitstream.vaddr, ctx->bitstream.paddr);
1753 }
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001754 if (ctx->dev->devtype->product == CODA_DX6)
1755 coda_free_aux_buf(dev, &ctx->workbuf);
1756
1757 coda_free_aux_buf(dev, &ctx->parabuf);
Javier Martin186b2502012-07-26 05:53:35 -03001758 v4l2_ctrl_handler_free(&ctx->ctrls);
Javier Martin186b2502012-07-26 05:53:35 -03001759 clk_disable_unprepare(dev->clk_ahb);
Fabio Estevamf82bc202013-08-21 11:14:16 -03001760 clk_disable_unprepare(dev->clk_per);
Philipp Zabel1e172732014-07-11 06:36:23 -03001761 pm_runtime_put_sync(&dev->plat_dev->dev);
Javier Martin186b2502012-07-26 05:53:35 -03001762 v4l2_fh_del(&ctx->fh);
1763 v4l2_fh_exit(&ctx->fh);
Philipp Zabele11f3e62012-07-25 09:16:58 -03001764 clear_bit(ctx->idx, &dev->instance_mask);
Philipp Zabel58b76772014-07-23 12:28:43 -03001765 if (ctx->ops->release)
1766 ctx->ops->release(ctx);
Philipp Zabele1519e82015-01-23 13:51:17 -03001767 debugfs_remove_recursive(ctx->debugfs_entry);
Javier Martin186b2502012-07-26 05:53:35 -03001768 kfree(ctx);
1769
1770 return 0;
1771}
1772
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001773static const struct v4l2_file_operations coda_fops = {
Javier Martin186b2502012-07-26 05:53:35 -03001774 .owner = THIS_MODULE,
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001775 .open = coda_open,
Javier Martin186b2502012-07-26 05:53:35 -03001776 .release = coda_release,
Philipp Zabel152ea1c2014-07-11 06:36:21 -03001777 .poll = v4l2_m2m_fop_poll,
Javier Martin186b2502012-07-26 05:53:35 -03001778 .unlocked_ioctl = video_ioctl2,
Philipp Zabel152ea1c2014-07-11 06:36:21 -03001779 .mmap = v4l2_m2m_fop_mmap,
Javier Martin186b2502012-07-26 05:53:35 -03001780};
1781
Philipp Zabel87048bb2012-07-02 07:03:43 -03001782static int coda_hw_init(struct coda_dev *dev)
Javier Martin186b2502012-07-26 05:53:35 -03001783{
Javier Martin186b2502012-07-26 05:53:35 -03001784 u32 data;
1785 u16 *p;
Fabio Estevam79830db2013-08-21 11:14:17 -03001786 int i, ret;
Javier Martin186b2502012-07-26 05:53:35 -03001787
Fabio Estevam79830db2013-08-21 11:14:17 -03001788 ret = clk_prepare_enable(dev->clk_per);
1789 if (ret)
Philipp Zabel1e172732014-07-11 06:36:23 -03001790 goto err_clk_per;
Fabio Estevam79830db2013-08-21 11:14:17 -03001791
1792 ret = clk_prepare_enable(dev->clk_ahb);
1793 if (ret)
1794 goto err_clk_ahb;
Javier Martin186b2502012-07-26 05:53:35 -03001795
Philipp Zabel8f452842014-07-11 06:36:35 -03001796 if (dev->rstc)
1797 reset_control_reset(dev->rstc);
1798
Javier Martin186b2502012-07-26 05:53:35 -03001799 /*
1800 * Copy the first CODA_ISRAM_SIZE in the internal SRAM.
Philipp Zabel87048bb2012-07-02 07:03:43 -03001801 * The 16-bit chars in the code buffer are in memory access
1802 * order, re-sort them to CODA order for register download.
Javier Martin186b2502012-07-26 05:53:35 -03001803 * Data in this SRAM survives a reboot.
1804 */
Philipp Zabel87048bb2012-07-02 07:03:43 -03001805 p = (u16 *)dev->codebuf.vaddr;
1806 if (dev->devtype->product == CODA_DX6) {
1807 for (i = 0; i < (CODA_ISRAM_SIZE / 2); i++) {
1808 data = CODA_DOWN_ADDRESS_SET(i) |
1809 CODA_DOWN_DATA_SET(p[i ^ 1]);
1810 coda_write(dev, data, CODA_REG_BIT_CODE_DOWN);
1811 }
1812 } else {
1813 for (i = 0; i < (CODA_ISRAM_SIZE / 2); i++) {
1814 data = CODA_DOWN_ADDRESS_SET(i) |
1815 CODA_DOWN_DATA_SET(p[round_down(i, 4) +
1816 3 - (i % 4)]);
1817 coda_write(dev, data, CODA_REG_BIT_CODE_DOWN);
1818 }
Javier Martin186b2502012-07-26 05:53:35 -03001819 }
Javier Martin186b2502012-07-26 05:53:35 -03001820
Philipp Zabel9acf7692013-05-23 10:42:56 -03001821 /* Clear registers */
1822 for (i = 0; i < 64; i++)
1823 coda_write(dev, 0, CODA_REG_BIT_CODE_BUF_ADDR + i * 4);
1824
Javier Martin186b2502012-07-26 05:53:35 -03001825 /* Tell the BIT where to find everything it needs */
Philipp Zabel89548442014-07-11 06:36:17 -03001826 if (dev->devtype->product == CODA_960 ||
1827 dev->devtype->product == CODA_7541) {
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001828 coda_write(dev, dev->tempbuf.paddr,
1829 CODA_REG_BIT_TEMP_BUF_ADDR);
Philipp Zabel918c66f2013-06-27 06:59:01 -03001830 coda_write(dev, 0, CODA_REG_BIT_BIT_STREAM_PARAM);
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001831 } else {
1832 coda_write(dev, dev->workbuf.paddr,
1833 CODA_REG_BIT_WORK_BUF_ADDR);
1834 }
Javier Martin186b2502012-07-26 05:53:35 -03001835 coda_write(dev, dev->codebuf.paddr,
1836 CODA_REG_BIT_CODE_BUF_ADDR);
1837 coda_write(dev, 0, CODA_REG_BIT_CODE_RUN);
1838
1839 /* Set default values */
1840 switch (dev->devtype->product) {
1841 case CODA_DX6:
Philipp Zabelf23797b2014-08-06 08:02:23 -03001842 coda_write(dev, CODADX6_STREAM_BUF_PIC_FLUSH,
1843 CODA_REG_BIT_STREAM_CTRL);
Javier Martin186b2502012-07-26 05:53:35 -03001844 break;
1845 default:
Philipp Zabelf23797b2014-08-06 08:02:23 -03001846 coda_write(dev, CODA7_STREAM_BUF_PIC_FLUSH,
1847 CODA_REG_BIT_STREAM_CTRL);
Javier Martin186b2502012-07-26 05:53:35 -03001848 }
Philipp Zabel89548442014-07-11 06:36:17 -03001849 if (dev->devtype->product == CODA_960)
1850 coda_write(dev, 1 << 12, CODA_REG_BIT_FRAME_MEM_CTRL);
1851 else
1852 coda_write(dev, 0, CODA_REG_BIT_FRAME_MEM_CTRL);
Philipp Zabel10436672012-07-02 09:03:55 -03001853
1854 if (dev->devtype->product != CODA_DX6)
1855 coda_write(dev, 0, CODA7_REG_BIT_AXI_SRAM_USE);
1856
Javier Martin186b2502012-07-26 05:53:35 -03001857 coda_write(dev, CODA_INT_INTERRUPT_ENABLE,
1858 CODA_REG_BIT_INT_ENABLE);
1859
1860 /* Reset VPU and start processor */
1861 data = coda_read(dev, CODA_REG_BIT_CODE_RESET);
1862 data |= CODA_REG_RESET_ENABLE;
1863 coda_write(dev, data, CODA_REG_BIT_CODE_RESET);
1864 udelay(10);
1865 data &= ~CODA_REG_RESET_ENABLE;
1866 coda_write(dev, data, CODA_REG_BIT_CODE_RESET);
1867 coda_write(dev, CODA_REG_RUN_ENABLE, CODA_REG_BIT_CODE_RUN);
1868
Philipp Zabelfe7554e2014-07-11 06:36:24 -03001869 clk_disable_unprepare(dev->clk_ahb);
1870 clk_disable_unprepare(dev->clk_per);
1871
1872 return 0;
1873
1874err_clk_ahb:
1875 clk_disable_unprepare(dev->clk_per);
1876err_clk_per:
1877 return ret;
1878}
1879
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001880static int coda_register_device(struct coda_dev *dev, int i)
Philipp Zabel121cacf2014-07-18 07:22:42 -03001881{
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001882 struct video_device *vfd = &dev->vfd[i];
1883
Dan Carpenter88ca3af2015-01-08 07:07:08 -03001884 if (i >= dev->devtype->num_vdevs)
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001885 return -EINVAL;
1886
Dan Carpenter88ca3af2015-01-08 07:07:08 -03001887 snprintf(vfd->name, sizeof(vfd->name), "%s",
1888 dev->devtype->vdevs[i]->name);
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001889 vfd->fops = &coda_fops;
1890 vfd->ioctl_ops = &coda_ioctl_ops;
Philipp Zabel121cacf2014-07-18 07:22:42 -03001891 vfd->release = video_device_release_empty,
1892 vfd->lock = &dev->dev_mutex;
1893 vfd->v4l2_dev = &dev->v4l2_dev;
1894 vfd->vfl_dir = VFL_DIR_M2M;
1895 video_set_drvdata(vfd, dev);
1896
Philipp Zabela188a662014-08-05 14:00:20 -03001897 /* Not applicable, use the selection API instead */
1898 v4l2_disable_ioctl(vfd, VIDIOC_CROPCAP);
1899 v4l2_disable_ioctl(vfd, VIDIOC_G_CROP);
1900 v4l2_disable_ioctl(vfd, VIDIOC_S_CROP);
1901
Philipp Zabel121cacf2014-07-18 07:22:42 -03001902 return video_register_device(vfd, VFL_TYPE_GRABBER, 0);
1903}
1904
Javier Martin186b2502012-07-26 05:53:35 -03001905static void coda_fw_callback(const struct firmware *fw, void *context)
1906{
1907 struct coda_dev *dev = context;
1908 struct platform_device *pdev = dev->plat_dev;
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001909 int i, ret;
Javier Martin186b2502012-07-26 05:53:35 -03001910
1911 if (!fw) {
1912 v4l2_err(&dev->v4l2_dev, "firmware request failed\n");
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03001913 goto put_pm;
Javier Martin186b2502012-07-26 05:53:35 -03001914 }
1915
1916 /* allocate auxiliary per-device code buffer for the BIT processor */
Philipp Zabelf61c0b12014-07-11 06:36:40 -03001917 ret = coda_alloc_aux_buf(dev, &dev->codebuf, fw->size, "codebuf",
1918 dev->debugfs_root);
Philipp Zabel5677e3b2013-06-21 03:55:30 -03001919 if (ret < 0) {
Javier Martin186b2502012-07-26 05:53:35 -03001920 dev_err(&pdev->dev, "failed to allocate code buffer\n");
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03001921 goto put_pm;
Javier Martin186b2502012-07-26 05:53:35 -03001922 }
1923
Philipp Zabel87048bb2012-07-02 07:03:43 -03001924 /* Copy the whole firmware image to the code buffer */
1925 memcpy(dev->codebuf.vaddr, fw->data, fw->size);
1926 release_firmware(fw);
1927
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03001928 ret = coda_hw_init(dev);
1929 if (ret < 0) {
1930 v4l2_err(&dev->v4l2_dev, "HW initialization failed\n");
1931 goto put_pm;
Javier Martin186b2502012-07-26 05:53:35 -03001932 }
1933
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03001934 ret = coda_check_firmware(dev);
1935 if (ret < 0)
1936 goto put_pm;
1937
Javier Martin186b2502012-07-26 05:53:35 -03001938 dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
1939 if (IS_ERR(dev->alloc_ctx)) {
1940 v4l2_err(&dev->v4l2_dev, "Failed to alloc vb2 context\n");
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03001941 goto put_pm;
Javier Martin186b2502012-07-26 05:53:35 -03001942 }
1943
1944 dev->m2m_dev = v4l2_m2m_init(&coda_m2m_ops);
1945 if (IS_ERR(dev->m2m_dev)) {
1946 v4l2_err(&dev->v4l2_dev, "Failed to init mem2mem device\n");
1947 goto rel_ctx;
1948 }
1949
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001950 for (i = 0; i < dev->devtype->num_vdevs; i++) {
1951 ret = coda_register_device(dev, i);
1952 if (ret) {
1953 v4l2_err(&dev->v4l2_dev,
1954 "Failed to register %s video device: %d\n",
1955 dev->devtype->vdevs[i]->name, ret);
1956 goto rel_vfd;
1957 }
Philipp Zabel121cacf2014-07-18 07:22:42 -03001958 }
1959
1960 v4l2_info(&dev->v4l2_dev, "codec registered as /dev/video[%d-%d]\n",
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001961 dev->vfd[0].num, dev->vfd[i - 1].num);
Javier Martin186b2502012-07-26 05:53:35 -03001962
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03001963 pm_runtime_put_sync(&pdev->dev);
Javier Martin186b2502012-07-26 05:53:35 -03001964 return;
1965
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03001966rel_vfd:
1967 while (--i >= 0)
1968 video_unregister_device(&dev->vfd[i]);
Javier Martin186b2502012-07-26 05:53:35 -03001969 v4l2_m2m_release(dev->m2m_dev);
1970rel_ctx:
1971 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx);
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03001972put_pm:
1973 pm_runtime_put_sync(&pdev->dev);
Javier Martin186b2502012-07-26 05:53:35 -03001974}
1975
1976static int coda_firmware_request(struct coda_dev *dev)
1977{
1978 char *fw = dev->devtype->firmware;
1979
1980 dev_dbg(&dev->plat_dev->dev, "requesting firmware '%s' for %s\n", fw,
1981 coda_product_name(dev->devtype->product));
1982
1983 return request_firmware_nowait(THIS_MODULE, true,
1984 fw, &dev->plat_dev->dev, GFP_KERNEL, dev, coda_fw_callback);
1985}
1986
1987enum coda_platform {
1988 CODA_IMX27,
Philipp Zabeldf1e74c2012-07-02 06:07:10 -03001989 CODA_IMX53,
Philipp Zabel89548442014-07-11 06:36:17 -03001990 CODA_IMX6Q,
1991 CODA_IMX6DL,
Javier Martin186b2502012-07-26 05:53:35 -03001992};
1993
Emil Goodec06d8752012-08-14 17:44:42 -03001994static const struct coda_devtype coda_devdata[] = {
Javier Martin186b2502012-07-26 05:53:35 -03001995 [CODA_IMX27] = {
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03001996 .firmware = "v4l-codadx6-imx27.bin",
1997 .product = CODA_DX6,
1998 .codecs = codadx6_codecs,
1999 .num_codecs = ARRAY_SIZE(codadx6_codecs),
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03002000 .vdevs = codadx6_video_devices,
2001 .num_vdevs = ARRAY_SIZE(codadx6_video_devices),
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03002002 .workbuf_size = 288 * 1024 + FMO_SLICE_SAVE_BUF_SIZE * 8 * 1024,
Philipp Zabel401e9722014-07-11 06:36:43 -03002003 .iram_size = 0xb000,
Javier Martin186b2502012-07-26 05:53:35 -03002004 },
Philipp Zabeldf1e74c2012-07-02 06:07:10 -03002005 [CODA_IMX53] = {
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03002006 .firmware = "v4l-coda7541-imx53.bin",
2007 .product = CODA_7541,
2008 .codecs = coda7_codecs,
2009 .num_codecs = ARRAY_SIZE(coda7_codecs),
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03002010 .vdevs = coda7_video_devices,
2011 .num_vdevs = ARRAY_SIZE(coda7_video_devices),
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03002012 .workbuf_size = 128 * 1024,
Philipp Zabel5d73fad2014-07-11 06:36:42 -03002013 .tempbuf_size = 304 * 1024,
Philipp Zabel401e9722014-07-11 06:36:43 -03002014 .iram_size = 0x14000,
Philipp Zabeldf1e74c2012-07-02 06:07:10 -03002015 },
Philipp Zabel89548442014-07-11 06:36:17 -03002016 [CODA_IMX6Q] = {
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03002017 .firmware = "v4l-coda960-imx6q.bin",
2018 .product = CODA_960,
2019 .codecs = coda9_codecs,
2020 .num_codecs = ARRAY_SIZE(coda9_codecs),
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03002021 .vdevs = coda9_video_devices,
2022 .num_vdevs = ARRAY_SIZE(coda9_video_devices),
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03002023 .workbuf_size = 80 * 1024,
Philipp Zabel5d73fad2014-07-11 06:36:42 -03002024 .tempbuf_size = 204 * 1024,
Philipp Zabel401e9722014-07-11 06:36:43 -03002025 .iram_size = 0x21000,
Philipp Zabel89548442014-07-11 06:36:17 -03002026 },
2027 [CODA_IMX6DL] = {
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03002028 .firmware = "v4l-coda960-imx6dl.bin",
2029 .product = CODA_960,
2030 .codecs = coda9_codecs,
2031 .num_codecs = ARRAY_SIZE(coda9_codecs),
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03002032 .vdevs = coda9_video_devices,
2033 .num_vdevs = ARRAY_SIZE(coda9_video_devices),
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03002034 .workbuf_size = 80 * 1024,
Philipp Zabel5d73fad2014-07-11 06:36:42 -03002035 .tempbuf_size = 204 * 1024,
Philipp Zabel401e9722014-07-11 06:36:43 -03002036 .iram_size = 0x20000,
Philipp Zabel89548442014-07-11 06:36:17 -03002037 },
Javier Martin186b2502012-07-26 05:53:35 -03002038};
2039
2040static struct platform_device_id coda_platform_ids[] = {
2041 { .name = "coda-imx27", .driver_data = CODA_IMX27 },
2042 { /* sentinel */ }
2043};
2044MODULE_DEVICE_TABLE(platform, coda_platform_ids);
2045
2046#ifdef CONFIG_OF
2047static const struct of_device_id coda_dt_ids[] = {
Alexander Shiyan7b0dd9e2013-06-15 08:09:57 -03002048 { .compatible = "fsl,imx27-vpu", .data = &coda_devdata[CODA_IMX27] },
Philipp Zabeldf1e74c2012-07-02 06:07:10 -03002049 { .compatible = "fsl,imx53-vpu", .data = &coda_devdata[CODA_IMX53] },
Philipp Zabel89548442014-07-11 06:36:17 -03002050 { .compatible = "fsl,imx6q-vpu", .data = &coda_devdata[CODA_IMX6Q] },
2051 { .compatible = "fsl,imx6dl-vpu", .data = &coda_devdata[CODA_IMX6DL] },
Javier Martin186b2502012-07-26 05:53:35 -03002052 { /* sentinel */ }
2053};
2054MODULE_DEVICE_TABLE(of, coda_dt_ids);
2055#endif
2056
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08002057static int coda_probe(struct platform_device *pdev)
Javier Martin186b2502012-07-26 05:53:35 -03002058{
2059 const struct of_device_id *of_id =
2060 of_match_device(of_match_ptr(coda_dt_ids), &pdev->dev);
2061 const struct platform_device_id *pdev_id;
Philipp Zabel657eee72013-04-29 16:17:14 -07002062 struct coda_platform_data *pdata = pdev->dev.platform_data;
2063 struct device_node *np = pdev->dev.of_node;
2064 struct gen_pool *pool;
Javier Martin186b2502012-07-26 05:53:35 -03002065 struct coda_dev *dev;
2066 struct resource *res;
2067 int ret, irq;
2068
Philipp Zabelf23797b2014-08-06 08:02:23 -03002069 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
Philipp Zabel6da999d2014-09-29 09:53:43 -03002070 if (!dev)
Javier Martin186b2502012-07-26 05:53:35 -03002071 return -ENOMEM;
Javier Martin186b2502012-07-26 05:53:35 -03002072
Philipp Zabelb2f91ae2014-10-02 14:08:27 -03002073 pdev_id = of_id ? of_id->data : platform_get_device_id(pdev);
2074
Fabio Estevamb7bd6602014-10-04 16:40:50 -03002075 if (of_id) {
Philipp Zabelb2f91ae2014-10-02 14:08:27 -03002076 dev->devtype = of_id->data;
Fabio Estevamb7bd6602014-10-04 16:40:50 -03002077 } else if (pdev_id) {
Philipp Zabelb2f91ae2014-10-02 14:08:27 -03002078 dev->devtype = &coda_devdata[pdev_id->driver_data];
Fabio Estevamb7bd6602014-10-04 16:40:50 -03002079 } else {
2080 ret = -EINVAL;
2081 goto err_v4l2_register;
Javier Martin186b2502012-07-26 05:53:35 -03002082 }
2083
2084 spin_lock_init(&dev->irqlock);
Philipp Zabele11f3e62012-07-25 09:16:58 -03002085 INIT_LIST_HEAD(&dev->instances);
Javier Martin186b2502012-07-26 05:53:35 -03002086
2087 dev->plat_dev = pdev;
2088 dev->clk_per = devm_clk_get(&pdev->dev, "per");
2089 if (IS_ERR(dev->clk_per)) {
2090 dev_err(&pdev->dev, "Could not get per clock\n");
2091 return PTR_ERR(dev->clk_per);
2092 }
2093
2094 dev->clk_ahb = devm_clk_get(&pdev->dev, "ahb");
2095 if (IS_ERR(dev->clk_ahb)) {
2096 dev_err(&pdev->dev, "Could not get ahb clock\n");
2097 return PTR_ERR(dev->clk_ahb);
2098 }
2099
2100 /* Get memory for physical registers */
2101 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Philipp Zabel611cbbf2013-05-21 04:19:27 -03002102 dev->regs_base = devm_ioremap_resource(&pdev->dev, res);
2103 if (IS_ERR(dev->regs_base))
2104 return PTR_ERR(dev->regs_base);
Javier Martin186b2502012-07-26 05:53:35 -03002105
2106 /* IRQ */
Philipp Zabel540b72e2014-08-05 14:00:09 -03002107 irq = platform_get_irq_byname(pdev, "bit");
2108 if (irq < 0)
2109 irq = platform_get_irq(pdev, 0);
Javier Martin186b2502012-07-26 05:53:35 -03002110 if (irq < 0) {
2111 dev_err(&pdev->dev, "failed to get irq resource\n");
Fabio Estevam7d377432014-06-04 15:46:23 -03002112 return irq;
Javier Martin186b2502012-07-26 05:53:35 -03002113 }
2114
Fabio Estevam08c8d142014-06-04 15:46:24 -03002115 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, coda_irq_handler,
2116 IRQF_ONESHOT, dev_name(&pdev->dev), dev);
2117 if (ret < 0) {
2118 dev_err(&pdev->dev, "failed to request irq: %d\n", ret);
2119 return ret;
Javier Martin186b2502012-07-26 05:53:35 -03002120 }
2121
Philipp Zabelee27aa92014-07-24 16:50:03 -03002122 dev->rstc = devm_reset_control_get_optional(&pdev->dev, NULL);
Philipp Zabel8f452842014-07-11 06:36:35 -03002123 if (IS_ERR(dev->rstc)) {
2124 ret = PTR_ERR(dev->rstc);
Philipp Zabelee27aa92014-07-24 16:50:03 -03002125 if (ret == -ENOENT || ret == -ENOSYS) {
Philipp Zabel8f452842014-07-11 06:36:35 -03002126 dev->rstc = NULL;
2127 } else {
Philipp Zabelf23797b2014-08-06 08:02:23 -03002128 dev_err(&pdev->dev, "failed get reset control: %d\n",
2129 ret);
Philipp Zabel8f452842014-07-11 06:36:35 -03002130 return ret;
2131 }
2132 }
2133
Philipp Zabel657eee72013-04-29 16:17:14 -07002134 /* Get IRAM pool from device tree or platform data */
2135 pool = of_get_named_gen_pool(np, "iram", 0);
2136 if (!pool && pdata)
2137 pool = dev_get_gen_pool(pdata->iram_dev);
2138 if (!pool) {
2139 dev_err(&pdev->dev, "iram pool not available\n");
2140 return -ENOMEM;
2141 }
2142 dev->iram_pool = pool;
2143
Javier Martin186b2502012-07-26 05:53:35 -03002144 ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
2145 if (ret)
2146 return ret;
2147
2148 mutex_init(&dev->dev_mutex);
Philipp Zabelfcb62822013-05-23 10:43:00 -03002149 mutex_init(&dev->coda_mutex);
Javier Martin186b2502012-07-26 05:53:35 -03002150
Philipp Zabelf61c0b12014-07-11 06:36:40 -03002151 dev->debugfs_root = debugfs_create_dir("coda", NULL);
2152 if (!dev->debugfs_root)
2153 dev_warn(&pdev->dev, "failed to create debugfs root\n");
2154
Javier Martin186b2502012-07-26 05:53:35 -03002155 /* allocate auxiliary per-device buffers for the BIT processor */
Philipp Zabel5d73fad2014-07-11 06:36:42 -03002156 if (dev->devtype->product == CODA_DX6) {
Philipp Zabel5677e3b2013-06-21 03:55:30 -03002157 ret = coda_alloc_aux_buf(dev, &dev->workbuf,
Philipp Zabele5b0d1c2014-07-11 06:36:41 -03002158 dev->devtype->workbuf_size, "workbuf",
Philipp Zabelf61c0b12014-07-11 06:36:40 -03002159 dev->debugfs_root);
Philipp Zabel5677e3b2013-06-21 03:55:30 -03002160 if (ret < 0) {
2161 dev_err(&pdev->dev, "failed to allocate work buffer\n");
Fabio Estevamb7bd6602014-10-04 16:40:50 -03002162 goto err_v4l2_register;
Philipp Zabel5677e3b2013-06-21 03:55:30 -03002163 }
Javier Martin186b2502012-07-26 05:53:35 -03002164 }
Philipp Zabel5d73fad2014-07-11 06:36:42 -03002165
2166 if (dev->devtype->tempbuf_size) {
Philipp Zabel5677e3b2013-06-21 03:55:30 -03002167 ret = coda_alloc_aux_buf(dev, &dev->tempbuf,
Philipp Zabel5d73fad2014-07-11 06:36:42 -03002168 dev->devtype->tempbuf_size, "tempbuf",
Philipp Zabelf61c0b12014-07-11 06:36:40 -03002169 dev->debugfs_root);
Philipp Zabel5677e3b2013-06-21 03:55:30 -03002170 if (ret < 0) {
2171 dev_err(&pdev->dev, "failed to allocate temp buffer\n");
Fabio Estevamb7bd6602014-10-04 16:40:50 -03002172 goto err_v4l2_register;
Philipp Zabel5677e3b2013-06-21 03:55:30 -03002173 }
Javier Martin186b2502012-07-26 05:53:35 -03002174 }
2175
Philipp Zabel401e9722014-07-11 06:36:43 -03002176 dev->iram.size = dev->devtype->iram_size;
Philipp Zabelb313bcc2014-07-11 06:36:16 -03002177 dev->iram.vaddr = gen_pool_dma_alloc(dev->iram_pool, dev->iram.size,
2178 &dev->iram.paddr);
2179 if (!dev->iram.vaddr) {
Philipp Zabel8be31c82014-08-05 14:00:13 -03002180 dev_warn(&pdev->dev, "unable to alloc iram\n");
2181 } else {
Philipp Zabel811a6932015-01-23 13:51:23 -03002182 memset(dev->iram.vaddr, 0, dev->iram.size);
Philipp Zabel8be31c82014-08-05 14:00:13 -03002183 dev->iram.blob.data = dev->iram.vaddr;
2184 dev->iram.blob.size = dev->iram.size;
2185 dev->iram.dentry = debugfs_create_blob("iram", 0644,
2186 dev->debugfs_root,
2187 &dev->iram.blob);
Philipp Zabel10436672012-07-02 09:03:55 -03002188 }
2189
Philipp Zabel32b6f202014-07-11 06:36:20 -03002190 dev->workqueue = alloc_workqueue("coda", WQ_UNBOUND | WQ_MEM_RECLAIM, 1);
2191 if (!dev->workqueue) {
2192 dev_err(&pdev->dev, "unable to alloc workqueue\n");
Fabio Estevam74d08d52014-10-04 16:40:51 -03002193 ret = -ENOMEM;
2194 goto err_v4l2_register;
Philipp Zabel32b6f202014-07-11 06:36:20 -03002195 }
2196
Javier Martin186b2502012-07-26 05:53:35 -03002197 platform_set_drvdata(pdev, dev);
2198
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03002199 /*
2200 * Start activated so we can directly call coda_hw_init in
Rafael J. Wysockie243c7c2014-12-04 01:10:10 +01002201 * coda_fw_callback regardless of whether CONFIG_PM is
Ulf Hanssonc5d28e22014-09-22 13:05:56 -03002202 * enabled or whether the device is associated with a PM domain.
2203 */
2204 pm_runtime_get_noresume(&pdev->dev);
2205 pm_runtime_set_active(&pdev->dev);
Philipp Zabel1e172732014-07-11 06:36:23 -03002206 pm_runtime_enable(&pdev->dev);
2207
Javier Martin186b2502012-07-26 05:53:35 -03002208 return coda_firmware_request(dev);
Fabio Estevamb7bd6602014-10-04 16:40:50 -03002209
2210err_v4l2_register:
2211 v4l2_device_unregister(&dev->v4l2_dev);
2212 return ret;
Javier Martin186b2502012-07-26 05:53:35 -03002213}
2214
2215static int coda_remove(struct platform_device *pdev)
2216{
2217 struct coda_dev *dev = platform_get_drvdata(pdev);
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03002218 int i;
Javier Martin186b2502012-07-26 05:53:35 -03002219
Philipp Zabel2c11d1b2014-10-02 14:08:28 -03002220 for (i = 0; i < ARRAY_SIZE(dev->vfd); i++) {
2221 if (video_get_drvdata(&dev->vfd[i]))
2222 video_unregister_device(&dev->vfd[i]);
2223 }
Javier Martin186b2502012-07-26 05:53:35 -03002224 if (dev->m2m_dev)
2225 v4l2_m2m_release(dev->m2m_dev);
Philipp Zabel1e172732014-07-11 06:36:23 -03002226 pm_runtime_disable(&pdev->dev);
Javier Martin186b2502012-07-26 05:53:35 -03002227 if (dev->alloc_ctx)
2228 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx);
2229 v4l2_device_unregister(&dev->v4l2_dev);
Philipp Zabel32b6f202014-07-11 06:36:20 -03002230 destroy_workqueue(dev->workqueue);
Philipp Zabelb313bcc2014-07-11 06:36:16 -03002231 if (dev->iram.vaddr)
2232 gen_pool_free(dev->iram_pool, (unsigned long)dev->iram.vaddr,
2233 dev->iram.size);
Philipp Zabel5677e3b2013-06-21 03:55:30 -03002234 coda_free_aux_buf(dev, &dev->codebuf);
2235 coda_free_aux_buf(dev, &dev->tempbuf);
2236 coda_free_aux_buf(dev, &dev->workbuf);
Philipp Zabelf61c0b12014-07-11 06:36:40 -03002237 debugfs_remove_recursive(dev->debugfs_root);
Javier Martin186b2502012-07-26 05:53:35 -03002238 return 0;
2239}
2240
Rafael J. Wysockie243c7c2014-12-04 01:10:10 +01002241#ifdef CONFIG_PM
Philipp Zabel1e172732014-07-11 06:36:23 -03002242static int coda_runtime_resume(struct device *dev)
2243{
2244 struct coda_dev *cdev = dev_get_drvdata(dev);
2245 int ret = 0;
2246
Philipp Zabel65919e62014-07-18 07:22:36 -03002247 if (dev->pm_domain && cdev->codebuf.vaddr) {
Philipp Zabel1e172732014-07-11 06:36:23 -03002248 ret = coda_hw_init(cdev);
2249 if (ret)
2250 v4l2_err(&cdev->v4l2_dev, "HW initialization failed\n");
2251 }
2252
2253 return ret;
2254}
2255#endif
2256
2257static const struct dev_pm_ops coda_pm_ops = {
2258 SET_RUNTIME_PM_OPS(NULL, coda_runtime_resume, NULL)
2259};
2260
Javier Martin186b2502012-07-26 05:53:35 -03002261static struct platform_driver coda_driver = {
2262 .probe = coda_probe,
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08002263 .remove = coda_remove,
Javier Martin186b2502012-07-26 05:53:35 -03002264 .driver = {
2265 .name = CODA_NAME,
Javier Martin186b2502012-07-26 05:53:35 -03002266 .of_match_table = of_match_ptr(coda_dt_ids),
Philipp Zabel1e172732014-07-11 06:36:23 -03002267 .pm = &coda_pm_ops,
Javier Martin186b2502012-07-26 05:53:35 -03002268 },
2269 .id_table = coda_platform_ids,
2270};
2271
2272module_platform_driver(coda_driver);
2273
2274MODULE_LICENSE("GPL");
2275MODULE_AUTHOR("Javier Martin <javier.martin@vista-silicon.com>");
2276MODULE_DESCRIPTION("Coda multi-standard codec V4L2 driver");