Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1 | /* |
| 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 Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame] | 15 | #include <linux/debugfs.h> |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 16 | #include <linux/delay.h> |
| 17 | #include <linux/firmware.h> |
Philipp Zabel | 657eee7 | 2013-04-29 16:17:14 -0700 | [diff] [blame] | 18 | #include <linux/genalloc.h> |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/io.h> |
| 21 | #include <linux/irq.h> |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 22 | #include <linux/kfifo.h> |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/of_device.h> |
| 25 | #include <linux/platform_device.h> |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 26 | #include <linux/pm_runtime.h> |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 27 | #include <linux/slab.h> |
| 28 | #include <linux/videodev2.h> |
| 29 | #include <linux/of.h> |
Philipp Zabel | 657eee7 | 2013-04-29 16:17:14 -0700 | [diff] [blame] | 30 | #include <linux/platform_data/coda.h> |
Philipp Zabel | 8f45284 | 2014-07-11 06:36:35 -0300 | [diff] [blame] | 31 | #include <linux/reset.h> |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 32 | |
| 33 | #include <media/v4l2-ctrls.h> |
| 34 | #include <media/v4l2-device.h> |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 35 | #include <media/v4l2-event.h> |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 36 | #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 Zabel | a2b3e46 | 2014-07-23 12:28:39 -0300 | [diff] [blame] | 41 | #include "coda.h" |
Philipp Zabel | e19a763 | 2014-07-23 12:28:38 -0300 | [diff] [blame] | 42 | #include "coda_regs.h" |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 43 | |
| 44 | #define CODA_NAME "coda" |
| 45 | |
Philipp Zabel | 0cddc7e | 2013-09-30 10:34:44 -0300 | [diff] [blame] | 46 | #define CODADX6_MAX_INSTANCES 4 |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 47 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 48 | #define CODA_PARA_BUF_SIZE (10 * 1024) |
| 49 | #define CODA_ISRAM_SIZE (2048 * 2) |
| 50 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 51 | #define MIN_W 176 |
| 52 | #define MIN_H 144 |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 53 | |
| 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 Zabel | 79924ca | 2014-07-23 12:28:45 -0300 | [diff] [blame] | 60 | int coda_debug; |
Philipp Zabel | c4eb1bfc | 2013-05-21 04:24:16 -0300 | [diff] [blame] | 61 | module_param(coda_debug, int, 0644); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 62 | MODULE_PARM_DESC(coda_debug, "Debug level (0-1)"); |
| 63 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 64 | struct coda_fmt { |
| 65 | char *name; |
| 66 | u32 fourcc; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 67 | }; |
| 68 | |
Philipp Zabel | a2b3e46 | 2014-07-23 12:28:39 -0300 | [diff] [blame] | 69 | void coda_write(struct coda_dev *dev, u32 data, u32 reg) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 70 | { |
| 71 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, |
| 72 | "%s: data=0x%x, reg=0x%x\n", __func__, data, reg); |
| 73 | writel(data, dev->regs_base + reg); |
| 74 | } |
| 75 | |
Philipp Zabel | a2b3e46 | 2014-07-23 12:28:39 -0300 | [diff] [blame] | 76 | unsigned int coda_read(struct coda_dev *dev, u32 reg) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 77 | { |
| 78 | u32 data; |
| 79 | data = readl(dev->regs_base + reg); |
| 80 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, |
| 81 | "%s: data=0x%x, reg=0x%x\n", __func__, data, reg); |
| 82 | return data; |
| 83 | } |
| 84 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 85 | /* |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 86 | * Array of all formats supported by any version of Coda: |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 87 | */ |
Philipp Zabel | 814c376 | 2014-07-18 07:22:45 -0300 | [diff] [blame] | 88 | static const struct coda_fmt coda_formats[] = { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 89 | { |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 90 | .name = "YUV 4:2:0 Planar, YCbCr", |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 91 | .fourcc = V4L2_PIX_FMT_YUV420, |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 92 | }, |
| 93 | { |
| 94 | .name = "YUV 4:2:0 Planar, YCrCb", |
| 95 | .fourcc = V4L2_PIX_FMT_YVU420, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 96 | }, |
| 97 | { |
| 98 | .name = "H264 Encoded Stream", |
| 99 | .fourcc = V4L2_PIX_FMT_H264, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 100 | }, |
| 101 | { |
| 102 | .name = "MPEG4 Encoded Stream", |
| 103 | .fourcc = V4L2_PIX_FMT_MPEG4, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 104 | }, |
| 105 | }; |
| 106 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 107 | #define CODA_CODEC(mode, src_fourcc, dst_fourcc, max_w, max_h) \ |
| 108 | { mode, src_fourcc, dst_fourcc, max_w, max_h } |
| 109 | |
| 110 | /* |
| 111 | * Arrays of codecs supported by each given version of Coda: |
| 112 | * i.MX27 -> codadx6 |
| 113 | * i.MX5x -> coda7 |
| 114 | * i.MX6 -> coda960 |
| 115 | * Use V4L2_PIX_FMT_YUV420 as placeholder for all supported YUV 4:2:0 variants |
| 116 | */ |
Philipp Zabel | 814c376 | 2014-07-18 07:22:45 -0300 | [diff] [blame] | 117 | static const struct coda_codec codadx6_codecs[] = { |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 118 | CODA_CODEC(CODADX6_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 720, 576), |
| 119 | CODA_CODEC(CODADX6_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 720, 576), |
Philipp Zabel | df1e74c | 2012-07-02 06:07:10 -0300 | [diff] [blame] | 120 | }; |
| 121 | |
Philipp Zabel | 814c376 | 2014-07-18 07:22:45 -0300 | [diff] [blame] | 122 | static const struct coda_codec coda7_codecs[] = { |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 123 | CODA_CODEC(CODA7_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 1280, 720), |
| 124 | CODA_CODEC(CODA7_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 1280, 720), |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 125 | CODA_CODEC(CODA7_MODE_DECODE_H264, V4L2_PIX_FMT_H264, V4L2_PIX_FMT_YUV420, 1920, 1080), |
| 126 | CODA_CODEC(CODA7_MODE_DECODE_MP4, V4L2_PIX_FMT_MPEG4, V4L2_PIX_FMT_YUV420, 1920, 1080), |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 127 | }; |
| 128 | |
Philipp Zabel | 814c376 | 2014-07-18 07:22:45 -0300 | [diff] [blame] | 129 | static const struct coda_codec coda9_codecs[] = { |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 130 | CODA_CODEC(CODA9_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 1920, 1080), |
| 131 | CODA_CODEC(CODA9_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 1920, 1080), |
| 132 | CODA_CODEC(CODA9_MODE_DECODE_H264, V4L2_PIX_FMT_H264, V4L2_PIX_FMT_YUV420, 1920, 1080), |
| 133 | CODA_CODEC(CODA9_MODE_DECODE_MP4, V4L2_PIX_FMT_MPEG4, V4L2_PIX_FMT_YUV420, 1920, 1080), |
| 134 | }; |
| 135 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 136 | static bool coda_format_is_yuv(u32 fourcc) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 137 | { |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 138 | switch (fourcc) { |
| 139 | case V4L2_PIX_FMT_YUV420: |
| 140 | case V4L2_PIX_FMT_YVU420: |
| 141 | return true; |
| 142 | default: |
| 143 | return false; |
| 144 | } |
| 145 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 146 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 147 | /* |
| 148 | * Normalize all supported YUV 4:2:0 formats to the value used in the codec |
| 149 | * tables. |
| 150 | */ |
| 151 | static u32 coda_format_normalize_yuv(u32 fourcc) |
| 152 | { |
| 153 | return coda_format_is_yuv(fourcc) ? V4L2_PIX_FMT_YUV420 : fourcc; |
| 154 | } |
| 155 | |
Philipp Zabel | 814c376 | 2014-07-18 07:22:45 -0300 | [diff] [blame] | 156 | static const struct coda_codec *coda_find_codec(struct coda_dev *dev, |
| 157 | int src_fourcc, int dst_fourcc) |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 158 | { |
Philipp Zabel | 814c376 | 2014-07-18 07:22:45 -0300 | [diff] [blame] | 159 | const struct coda_codec *codecs = dev->devtype->codecs; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 160 | int num_codecs = dev->devtype->num_codecs; |
| 161 | int k; |
| 162 | |
| 163 | src_fourcc = coda_format_normalize_yuv(src_fourcc); |
| 164 | dst_fourcc = coda_format_normalize_yuv(dst_fourcc); |
| 165 | if (src_fourcc == dst_fourcc) |
| 166 | return NULL; |
| 167 | |
| 168 | for (k = 0; k < num_codecs; k++) { |
| 169 | if (codecs[k].src_fourcc == src_fourcc && |
| 170 | codecs[k].dst_fourcc == dst_fourcc) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 171 | break; |
| 172 | } |
| 173 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 174 | if (k == num_codecs) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 175 | return NULL; |
| 176 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 177 | return &codecs[k]; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 178 | } |
| 179 | |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 180 | static void coda_get_max_dimensions(struct coda_dev *dev, |
Philipp Zabel | 814c376 | 2014-07-18 07:22:45 -0300 | [diff] [blame] | 181 | const struct coda_codec *codec, |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 182 | int *max_w, int *max_h) |
| 183 | { |
Philipp Zabel | 814c376 | 2014-07-18 07:22:45 -0300 | [diff] [blame] | 184 | const struct coda_codec *codecs = dev->devtype->codecs; |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 185 | int num_codecs = dev->devtype->num_codecs; |
| 186 | unsigned int w, h; |
| 187 | int k; |
| 188 | |
| 189 | if (codec) { |
| 190 | w = codec->max_w; |
| 191 | h = codec->max_h; |
| 192 | } else { |
| 193 | for (k = 0, w = 0, h = 0; k < num_codecs; k++) { |
| 194 | w = max(w, codecs[k].max_w); |
| 195 | h = max(h, codecs[k].max_h); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | if (max_w) |
| 200 | *max_w = w; |
| 201 | if (max_h) |
| 202 | *max_h = h; |
| 203 | } |
| 204 | |
Philipp Zabel | 79924ca | 2014-07-23 12:28:45 -0300 | [diff] [blame] | 205 | const char *coda_product_name(int product) |
Philipp Zabel | 927933f | 2013-09-30 10:34:48 -0300 | [diff] [blame] | 206 | { |
| 207 | static char buf[9]; |
| 208 | |
| 209 | switch (product) { |
| 210 | case CODA_DX6: |
| 211 | return "CodaDx6"; |
| 212 | case CODA_7541: |
| 213 | return "CODA7541"; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 214 | case CODA_960: |
| 215 | return "CODA960"; |
Philipp Zabel | 927933f | 2013-09-30 10:34:48 -0300 | [diff] [blame] | 216 | default: |
| 217 | snprintf(buf, sizeof(buf), "(0x%04x)", product); |
| 218 | return buf; |
| 219 | } |
| 220 | } |
| 221 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 222 | /* |
| 223 | * V4L2 ioctl() operations. |
| 224 | */ |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 225 | static int coda_querycap(struct file *file, void *priv, |
| 226 | struct v4l2_capability *cap) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 227 | { |
Philipp Zabel | 927933f | 2013-09-30 10:34:48 -0300 | [diff] [blame] | 228 | struct coda_ctx *ctx = fh_to_ctx(priv); |
| 229 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 230 | strlcpy(cap->driver, CODA_NAME, sizeof(cap->driver)); |
Philipp Zabel | 927933f | 2013-09-30 10:34:48 -0300 | [diff] [blame] | 231 | strlcpy(cap->card, coda_product_name(ctx->dev->devtype->product), |
| 232 | sizeof(cap->card)); |
Philipp Zabel | dad0e1c | 2013-05-21 04:18:22 -0300 | [diff] [blame] | 233 | strlcpy(cap->bus_info, "platform:" CODA_NAME, sizeof(cap->bus_info)); |
Philipp Zabel | 3898e7a | 2014-07-18 07:22:37 -0300 | [diff] [blame] | 234 | cap->device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 235 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
| 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
Philipp Zabel | 22e244b | 2014-07-18 07:22:43 -0300 | [diff] [blame] | 240 | static int coda_enum_fmt(struct file *file, void *priv, |
| 241 | struct v4l2_fmtdesc *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 242 | { |
| 243 | struct coda_ctx *ctx = fh_to_ctx(priv); |
Philipp Zabel | 814c376 | 2014-07-18 07:22:45 -0300 | [diff] [blame] | 244 | const struct coda_codec *codecs = ctx->dev->devtype->codecs; |
| 245 | const struct coda_fmt *formats = coda_formats; |
| 246 | const struct coda_fmt *fmt; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 247 | int num_codecs = ctx->dev->devtype->num_codecs; |
| 248 | int num_formats = ARRAY_SIZE(coda_formats); |
| 249 | int i, k, num = 0; |
Philipp Zabel | 22e244b | 2014-07-18 07:22:43 -0300 | [diff] [blame] | 250 | bool yuv; |
| 251 | |
| 252 | if (ctx->inst_type == CODA_INST_ENCODER) |
| 253 | yuv = (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT); |
| 254 | else |
| 255 | yuv = (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 256 | |
| 257 | for (i = 0; i < num_formats; i++) { |
Philipp Zabel | 22e244b | 2014-07-18 07:22:43 -0300 | [diff] [blame] | 258 | /* Skip either raw or compressed formats */ |
| 259 | if (yuv != coda_format_is_yuv(formats[i].fourcc)) |
| 260 | continue; |
| 261 | /* All uncompressed formats are always supported */ |
| 262 | if (yuv) { |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 263 | if (num == f->index) |
| 264 | break; |
| 265 | ++num; |
| 266 | continue; |
| 267 | } |
| 268 | /* Compressed formats may be supported, check the codec list */ |
| 269 | for (k = 0; k < num_codecs; k++) { |
Philipp Zabel | 22e244b | 2014-07-18 07:22:43 -0300 | [diff] [blame] | 270 | if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && |
| 271 | formats[i].fourcc == codecs[k].dst_fourcc) |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 272 | break; |
Philipp Zabel | 22e244b | 2014-07-18 07:22:43 -0300 | [diff] [blame] | 273 | if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT && |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 274 | formats[i].fourcc == codecs[k].src_fourcc) |
| 275 | break; |
| 276 | } |
| 277 | if (k < num_codecs) { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 278 | if (num == f->index) |
| 279 | break; |
| 280 | ++num; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | if (i < num_formats) { |
| 285 | fmt = &formats[i]; |
| 286 | strlcpy(f->description, fmt->name, sizeof(f->description)); |
| 287 | f->pixelformat = fmt->fourcc; |
Philipp Zabel | 22e244b | 2014-07-18 07:22:43 -0300 | [diff] [blame] | 288 | if (!yuv) |
Philipp Zabel | baf7021 | 2013-09-30 10:34:46 -0300 | [diff] [blame] | 289 | f->flags |= V4L2_FMT_FLAG_COMPRESSED; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | /* Format not found */ |
| 294 | return -EINVAL; |
| 295 | } |
| 296 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 297 | static int coda_g_fmt(struct file *file, void *priv, |
| 298 | struct v4l2_format *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 299 | { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 300 | struct coda_q_data *q_data; |
| 301 | struct coda_ctx *ctx = fh_to_ctx(priv); |
| 302 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 303 | q_data = get_q_data(ctx, f->type); |
Philipp Zabel | b973629 | 2014-07-11 06:36:18 -0300 | [diff] [blame] | 304 | if (!q_data) |
| 305 | return -EINVAL; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 306 | |
| 307 | f->fmt.pix.field = V4L2_FIELD_NONE; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 308 | f->fmt.pix.pixelformat = q_data->fourcc; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 309 | f->fmt.pix.width = q_data->width; |
| 310 | f->fmt.pix.height = q_data->height; |
Philipp Zabel | 2fd6a37 | 2014-07-11 06:36:36 -0300 | [diff] [blame] | 311 | f->fmt.pix.bytesperline = q_data->bytesperline; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 312 | |
| 313 | f->fmt.pix.sizeimage = q_data->sizeimage; |
| 314 | f->fmt.pix.colorspace = ctx->colorspace; |
| 315 | |
| 316 | return 0; |
| 317 | } |
| 318 | |
Philipp Zabel | 814c376 | 2014-07-18 07:22:45 -0300 | [diff] [blame] | 319 | static int coda_try_fmt(struct coda_ctx *ctx, const struct coda_codec *codec, |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 320 | struct v4l2_format *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 321 | { |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 322 | struct coda_dev *dev = ctx->dev; |
| 323 | struct coda_q_data *q_data; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 324 | unsigned int max_w, max_h; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 325 | enum v4l2_field field; |
| 326 | |
| 327 | field = f->fmt.pix.field; |
| 328 | if (field == V4L2_FIELD_ANY) |
| 329 | field = V4L2_FIELD_NONE; |
| 330 | else if (V4L2_FIELD_NONE != field) |
| 331 | return -EINVAL; |
| 332 | |
| 333 | /* V4L2 specification suggests the driver corrects the format struct |
| 334 | * if any of the dimensions is unsupported */ |
| 335 | f->fmt.pix.field = field; |
| 336 | |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 337 | coda_get_max_dimensions(dev, codec, &max_w, &max_h); |
| 338 | v4l_bound_align_image(&f->fmt.pix.width, MIN_W, max_w, W_ALIGN, |
| 339 | &f->fmt.pix.height, MIN_H, max_h, H_ALIGN, |
| 340 | S_ALIGN); |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 341 | |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 342 | switch (f->fmt.pix.pixelformat) { |
| 343 | case V4L2_PIX_FMT_YUV420: |
| 344 | case V4L2_PIX_FMT_YVU420: |
| 345 | case V4L2_PIX_FMT_H264: |
| 346 | case V4L2_PIX_FMT_MPEG4: |
| 347 | case V4L2_PIX_FMT_JPEG: |
| 348 | break; |
| 349 | default: |
| 350 | q_data = get_q_data(ctx, f->type); |
Philipp Zabel | b973629 | 2014-07-11 06:36:18 -0300 | [diff] [blame] | 351 | if (!q_data) |
| 352 | return -EINVAL; |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 353 | f->fmt.pix.pixelformat = q_data->fourcc; |
| 354 | } |
| 355 | |
| 356 | switch (f->fmt.pix.pixelformat) { |
| 357 | case V4L2_PIX_FMT_YUV420: |
| 358 | case V4L2_PIX_FMT_YVU420: |
Philipp Zabel | 451dfe5 | 2014-07-11 06:36:39 -0300 | [diff] [blame] | 359 | /* Frame stride must be multiple of 8, but 16 for h.264 */ |
| 360 | f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 16); |
Philipp Zabel | 47cf0c6 | 2013-05-23 10:42:54 -0300 | [diff] [blame] | 361 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * |
Philipp Zabel | 451d43a | 2012-07-26 09:18:27 -0300 | [diff] [blame] | 362 | f->fmt.pix.height * 3 / 2; |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 363 | break; |
| 364 | case V4L2_PIX_FMT_H264: |
| 365 | case V4L2_PIX_FMT_MPEG4: |
| 366 | case V4L2_PIX_FMT_JPEG: |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 367 | f->fmt.pix.bytesperline = 0; |
| 368 | f->fmt.pix.sizeimage = CODA_MAX_FRAME_SIZE; |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 369 | break; |
| 370 | default: |
| 371 | BUG(); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 377 | static int coda_try_fmt_vid_cap(struct file *file, void *priv, |
| 378 | struct v4l2_format *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 379 | { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 380 | struct coda_ctx *ctx = fh_to_ctx(priv); |
Philipp Zabel | 814c376 | 2014-07-18 07:22:45 -0300 | [diff] [blame] | 381 | const struct coda_codec *codec = NULL; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 382 | struct vb2_queue *src_vq; |
| 383 | int ret; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 384 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 385 | /* |
| 386 | * If the source format is already fixed, try to find a codec that |
| 387 | * converts to the given destination format |
| 388 | */ |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 389 | src_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 390 | if (vb2_is_streaming(src_vq)) { |
| 391 | struct coda_q_data *q_data_src; |
| 392 | |
| 393 | q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
| 394 | codec = coda_find_codec(ctx->dev, q_data_src->fourcc, |
| 395 | f->fmt.pix.pixelformat); |
| 396 | if (!codec) |
| 397 | return -EINVAL; |
Philipp Zabel | 91b5841e | 2014-07-18 07:22:41 -0300 | [diff] [blame] | 398 | |
| 399 | f->fmt.pix.width = q_data_src->width; |
| 400 | f->fmt.pix.height = q_data_src->height; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 401 | } else { |
| 402 | /* Otherwise determine codec by encoded format, if possible */ |
| 403 | codec = coda_find_codec(ctx->dev, V4L2_PIX_FMT_YUV420, |
| 404 | f->fmt.pix.pixelformat); |
| 405 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 406 | |
| 407 | f->fmt.pix.colorspace = ctx->colorspace; |
| 408 | |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 409 | ret = coda_try_fmt(ctx, codec, f); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 410 | if (ret < 0) |
| 411 | return ret; |
| 412 | |
| 413 | /* The h.264 decoder only returns complete 16x16 macroblocks */ |
| 414 | if (codec && codec->src_fourcc == V4L2_PIX_FMT_H264) { |
Philipp Zabel | 1b0ed7b | 2014-07-11 06:36:37 -0300 | [diff] [blame] | 415 | f->fmt.pix.width = f->fmt.pix.width; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 416 | f->fmt.pix.height = round_up(f->fmt.pix.height, 16); |
Philipp Zabel | 1b0ed7b | 2014-07-11 06:36:37 -0300 | [diff] [blame] | 417 | f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 16); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 418 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * |
| 419 | f->fmt.pix.height * 3 / 2; |
| 420 | } |
| 421 | |
| 422 | return 0; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 423 | } |
| 424 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 425 | static int coda_try_fmt_vid_out(struct file *file, void *priv, |
| 426 | struct v4l2_format *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 427 | { |
| 428 | struct coda_ctx *ctx = fh_to_ctx(priv); |
Philipp Zabel | fcf5976 | 2014-08-05 14:00:12 -0300 | [diff] [blame] | 429 | const struct coda_codec *codec = NULL; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 430 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 431 | /* Determine codec by encoded format, returns NULL if raw or invalid */ |
Philipp Zabel | fcf5976 | 2014-08-05 14:00:12 -0300 | [diff] [blame] | 432 | if (ctx->inst_type == CODA_INST_DECODER) { |
| 433 | codec = coda_find_codec(ctx->dev, f->fmt.pix.pixelformat, |
Philipp Zabel | 4f31ff0 | 2014-07-18 07:22:44 -0300 | [diff] [blame] | 434 | V4L2_PIX_FMT_YUV420); |
| 435 | if (!codec) |
Philipp Zabel | fcf5976 | 2014-08-05 14:00:12 -0300 | [diff] [blame] | 436 | codec = coda_find_codec(ctx->dev, V4L2_PIX_FMT_H264, |
| 437 | V4L2_PIX_FMT_YUV420); |
| 438 | if (!codec) |
Philipp Zabel | 4f31ff0 | 2014-07-18 07:22:44 -0300 | [diff] [blame] | 439 | return -EINVAL; |
| 440 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 441 | |
| 442 | if (!f->fmt.pix.colorspace) |
| 443 | f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709; |
| 444 | |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 445 | return coda_try_fmt(ctx, codec, f); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 446 | } |
| 447 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 448 | static int coda_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 449 | { |
| 450 | struct coda_q_data *q_data; |
| 451 | struct vb2_queue *vq; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 452 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 453 | vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 454 | if (!vq) |
| 455 | return -EINVAL; |
| 456 | |
| 457 | q_data = get_q_data(ctx, f->type); |
| 458 | if (!q_data) |
| 459 | return -EINVAL; |
| 460 | |
| 461 | if (vb2_is_busy(vq)) { |
| 462 | v4l2_err(&ctx->dev->v4l2_dev, "%s queue busy\n", __func__); |
| 463 | return -EBUSY; |
| 464 | } |
| 465 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 466 | q_data->fourcc = f->fmt.pix.pixelformat; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 467 | q_data->width = f->fmt.pix.width; |
| 468 | q_data->height = f->fmt.pix.height; |
Philipp Zabel | 2fd6a37 | 2014-07-11 06:36:36 -0300 | [diff] [blame] | 469 | q_data->bytesperline = f->fmt.pix.bytesperline; |
Philipp Zabel | 451d43a | 2012-07-26 09:18:27 -0300 | [diff] [blame] | 470 | q_data->sizeimage = f->fmt.pix.sizeimage; |
Philipp Zabel | 52c4167 | 2014-07-11 06:36:19 -0300 | [diff] [blame] | 471 | q_data->rect.left = 0; |
| 472 | q_data->rect.top = 0; |
| 473 | q_data->rect.width = f->fmt.pix.width; |
| 474 | q_data->rect.height = f->fmt.pix.height; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 475 | |
| 476 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 477 | "Setting format for type %d, wxh: %dx%d, fmt: %d\n", |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 478 | f->type, q_data->width, q_data->height, q_data->fourcc); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 479 | |
| 480 | return 0; |
| 481 | } |
| 482 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 483 | static int coda_s_fmt_vid_cap(struct file *file, void *priv, |
| 484 | struct v4l2_format *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 485 | { |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 486 | struct coda_ctx *ctx = fh_to_ctx(priv); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 487 | int ret; |
| 488 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 489 | ret = coda_try_fmt_vid_cap(file, priv, f); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 490 | if (ret) |
| 491 | return ret; |
| 492 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 493 | return coda_s_fmt(ctx, f); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 494 | } |
| 495 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 496 | static int coda_s_fmt_vid_out(struct file *file, void *priv, |
| 497 | struct v4l2_format *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 498 | { |
| 499 | struct coda_ctx *ctx = fh_to_ctx(priv); |
| 500 | int ret; |
| 501 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 502 | ret = coda_try_fmt_vid_out(file, priv, f); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 503 | if (ret) |
| 504 | return ret; |
| 505 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 506 | ret = coda_s_fmt(ctx, f); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 507 | if (ret) |
| 508 | ctx->colorspace = f->fmt.pix.colorspace; |
| 509 | |
| 510 | return ret; |
| 511 | } |
| 512 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 513 | static int coda_qbuf(struct file *file, void *priv, |
| 514 | struct v4l2_buffer *buf) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 515 | { |
| 516 | struct coda_ctx *ctx = fh_to_ctx(priv); |
| 517 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 518 | return v4l2_m2m_qbuf(file, ctx->fh.m2m_ctx, buf); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 519 | } |
| 520 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 521 | static bool coda_buf_is_end_of_stream(struct coda_ctx *ctx, |
| 522 | struct v4l2_buffer *buf) |
| 523 | { |
| 524 | struct vb2_queue *src_vq; |
| 525 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 526 | src_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 527 | |
| 528 | return ((ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) && |
| 529 | (buf->sequence == (ctx->qsequence - 1))); |
| 530 | } |
| 531 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 532 | static int coda_dqbuf(struct file *file, void *priv, |
| 533 | struct v4l2_buffer *buf) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 534 | { |
| 535 | struct coda_ctx *ctx = fh_to_ctx(priv); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 536 | int ret; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 537 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 538 | ret = v4l2_m2m_dqbuf(file, ctx->fh.m2m_ctx, buf); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 539 | |
| 540 | /* If this is the last capture buffer, emit an end-of-stream event */ |
| 541 | if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && |
| 542 | coda_buf_is_end_of_stream(ctx, buf)) { |
| 543 | const struct v4l2_event eos_event = { |
| 544 | .type = V4L2_EVENT_EOS |
| 545 | }; |
| 546 | |
| 547 | v4l2_event_queue_fh(&ctx->fh, &eos_event); |
| 548 | } |
| 549 | |
| 550 | return ret; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 551 | } |
| 552 | |
Philipp Zabel | 52c4167 | 2014-07-11 06:36:19 -0300 | [diff] [blame] | 553 | static int coda_g_selection(struct file *file, void *fh, |
| 554 | struct v4l2_selection *s) |
| 555 | { |
| 556 | struct coda_ctx *ctx = fh_to_ctx(fh); |
| 557 | struct coda_q_data *q_data; |
| 558 | struct v4l2_rect r, *rsel; |
| 559 | |
| 560 | q_data = get_q_data(ctx, s->type); |
| 561 | if (!q_data) |
| 562 | return -EINVAL; |
| 563 | |
| 564 | r.left = 0; |
| 565 | r.top = 0; |
| 566 | r.width = q_data->width; |
| 567 | r.height = q_data->height; |
| 568 | rsel = &q_data->rect; |
| 569 | |
| 570 | switch (s->target) { |
| 571 | case V4L2_SEL_TGT_CROP_DEFAULT: |
| 572 | case V4L2_SEL_TGT_CROP_BOUNDS: |
| 573 | rsel = &r; |
| 574 | /* fallthrough */ |
| 575 | case V4L2_SEL_TGT_CROP: |
| 576 | if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) |
| 577 | return -EINVAL; |
| 578 | break; |
| 579 | case V4L2_SEL_TGT_COMPOSE_BOUNDS: |
| 580 | case V4L2_SEL_TGT_COMPOSE_PADDED: |
| 581 | rsel = &r; |
| 582 | /* fallthrough */ |
| 583 | case V4L2_SEL_TGT_COMPOSE: |
| 584 | case V4L2_SEL_TGT_COMPOSE_DEFAULT: |
| 585 | if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 586 | return -EINVAL; |
| 587 | break; |
| 588 | default: |
| 589 | return -EINVAL; |
| 590 | } |
| 591 | |
| 592 | s->r = *rsel; |
| 593 | |
| 594 | return 0; |
| 595 | } |
| 596 | |
Philipp Zabel | 64ba40a | 2013-09-30 10:34:52 -0300 | [diff] [blame] | 597 | static int coda_try_decoder_cmd(struct file *file, void *fh, |
| 598 | struct v4l2_decoder_cmd *dc) |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 599 | { |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 600 | if (dc->cmd != V4L2_DEC_CMD_STOP) |
| 601 | return -EINVAL; |
| 602 | |
Philipp Zabel | 64ba40a | 2013-09-30 10:34:52 -0300 | [diff] [blame] | 603 | if (dc->flags & V4L2_DEC_CMD_STOP_TO_BLACK) |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 604 | return -EINVAL; |
| 605 | |
Philipp Zabel | 64ba40a | 2013-09-30 10:34:52 -0300 | [diff] [blame] | 606 | if (!(dc->flags & V4L2_DEC_CMD_STOP_IMMEDIATELY) && (dc->stop.pts != 0)) |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 607 | return -EINVAL; |
| 608 | |
Philipp Zabel | 64ba40a | 2013-09-30 10:34:52 -0300 | [diff] [blame] | 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | static int coda_decoder_cmd(struct file *file, void *fh, |
| 613 | struct v4l2_decoder_cmd *dc) |
| 614 | { |
| 615 | struct coda_ctx *ctx = fh_to_ctx(fh); |
| 616 | int ret; |
| 617 | |
| 618 | ret = coda_try_decoder_cmd(file, fh, dc); |
| 619 | if (ret < 0) |
| 620 | return ret; |
| 621 | |
| 622 | /* Ignore decoder stop command silently in encoder context */ |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 623 | if (ctx->inst_type != CODA_INST_DECODER) |
Philipp Zabel | 64ba40a | 2013-09-30 10:34:52 -0300 | [diff] [blame] | 624 | return 0; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 625 | |
Philipp Zabel | 347bb7f | 2014-07-23 12:28:42 -0300 | [diff] [blame] | 626 | /* Set the stream-end flag on this context */ |
| 627 | coda_bit_stream_end_flag(ctx); |
Philipp Zabel | 84e2365 | 2014-07-11 06:36:34 -0300 | [diff] [blame] | 628 | ctx->hold = false; |
Michael Olbrich | f3497da | 2014-07-11 06:36:30 -0300 | [diff] [blame] | 629 | v4l2_m2m_try_schedule(ctx->fh.m2m_ctx); |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 630 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 631 | return 0; |
| 632 | } |
| 633 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 634 | static int coda_subscribe_event(struct v4l2_fh *fh, |
| 635 | const struct v4l2_event_subscription *sub) |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 636 | { |
| 637 | switch (sub->type) { |
| 638 | case V4L2_EVENT_EOS: |
| 639 | return v4l2_event_subscribe(fh, sub, 0, NULL); |
| 640 | default: |
| 641 | return v4l2_ctrl_subscribe_event(fh, sub); |
| 642 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | static const struct v4l2_ioctl_ops coda_ioctl_ops = { |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 646 | .vidioc_querycap = coda_querycap, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 647 | |
Philipp Zabel | 22e244b | 2014-07-18 07:22:43 -0300 | [diff] [blame] | 648 | .vidioc_enum_fmt_vid_cap = coda_enum_fmt, |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 649 | .vidioc_g_fmt_vid_cap = coda_g_fmt, |
| 650 | .vidioc_try_fmt_vid_cap = coda_try_fmt_vid_cap, |
| 651 | .vidioc_s_fmt_vid_cap = coda_s_fmt_vid_cap, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 652 | |
Philipp Zabel | 22e244b | 2014-07-18 07:22:43 -0300 | [diff] [blame] | 653 | .vidioc_enum_fmt_vid_out = coda_enum_fmt, |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 654 | .vidioc_g_fmt_vid_out = coda_g_fmt, |
| 655 | .vidioc_try_fmt_vid_out = coda_try_fmt_vid_out, |
| 656 | .vidioc_s_fmt_vid_out = coda_s_fmt_vid_out, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 657 | |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 658 | .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, |
| 659 | .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 660 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 661 | .vidioc_qbuf = coda_qbuf, |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 662 | .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 663 | .vidioc_dqbuf = coda_dqbuf, |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 664 | .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 665 | |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 666 | .vidioc_streamon = v4l2_m2m_ioctl_streamon, |
| 667 | .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 668 | |
Philipp Zabel | 52c4167 | 2014-07-11 06:36:19 -0300 | [diff] [blame] | 669 | .vidioc_g_selection = coda_g_selection, |
| 670 | |
Philipp Zabel | 64ba40a | 2013-09-30 10:34:52 -0300 | [diff] [blame] | 671 | .vidioc_try_decoder_cmd = coda_try_decoder_cmd, |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 672 | .vidioc_decoder_cmd = coda_decoder_cmd, |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 673 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 674 | .vidioc_subscribe_event = coda_subscribe_event, |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 675 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 676 | }; |
| 677 | |
Philipp Zabel | 79924ca | 2014-07-23 12:28:45 -0300 | [diff] [blame] | 678 | void coda_set_gdi_regs(struct coda_ctx *ctx) |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 679 | { |
| 680 | struct gdi_tiled_map *tiled_map = &ctx->tiled_map; |
| 681 | struct coda_dev *dev = ctx->dev; |
| 682 | int i; |
| 683 | |
| 684 | for (i = 0; i < 16; i++) |
| 685 | coda_write(dev, tiled_map->xy2ca_map[i], |
| 686 | CODA9_GDI_XY2_CAS_0 + 4 * i); |
| 687 | for (i = 0; i < 4; i++) |
| 688 | coda_write(dev, tiled_map->xy2ba_map[i], |
| 689 | CODA9_GDI_XY2_BA_0 + 4 * i); |
| 690 | for (i = 0; i < 16; i++) |
| 691 | coda_write(dev, tiled_map->xy2ra_map[i], |
| 692 | CODA9_GDI_XY2_RAS_0 + 4 * i); |
| 693 | coda_write(dev, tiled_map->xy2rbc_config, CODA9_GDI_XY2_RBC_CONFIG); |
| 694 | for (i = 0; i < 32; i++) |
| 695 | coda_write(dev, tiled_map->rbc2axi_map[i], |
| 696 | CODA9_GDI_RBC2_AXI_0 + 4 * i); |
| 697 | } |
| 698 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 699 | /* |
| 700 | * Mem-to-mem operations. |
| 701 | */ |
Philipp Zabel | 477c1cf | 2013-06-21 03:55:33 -0300 | [diff] [blame] | 702 | |
| 703 | static void coda_device_run(void *m2m_priv) |
| 704 | { |
| 705 | struct coda_ctx *ctx = m2m_priv; |
| 706 | struct coda_dev *dev = ctx->dev; |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 707 | |
| 708 | queue_work(dev->workqueue, &ctx->pic_run_work); |
| 709 | } |
| 710 | |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 711 | static void coda_pic_run_work(struct work_struct *work) |
| 712 | { |
| 713 | struct coda_ctx *ctx = container_of(work, struct coda_ctx, pic_run_work); |
| 714 | struct coda_dev *dev = ctx->dev; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 715 | int ret; |
| 716 | |
| 717 | mutex_lock(&ctx->buffer_mutex); |
Philipp Zabel | 477c1cf | 2013-06-21 03:55:33 -0300 | [diff] [blame] | 718 | mutex_lock(&dev->coda_mutex); |
| 719 | |
Philipp Zabel | a1192a1 | 2014-07-23 12:28:40 -0300 | [diff] [blame] | 720 | ret = ctx->ops->prepare_run(ctx); |
| 721 | if (ret < 0 && ctx->inst_type == CODA_INST_DECODER) { |
| 722 | mutex_unlock(&dev->coda_mutex); |
| 723 | mutex_unlock(&ctx->buffer_mutex); |
| 724 | /* job_finish scheduled by prepare_decode */ |
| 725 | return; |
Philipp Zabel | 1043667 | 2012-07-02 09:03:55 -0300 | [diff] [blame] | 726 | } |
| 727 | |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 728 | if (!wait_for_completion_timeout(&ctx->completion, msecs_to_jiffies(1000))) { |
| 729 | dev_err(&dev->plat_dev->dev, "CODA PIC_RUN timeout\n"); |
Philipp Zabel | 84e2365 | 2014-07-11 06:36:34 -0300 | [diff] [blame] | 730 | |
| 731 | ctx->hold = true; |
Philipp Zabel | 8f45284 | 2014-07-11 06:36:35 -0300 | [diff] [blame] | 732 | |
| 733 | coda_hw_reset(ctx); |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 734 | } else if (!ctx->aborting) { |
Philipp Zabel | a1192a1 | 2014-07-23 12:28:40 -0300 | [diff] [blame] | 735 | ctx->ops->finish_run(ctx); |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | if (ctx->aborting || (!ctx->streamon_cap && !ctx->streamon_out)) |
| 739 | queue_work(dev->workqueue, &ctx->seq_end_work); |
| 740 | |
| 741 | mutex_unlock(&dev->coda_mutex); |
| 742 | mutex_unlock(&ctx->buffer_mutex); |
| 743 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 744 | v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | static int coda_job_ready(void *m2m_priv) |
| 748 | { |
| 749 | struct coda_ctx *ctx = m2m_priv; |
| 750 | |
| 751 | /* |
| 752 | * For both 'P' and 'key' frame cases 1 picture |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 753 | * and 1 frame are needed. In the decoder case, |
| 754 | * the compressed frame can be in the bitstream. |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 755 | */ |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 756 | if (!v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) && |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 757 | ctx->inst_type != CODA_INST_DECODER) { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 758 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 759 | "not ready: not enough video buffers.\n"); |
| 760 | return 0; |
| 761 | } |
| 762 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 763 | if (!v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx)) { |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 764 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 765 | "not ready: not enough video capture buffers.\n"); |
| 766 | return 0; |
| 767 | } |
| 768 | |
Philipp Zabel | 84e2365 | 2014-07-11 06:36:34 -0300 | [diff] [blame] | 769 | if (ctx->hold || |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 770 | ((ctx->inst_type == CODA_INST_DECODER) && |
| 771 | (coda_get_bitstream_payload(ctx) < 512) && |
| 772 | !(ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG))) { |
| 773 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 774 | "%d: not ready: not enough bitstream data.\n", |
| 775 | ctx->idx); |
| 776 | return 0; |
| 777 | } |
| 778 | |
Philipp Zabel | 3e74826 | 2013-05-23 10:43:01 -0300 | [diff] [blame] | 779 | if (ctx->aborting) { |
| 780 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 781 | "not ready: aborting\n"); |
| 782 | return 0; |
| 783 | } |
| 784 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 785 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 786 | "job ready\n"); |
| 787 | return 1; |
| 788 | } |
| 789 | |
| 790 | static void coda_job_abort(void *priv) |
| 791 | { |
| 792 | struct coda_ctx *ctx = priv; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 793 | |
| 794 | ctx->aborting = 1; |
| 795 | |
| 796 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 797 | "Aborting task\n"); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | static void coda_lock(void *m2m_priv) |
| 801 | { |
| 802 | struct coda_ctx *ctx = m2m_priv; |
| 803 | struct coda_dev *pcdev = ctx->dev; |
| 804 | mutex_lock(&pcdev->dev_mutex); |
| 805 | } |
| 806 | |
| 807 | static void coda_unlock(void *m2m_priv) |
| 808 | { |
| 809 | struct coda_ctx *ctx = m2m_priv; |
| 810 | struct coda_dev *pcdev = ctx->dev; |
| 811 | mutex_unlock(&pcdev->dev_mutex); |
| 812 | } |
| 813 | |
Philipp Zabel | 814c376 | 2014-07-18 07:22:45 -0300 | [diff] [blame] | 814 | static const struct v4l2_m2m_ops coda_m2m_ops = { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 815 | .device_run = coda_device_run, |
| 816 | .job_ready = coda_job_ready, |
| 817 | .job_abort = coda_job_abort, |
| 818 | .lock = coda_lock, |
| 819 | .unlock = coda_unlock, |
| 820 | }; |
| 821 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 822 | static void coda_set_tiled_map_type(struct coda_ctx *ctx, int tiled_map_type) |
| 823 | { |
| 824 | struct gdi_tiled_map *tiled_map = &ctx->tiled_map; |
| 825 | int luma_map, chro_map, i; |
| 826 | |
| 827 | memset(tiled_map, 0, sizeof(*tiled_map)); |
| 828 | |
| 829 | luma_map = 64; |
| 830 | chro_map = 64; |
| 831 | tiled_map->map_type = tiled_map_type; |
| 832 | for (i = 0; i < 16; i++) |
| 833 | tiled_map->xy2ca_map[i] = luma_map << 8 | chro_map; |
| 834 | for (i = 0; i < 4; i++) |
| 835 | tiled_map->xy2ba_map[i] = luma_map << 8 | chro_map; |
| 836 | for (i = 0; i < 16; i++) |
| 837 | tiled_map->xy2ra_map[i] = luma_map << 8 | chro_map; |
| 838 | |
| 839 | if (tiled_map_type == GDI_LINEAR_FRAME_MAP) { |
| 840 | tiled_map->xy2rbc_config = 0; |
| 841 | } else { |
| 842 | dev_err(&ctx->dev->plat_dev->dev, "invalid map type: %d\n", |
| 843 | tiled_map_type); |
| 844 | return; |
| 845 | } |
| 846 | } |
| 847 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 848 | static void set_default_params(struct coda_ctx *ctx) |
| 849 | { |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 850 | u32 src_fourcc, dst_fourcc; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 851 | int max_w; |
| 852 | int max_h; |
| 853 | |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 854 | if (ctx->inst_type == CODA_INST_ENCODER) { |
| 855 | src_fourcc = V4L2_PIX_FMT_YUV420; |
| 856 | dst_fourcc = V4L2_PIX_FMT_H264; |
| 857 | } else { |
| 858 | src_fourcc = V4L2_PIX_FMT_H264; |
| 859 | dst_fourcc = V4L2_PIX_FMT_YUV420; |
| 860 | } |
| 861 | ctx->codec = coda_find_codec(ctx->dev, src_fourcc, dst_fourcc); |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 862 | max_w = ctx->codec->max_w; |
| 863 | max_h = ctx->codec->max_h; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 864 | |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 865 | ctx->params.codec_mode = ctx->codec->mode; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 866 | ctx->colorspace = V4L2_COLORSPACE_REC709; |
| 867 | ctx->params.framerate = 30; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 868 | ctx->aborting = 0; |
| 869 | |
| 870 | /* Default formats for output and input queues */ |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 871 | ctx->q_data[V4L2_M2M_SRC].fourcc = ctx->codec->src_fourcc; |
| 872 | ctx->q_data[V4L2_M2M_DST].fourcc = ctx->codec->dst_fourcc; |
| 873 | ctx->q_data[V4L2_M2M_SRC].width = max_w; |
| 874 | ctx->q_data[V4L2_M2M_SRC].height = max_h; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 875 | ctx->q_data[V4L2_M2M_DST].width = max_w; |
| 876 | ctx->q_data[V4L2_M2M_DST].height = max_h; |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 877 | if (ctx->codec->src_fourcc == V4L2_PIX_FMT_YUV420) { |
| 878 | ctx->q_data[V4L2_M2M_SRC].bytesperline = max_w; |
| 879 | ctx->q_data[V4L2_M2M_SRC].sizeimage = (max_w * max_h * 3) / 2; |
| 880 | ctx->q_data[V4L2_M2M_DST].bytesperline = 0; |
| 881 | ctx->q_data[V4L2_M2M_DST].sizeimage = CODA_MAX_FRAME_SIZE; |
| 882 | } else { |
| 883 | ctx->q_data[V4L2_M2M_SRC].bytesperline = 0; |
| 884 | ctx->q_data[V4L2_M2M_SRC].sizeimage = CODA_MAX_FRAME_SIZE; |
| 885 | ctx->q_data[V4L2_M2M_DST].bytesperline = max_w; |
| 886 | ctx->q_data[V4L2_M2M_DST].sizeimage = (max_w * max_h * 3) / 2; |
| 887 | } |
Philipp Zabel | 52c4167 | 2014-07-11 06:36:19 -0300 | [diff] [blame] | 888 | ctx->q_data[V4L2_M2M_SRC].rect.width = max_w; |
| 889 | ctx->q_data[V4L2_M2M_SRC].rect.height = max_h; |
| 890 | ctx->q_data[V4L2_M2M_DST].rect.width = max_w; |
| 891 | ctx->q_data[V4L2_M2M_DST].rect.height = max_h; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 892 | |
| 893 | if (ctx->dev->devtype->product == CODA_960) |
| 894 | coda_set_tiled_map_type(ctx, GDI_LINEAR_FRAME_MAP); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | /* |
| 898 | * Queue operations |
| 899 | */ |
| 900 | static int coda_queue_setup(struct vb2_queue *vq, |
| 901 | const struct v4l2_format *fmt, |
| 902 | unsigned int *nbuffers, unsigned int *nplanes, |
| 903 | unsigned int sizes[], void *alloc_ctxs[]) |
| 904 | { |
| 905 | struct coda_ctx *ctx = vb2_get_drv_priv(vq); |
Philipp Zabel | e34db06 | 2012-08-29 08:22:00 -0300 | [diff] [blame] | 906 | struct coda_q_data *q_data; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 907 | unsigned int size; |
| 908 | |
Philipp Zabel | e34db06 | 2012-08-29 08:22:00 -0300 | [diff] [blame] | 909 | q_data = get_q_data(ctx, vq->type); |
| 910 | size = q_data->sizeimage; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 911 | |
| 912 | *nplanes = 1; |
| 913 | sizes[0] = size; |
| 914 | |
| 915 | alloc_ctxs[0] = ctx->dev->alloc_ctx; |
| 916 | |
| 917 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 918 | "get %d buffer(s) of size %d each.\n", *nbuffers, size); |
| 919 | |
| 920 | return 0; |
| 921 | } |
| 922 | |
| 923 | static int coda_buf_prepare(struct vb2_buffer *vb) |
| 924 | { |
| 925 | struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); |
| 926 | struct coda_q_data *q_data; |
| 927 | |
| 928 | q_data = get_q_data(ctx, vb->vb2_queue->type); |
| 929 | |
| 930 | if (vb2_plane_size(vb, 0) < q_data->sizeimage) { |
| 931 | v4l2_warn(&ctx->dev->v4l2_dev, |
| 932 | "%s data will not fit into plane (%lu < %lu)\n", |
| 933 | __func__, vb2_plane_size(vb, 0), |
| 934 | (long)q_data->sizeimage); |
| 935 | return -EINVAL; |
| 936 | } |
| 937 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 938 | return 0; |
| 939 | } |
| 940 | |
| 941 | static void coda_buf_queue(struct vb2_buffer *vb) |
| 942 | { |
| 943 | struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 944 | struct coda_q_data *q_data; |
| 945 | |
| 946 | q_data = get_q_data(ctx, vb->vb2_queue->type); |
| 947 | |
| 948 | /* |
| 949 | * In the decoder case, immediately try to copy the buffer into the |
| 950 | * bitstream ringbuffer and mark it as ready to be dequeued. |
| 951 | */ |
| 952 | if (q_data->fourcc == V4L2_PIX_FMT_H264 && |
| 953 | vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { |
| 954 | /* |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 955 | * For backwards compatibility, queuing an empty buffer marks |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 956 | * the stream end |
| 957 | */ |
Philipp Zabel | 347bb7f | 2014-07-23 12:28:42 -0300 | [diff] [blame] | 958 | if (vb2_get_plane_payload(vb, 0) == 0) |
| 959 | coda_bit_stream_end_flag(ctx); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 960 | mutex_lock(&ctx->bitstream_mutex); |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 961 | v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb); |
Michael Olbrich | eabed93 | 2014-07-18 07:22:40 -0300 | [diff] [blame] | 962 | if (vb2_is_streaming(vb->vb2_queue)) |
| 963 | coda_fill_bitstream(ctx); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 964 | mutex_unlock(&ctx->bitstream_mutex); |
| 965 | } else { |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 966 | v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 967 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 968 | } |
| 969 | |
Philipp Zabel | 79924ca | 2014-07-23 12:28:45 -0300 | [diff] [blame] | 970 | int coda_alloc_aux_buf(struct coda_dev *dev, struct coda_aux_buf *buf, |
| 971 | size_t size, const char *name, struct dentry *parent) |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 972 | { |
| 973 | buf->vaddr = dma_alloc_coherent(&dev->plat_dev->dev, size, &buf->paddr, |
| 974 | GFP_KERNEL); |
| 975 | if (!buf->vaddr) |
| 976 | return -ENOMEM; |
| 977 | |
| 978 | buf->size = size; |
| 979 | |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame] | 980 | if (name && parent) { |
| 981 | buf->blob.data = buf->vaddr; |
| 982 | buf->blob.size = size; |
| 983 | buf->dentry = debugfs_create_blob(name, 0644, parent, &buf->blob); |
| 984 | if (!buf->dentry) |
| 985 | dev_warn(&dev->plat_dev->dev, |
| 986 | "failed to create debugfs entry %s\n", name); |
| 987 | } |
| 988 | |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 989 | return 0; |
| 990 | } |
| 991 | |
Philipp Zabel | 79924ca | 2014-07-23 12:28:45 -0300 | [diff] [blame] | 992 | void coda_free_aux_buf(struct coda_dev *dev, |
| 993 | struct coda_aux_buf *buf) |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 994 | { |
| 995 | if (buf->vaddr) { |
| 996 | dma_free_coherent(&dev->plat_dev->dev, buf->size, |
| 997 | buf->vaddr, buf->paddr); |
| 998 | buf->vaddr = NULL; |
| 999 | buf->size = 0; |
| 1000 | } |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame] | 1001 | debugfs_remove(buf->dentry); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1002 | } |
| 1003 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1004 | static int coda_start_streaming(struct vb2_queue *q, unsigned int count) |
| 1005 | { |
| 1006 | struct coda_ctx *ctx = vb2_get_drv_priv(q); |
| 1007 | struct v4l2_device *v4l2_dev = &ctx->dev->v4l2_dev; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1008 | struct coda_q_data *q_data_src, *q_data_dst; |
Philipp Zabel | b906352 | 2014-08-05 14:00:10 -0300 | [diff] [blame] | 1009 | struct vb2_buffer *buf; |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 1010 | u32 dst_fourcc; |
Philipp Zabel | d35167a | 2013-05-23 10:42:59 -0300 | [diff] [blame] | 1011 | int ret = 0; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1012 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 1013 | q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1014 | if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { |
| 1015 | if (q_data_src->fourcc == V4L2_PIX_FMT_H264) { |
Michael Olbrich | eabed93 | 2014-07-18 07:22:40 -0300 | [diff] [blame] | 1016 | /* copy the buffers that where queued before streamon */ |
| 1017 | mutex_lock(&ctx->bitstream_mutex); |
| 1018 | coda_fill_bitstream(ctx); |
| 1019 | mutex_unlock(&ctx->bitstream_mutex); |
| 1020 | |
Philipp Zabel | b906352 | 2014-08-05 14:00:10 -0300 | [diff] [blame] | 1021 | if (coda_get_bitstream_payload(ctx) < 512) { |
| 1022 | ret = -EINVAL; |
| 1023 | goto err; |
| 1024 | } |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1025 | } else { |
Philipp Zabel | b906352 | 2014-08-05 14:00:10 -0300 | [diff] [blame] | 1026 | if (count < 1) { |
| 1027 | ret = -EINVAL; |
| 1028 | goto err; |
| 1029 | } |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | ctx->streamon_out = 1; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1033 | } else { |
Philipp Zabel | b906352 | 2014-08-05 14:00:10 -0300 | [diff] [blame] | 1034 | if (count < 1) { |
| 1035 | ret = -EINVAL; |
| 1036 | goto err; |
| 1037 | } |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1038 | |
| 1039 | ctx->streamon_cap = 1; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 1040 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1041 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 1042 | /* Don't start the coda unless both queues are on */ |
| 1043 | if (!(ctx->streamon_out & ctx->streamon_cap)) |
| 1044 | return 0; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1045 | |
Philipp Zabel | eb10751 | 2013-09-30 10:34:45 -0300 | [diff] [blame] | 1046 | /* Allow decoder device_run with no new buffers queued */ |
| 1047 | if (ctx->inst_type == CODA_INST_DECODER) |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 1048 | v4l2_m2m_set_src_buffered(ctx->fh.m2m_ctx, true); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1049 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 1050 | ctx->gopcounter = ctx->params.gop_size - 1; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1051 | q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 1052 | dst_fourcc = q_data_dst->fourcc; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1053 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 1054 | ctx->codec = coda_find_codec(ctx->dev, q_data_src->fourcc, |
| 1055 | q_data_dst->fourcc); |
| 1056 | if (!ctx->codec) { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1057 | v4l2_err(v4l2_dev, "couldn't tell instance type.\n"); |
Philipp Zabel | b906352 | 2014-08-05 14:00:10 -0300 | [diff] [blame] | 1058 | ret = -EINVAL; |
| 1059 | goto err; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1060 | } |
| 1061 | |
Philipp Zabel | a1192a1 | 2014-07-23 12:28:40 -0300 | [diff] [blame] | 1062 | ret = ctx->ops->start_streaming(ctx); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1063 | if (ctx->inst_type == CODA_INST_DECODER) { |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1064 | if (ret == -EAGAIN) |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1065 | return 0; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1066 | else if (ret < 0) |
Philipp Zabel | b906352 | 2014-08-05 14:00:10 -0300 | [diff] [blame] | 1067 | goto err; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1068 | } |
| 1069 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1070 | ctx->initialized = 1; |
| 1071 | return ret; |
Philipp Zabel | b906352 | 2014-08-05 14:00:10 -0300 | [diff] [blame] | 1072 | |
| 1073 | err: |
| 1074 | if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { |
| 1075 | while ((buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx))) |
| 1076 | v4l2_m2m_buf_done(buf, VB2_BUF_STATE_DEQUEUED); |
| 1077 | } else { |
| 1078 | while ((buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx))) |
| 1079 | v4l2_m2m_buf_done(buf, VB2_BUF_STATE_DEQUEUED); |
| 1080 | } |
| 1081 | return ret; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1082 | } |
| 1083 | |
Hans Verkuil | e37559b | 2014-04-17 02:47:21 -0300 | [diff] [blame] | 1084 | static void coda_stop_streaming(struct vb2_queue *q) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1085 | { |
| 1086 | struct coda_ctx *ctx = vb2_get_drv_priv(q); |
Philipp Zabel | 2fb57f0 | 2012-07-25 09:22:07 -0300 | [diff] [blame] | 1087 | struct coda_dev *dev = ctx->dev; |
Philipp Zabel | 4a31b52 | 2014-08-05 14:00:11 -0300 | [diff] [blame] | 1088 | struct vb2_buffer *buf; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1089 | |
| 1090 | if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1091 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1092 | "%s: output\n", __func__); |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 1093 | ctx->streamon_out = 0; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1094 | |
Philipp Zabel | 347bb7f | 2014-07-23 12:28:42 -0300 | [diff] [blame] | 1095 | coda_bit_stream_end_flag(ctx); |
Philipp Zabel | 4a31b52 | 2014-08-05 14:00:11 -0300 | [diff] [blame] | 1096 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1097 | ctx->isequence = 0; |
Philipp Zabel | 4a31b52 | 2014-08-05 14:00:11 -0300 | [diff] [blame] | 1098 | |
| 1099 | while ((buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx))) |
| 1100 | v4l2_m2m_buf_done(buf, VB2_BUF_STATE_ERROR); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1101 | } else { |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1102 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1103 | "%s: capture\n", __func__); |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 1104 | ctx->streamon_cap = 0; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1105 | |
| 1106 | ctx->osequence = 0; |
Philipp Zabel | cb2c028 | 2014-07-11 06:36:33 -0300 | [diff] [blame] | 1107 | ctx->sequence_offset = 0; |
Philipp Zabel | 4a31b52 | 2014-08-05 14:00:11 -0300 | [diff] [blame] | 1108 | |
| 1109 | while ((buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx))) |
| 1110 | v4l2_m2m_buf_done(buf, VB2_BUF_STATE_ERROR); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1111 | } |
| 1112 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1113 | if (!ctx->streamon_out && !ctx->streamon_cap) { |
Philipp Zabel | 846ced9 | 2014-07-11 06:36:31 -0300 | [diff] [blame] | 1114 | struct coda_timestamp *ts; |
| 1115 | |
| 1116 | while (!list_empty(&ctx->timestamp_list)) { |
| 1117 | ts = list_first_entry(&ctx->timestamp_list, |
| 1118 | struct coda_timestamp, list); |
| 1119 | list_del(&ts->list); |
| 1120 | kfree(ts); |
| 1121 | } |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1122 | kfifo_init(&ctx->bitstream_fifo, |
| 1123 | ctx->bitstream.vaddr, ctx->bitstream.size); |
| 1124 | ctx->runcounter = 0; |
Philipp Zabel | 62bed14 | 2012-07-25 10:40:39 -0300 | [diff] [blame] | 1125 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1126 | } |
| 1127 | |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1128 | static const struct vb2_ops coda_qops = { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1129 | .queue_setup = coda_queue_setup, |
| 1130 | .buf_prepare = coda_buf_prepare, |
| 1131 | .buf_queue = coda_buf_queue, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1132 | .start_streaming = coda_start_streaming, |
| 1133 | .stop_streaming = coda_stop_streaming, |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 1134 | .wait_prepare = vb2_ops_wait_prepare, |
| 1135 | .wait_finish = vb2_ops_wait_finish, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1136 | }; |
| 1137 | |
| 1138 | static int coda_s_ctrl(struct v4l2_ctrl *ctrl) |
| 1139 | { |
| 1140 | struct coda_ctx *ctx = |
| 1141 | container_of(ctrl->handler, struct coda_ctx, ctrls); |
| 1142 | |
| 1143 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 1144 | "s_ctrl: id = %d, val = %d\n", ctrl->id, ctrl->val); |
| 1145 | |
| 1146 | switch (ctrl->id) { |
Philipp Zabel | 8f35c7b | 2012-07-09 04:25:52 -0300 | [diff] [blame] | 1147 | case V4L2_CID_HFLIP: |
| 1148 | if (ctrl->val) |
| 1149 | ctx->params.rot_mode |= CODA_MIR_HOR; |
| 1150 | else |
| 1151 | ctx->params.rot_mode &= ~CODA_MIR_HOR; |
| 1152 | break; |
| 1153 | case V4L2_CID_VFLIP: |
| 1154 | if (ctrl->val) |
| 1155 | ctx->params.rot_mode |= CODA_MIR_VER; |
| 1156 | else |
| 1157 | ctx->params.rot_mode &= ~CODA_MIR_VER; |
| 1158 | break; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1159 | case V4L2_CID_MPEG_VIDEO_BITRATE: |
| 1160 | ctx->params.bitrate = ctrl->val / 1000; |
| 1161 | break; |
| 1162 | case V4L2_CID_MPEG_VIDEO_GOP_SIZE: |
| 1163 | ctx->params.gop_size = ctrl->val; |
| 1164 | break; |
| 1165 | case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP: |
| 1166 | ctx->params.h264_intra_qp = ctrl->val; |
| 1167 | break; |
| 1168 | case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP: |
| 1169 | ctx->params.h264_inter_qp = ctrl->val; |
| 1170 | break; |
Philipp Zabel | 1a5567e | 2014-07-11 06:36:26 -0300 | [diff] [blame] | 1171 | case V4L2_CID_MPEG_VIDEO_H264_MIN_QP: |
| 1172 | ctx->params.h264_min_qp = ctrl->val; |
| 1173 | break; |
| 1174 | case V4L2_CID_MPEG_VIDEO_H264_MAX_QP: |
| 1175 | ctx->params.h264_max_qp = ctrl->val; |
| 1176 | break; |
Philipp Zabel | de23b1d | 2014-07-11 06:36:27 -0300 | [diff] [blame] | 1177 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA: |
| 1178 | ctx->params.h264_deblk_alpha = ctrl->val; |
| 1179 | break; |
| 1180 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA: |
| 1181 | ctx->params.h264_deblk_beta = ctrl->val; |
| 1182 | break; |
| 1183 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE: |
| 1184 | ctx->params.h264_deblk_enabled = (ctrl->val == |
| 1185 | V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED); |
| 1186 | break; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1187 | case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP: |
| 1188 | ctx->params.mpeg4_intra_qp = ctrl->val; |
| 1189 | break; |
| 1190 | case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP: |
| 1191 | ctx->params.mpeg4_inter_qp = ctrl->val; |
| 1192 | break; |
| 1193 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE: |
| 1194 | ctx->params.slice_mode = ctrl->val; |
| 1195 | break; |
| 1196 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB: |
| 1197 | ctx->params.slice_max_mb = ctrl->val; |
| 1198 | break; |
Philipp Zabel | c566c78 | 2012-08-08 11:59:38 -0300 | [diff] [blame] | 1199 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES: |
| 1200 | ctx->params.slice_max_bits = ctrl->val * 8; |
| 1201 | break; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1202 | case V4L2_CID_MPEG_VIDEO_HEADER_MODE: |
| 1203 | break; |
Philipp Zabel | f38f79d | 2014-07-11 06:36:28 -0300 | [diff] [blame] | 1204 | case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB: |
| 1205 | ctx->params.intra_refresh = ctrl->val; |
| 1206 | break; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1207 | default: |
| 1208 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 1209 | "Invalid control, id=%d, val=%d\n", |
| 1210 | ctrl->id, ctrl->val); |
| 1211 | return -EINVAL; |
| 1212 | } |
| 1213 | |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
Philipp Zabel | 814c376 | 2014-07-18 07:22:45 -0300 | [diff] [blame] | 1217 | static const struct v4l2_ctrl_ops coda_ctrl_ops = { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1218 | .s_ctrl = coda_s_ctrl, |
| 1219 | }; |
| 1220 | |
| 1221 | static int coda_ctrls_setup(struct coda_ctx *ctx) |
| 1222 | { |
| 1223 | v4l2_ctrl_handler_init(&ctx->ctrls, 9); |
| 1224 | |
| 1225 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
Philipp Zabel | 8f35c7b | 2012-07-09 04:25:52 -0300 | [diff] [blame] | 1226 | V4L2_CID_HFLIP, 0, 1, 1, 0); |
| 1227 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 1228 | V4L2_CID_VFLIP, 0, 1, 1, 0); |
| 1229 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1230 | V4L2_CID_MPEG_VIDEO_BITRATE, 0, 32767000, 1, 0); |
| 1231 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 1232 | V4L2_CID_MPEG_VIDEO_GOP_SIZE, 1, 60, 1, 16); |
| 1233 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
Philipp Zabel | 594a750 | 2014-07-11 06:36:14 -0300 | [diff] [blame] | 1234 | V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP, 0, 51, 1, 25); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1235 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
Philipp Zabel | 594a750 | 2014-07-11 06:36:14 -0300 | [diff] [blame] | 1236 | V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP, 0, 51, 1, 25); |
Philipp Zabel | 1a5567e | 2014-07-11 06:36:26 -0300 | [diff] [blame] | 1237 | if (ctx->dev->devtype->product != CODA_960) { |
| 1238 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 1239 | V4L2_CID_MPEG_VIDEO_H264_MIN_QP, 0, 51, 1, 12); |
| 1240 | } |
| 1241 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 1242 | V4L2_CID_MPEG_VIDEO_H264_MAX_QP, 0, 51, 1, 51); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1243 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
Philipp Zabel | de23b1d | 2014-07-11 06:36:27 -0300 | [diff] [blame] | 1244 | V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA, 0, 15, 1, 0); |
| 1245 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 1246 | V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA, 0, 15, 1, 0); |
| 1247 | v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops, |
| 1248 | V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE, |
| 1249 | V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED, 0x0, |
| 1250 | V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED); |
| 1251 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1252 | V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP, 1, 31, 1, 2); |
| 1253 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 1254 | V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP, 1, 31, 1, 2); |
| 1255 | v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops, |
| 1256 | V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE, |
Philipp Zabel | c566c78 | 2012-08-08 11:59:38 -0300 | [diff] [blame] | 1257 | V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES, 0x0, |
| 1258 | V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1259 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 1260 | V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB, 1, 0x3fffffff, 1, 1); |
Philipp Zabel | c566c78 | 2012-08-08 11:59:38 -0300 | [diff] [blame] | 1261 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 1262 | V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES, 1, 0x3fffffff, 1, 500); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1263 | v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops, |
| 1264 | V4L2_CID_MPEG_VIDEO_HEADER_MODE, |
| 1265 | V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME, |
| 1266 | (1 << V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE), |
| 1267 | V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME); |
Philipp Zabel | f38f79d | 2014-07-11 06:36:28 -0300 | [diff] [blame] | 1268 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 1269 | V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB, 0, 1920 * 1088 / 256, 1, 0); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1270 | |
| 1271 | if (ctx->ctrls.error) { |
| 1272 | v4l2_err(&ctx->dev->v4l2_dev, "control initialization error (%d)", |
| 1273 | ctx->ctrls.error); |
| 1274 | return -EINVAL; |
| 1275 | } |
| 1276 | |
| 1277 | return v4l2_ctrl_handler_setup(&ctx->ctrls); |
| 1278 | } |
| 1279 | |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1280 | static int coda_queue_init(struct coda_ctx *ctx, struct vb2_queue *vq) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1281 | { |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1282 | vq->drv_priv = ctx; |
| 1283 | vq->ops = &coda_qops; |
| 1284 | vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); |
| 1285 | vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; |
| 1286 | vq->lock = &ctx->dev->dev_mutex; |
| 1287 | |
| 1288 | return vb2_queue_init(vq); |
| 1289 | } |
| 1290 | |
Philipp Zabel | 79924ca | 2014-07-23 12:28:45 -0300 | [diff] [blame] | 1291 | int coda_encoder_queue_init(void *priv, struct vb2_queue *src_vq, |
| 1292 | struct vb2_queue *dst_vq) |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1293 | { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1294 | int ret; |
| 1295 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1296 | src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; |
Philipp Zabel | d29a8cf | 2014-07-18 07:22:38 -0300 | [diff] [blame] | 1297 | src_vq->io_modes = VB2_DMABUF | VB2_MMAP; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1298 | src_vq->mem_ops = &vb2_dma_contig_memops; |
| 1299 | |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1300 | ret = coda_queue_init(priv, src_vq); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1301 | if (ret) |
| 1302 | return ret; |
| 1303 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1304 | dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Philipp Zabel | d29a8cf | 2014-07-18 07:22:38 -0300 | [diff] [blame] | 1305 | dst_vq->io_modes = VB2_DMABUF | VB2_MMAP; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1306 | dst_vq->mem_ops = &vb2_dma_contig_memops; |
| 1307 | |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1308 | return coda_queue_init(priv, dst_vq); |
| 1309 | } |
| 1310 | |
Philipp Zabel | 79924ca | 2014-07-23 12:28:45 -0300 | [diff] [blame] | 1311 | int coda_decoder_queue_init(void *priv, struct vb2_queue *src_vq, |
| 1312 | struct vb2_queue *dst_vq) |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1313 | { |
| 1314 | int ret; |
| 1315 | |
| 1316 | src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; |
| 1317 | src_vq->io_modes = VB2_DMABUF | VB2_MMAP; |
| 1318 | src_vq->mem_ops = &vb2_dma_contig_memops; |
| 1319 | |
| 1320 | ret = coda_queue_init(priv, src_vq); |
| 1321 | if (ret) |
| 1322 | return ret; |
| 1323 | |
| 1324 | dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1325 | dst_vq->io_modes = VB2_DMABUF | VB2_MMAP; |
| 1326 | dst_vq->mem_ops = &vb2_dma_contig_memops; |
| 1327 | |
| 1328 | return coda_queue_init(priv, dst_vq); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1329 | } |
| 1330 | |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 1331 | static int coda_next_free_instance(struct coda_dev *dev) |
| 1332 | { |
Philipp Zabel | 0cddc7e | 2013-09-30 10:34:44 -0300 | [diff] [blame] | 1333 | int idx = ffz(dev->instance_mask); |
| 1334 | |
| 1335 | if ((idx < 0) || |
| 1336 | (dev->devtype->product == CODA_DX6 && idx > CODADX6_MAX_INSTANCES)) |
| 1337 | return -EBUSY; |
| 1338 | |
| 1339 | return idx; |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 1340 | } |
| 1341 | |
Philipp Zabel | a1192a1 | 2014-07-23 12:28:40 -0300 | [diff] [blame] | 1342 | static int coda_open(struct file *file, enum coda_inst_type inst_type, |
| 1343 | const struct coda_context_ops *ctx_ops) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1344 | { |
| 1345 | struct coda_dev *dev = video_drvdata(file); |
| 1346 | struct coda_ctx *ctx = NULL; |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame] | 1347 | char *name; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1348 | int ret; |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 1349 | int idx; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1350 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1351 | ctx = kzalloc(sizeof *ctx, GFP_KERNEL); |
| 1352 | if (!ctx) |
| 1353 | return -ENOMEM; |
| 1354 | |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 1355 | idx = coda_next_free_instance(dev); |
Philipp Zabel | 0cddc7e | 2013-09-30 10:34:44 -0300 | [diff] [blame] | 1356 | if (idx < 0) { |
| 1357 | ret = idx; |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 1358 | goto err_coda_max; |
| 1359 | } |
| 1360 | set_bit(idx, &dev->instance_mask); |
| 1361 | |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame] | 1362 | name = kasprintf(GFP_KERNEL, "context%d", idx); |
| 1363 | ctx->debugfs_entry = debugfs_create_dir(name, dev->debugfs_root); |
| 1364 | kfree(name); |
| 1365 | |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1366 | ctx->inst_type = inst_type; |
Philipp Zabel | a1192a1 | 2014-07-23 12:28:40 -0300 | [diff] [blame] | 1367 | ctx->ops = ctx_ops; |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 1368 | init_completion(&ctx->completion); |
| 1369 | INIT_WORK(&ctx->pic_run_work, coda_pic_run_work); |
Philipp Zabel | a1192a1 | 2014-07-23 12:28:40 -0300 | [diff] [blame] | 1370 | INIT_WORK(&ctx->seq_end_work, ctx->ops->seq_end_work); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1371 | v4l2_fh_init(&ctx->fh, video_devdata(file)); |
| 1372 | file->private_data = &ctx->fh; |
| 1373 | v4l2_fh_add(&ctx->fh); |
| 1374 | ctx->dev = dev; |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 1375 | ctx->idx = idx; |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1376 | switch (dev->devtype->product) { |
| 1377 | case CODA_7541: |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1378 | case CODA_960: |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1379 | ctx->reg_idx = 0; |
| 1380 | break; |
| 1381 | default: |
| 1382 | ctx->reg_idx = idx; |
| 1383 | } |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 1384 | |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 1385 | /* Power up and upload firmware if necessary */ |
| 1386 | ret = pm_runtime_get_sync(&dev->plat_dev->dev); |
| 1387 | if (ret < 0) { |
| 1388 | v4l2_err(&dev->v4l2_dev, "failed to power up: %d\n", ret); |
| 1389 | goto err_pm_get; |
| 1390 | } |
| 1391 | |
Fabio Estevam | 79830db | 2013-08-21 11:14:17 -0300 | [diff] [blame] | 1392 | ret = clk_prepare_enable(dev->clk_per); |
| 1393 | if (ret) |
| 1394 | goto err_clk_per; |
| 1395 | |
| 1396 | ret = clk_prepare_enable(dev->clk_ahb); |
| 1397 | if (ret) |
| 1398 | goto err_clk_ahb; |
| 1399 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1400 | set_default_params(ctx); |
Philipp Zabel | a1192a1 | 2014-07-23 12:28:40 -0300 | [diff] [blame] | 1401 | ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, |
| 1402 | ctx->ops->queue_init); |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 1403 | if (IS_ERR(ctx->fh.m2m_ctx)) { |
| 1404 | ret = PTR_ERR(ctx->fh.m2m_ctx); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1405 | |
| 1406 | v4l2_err(&dev->v4l2_dev, "%s return error (%d)\n", |
| 1407 | __func__, ret); |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 1408 | goto err_ctx_init; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1409 | } |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 1410 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1411 | ret = coda_ctrls_setup(ctx); |
| 1412 | if (ret) { |
| 1413 | v4l2_err(&dev->v4l2_dev, "failed to setup coda controls\n"); |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 1414 | goto err_ctrls_setup; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | ctx->fh.ctrl_handler = &ctx->ctrls; |
| 1418 | |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame] | 1419 | ret = coda_alloc_context_buf(ctx, &ctx->parabuf, CODA_PARA_BUF_SIZE, |
| 1420 | "parabuf"); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1421 | if (ret < 0) { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1422 | v4l2_err(&dev->v4l2_dev, "failed to allocate parabuf"); |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 1423 | goto err_dma_alloc; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1424 | } |
| 1425 | |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 1426 | ctx->bitstream.size = CODA_MAX_FRAME_SIZE; |
| 1427 | ctx->bitstream.vaddr = dma_alloc_writecombine(&dev->plat_dev->dev, |
| 1428 | ctx->bitstream.size, &ctx->bitstream.paddr, GFP_KERNEL); |
| 1429 | if (!ctx->bitstream.vaddr) { |
| 1430 | v4l2_err(&dev->v4l2_dev, "failed to allocate bitstream ringbuffer"); |
| 1431 | ret = -ENOMEM; |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 1432 | goto err_dma_writecombine; |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 1433 | } |
| 1434 | kfifo_init(&ctx->bitstream_fifo, |
| 1435 | ctx->bitstream.vaddr, ctx->bitstream.size); |
| 1436 | mutex_init(&ctx->bitstream_mutex); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1437 | mutex_init(&ctx->buffer_mutex); |
Philipp Zabel | 846ced9 | 2014-07-11 06:36:31 -0300 | [diff] [blame] | 1438 | INIT_LIST_HEAD(&ctx->timestamp_list); |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 1439 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1440 | coda_lock(ctx); |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 1441 | list_add(&ctx->list, &dev->instances); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1442 | coda_unlock(ctx); |
| 1443 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1444 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Created instance %d (%p)\n", |
| 1445 | ctx->idx, ctx); |
| 1446 | |
| 1447 | return 0; |
| 1448 | |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 1449 | err_dma_writecombine: |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 1450 | if (ctx->dev->devtype->product == CODA_DX6) |
| 1451 | coda_free_aux_buf(dev, &ctx->workbuf); |
| 1452 | coda_free_aux_buf(dev, &ctx->parabuf); |
| 1453 | err_dma_alloc: |
| 1454 | v4l2_ctrl_handler_free(&ctx->ctrls); |
| 1455 | err_ctrls_setup: |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 1456 | v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 1457 | err_ctx_init: |
| 1458 | clk_disable_unprepare(dev->clk_ahb); |
Fabio Estevam | 79830db | 2013-08-21 11:14:17 -0300 | [diff] [blame] | 1459 | err_clk_ahb: |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 1460 | clk_disable_unprepare(dev->clk_per); |
Fabio Estevam | 79830db | 2013-08-21 11:14:17 -0300 | [diff] [blame] | 1461 | err_clk_per: |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 1462 | pm_runtime_put_sync(&dev->plat_dev->dev); |
| 1463 | err_pm_get: |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1464 | v4l2_fh_del(&ctx->fh); |
| 1465 | v4l2_fh_exit(&ctx->fh); |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 1466 | clear_bit(ctx->idx, &dev->instance_mask); |
| 1467 | err_coda_max: |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1468 | kfree(ctx); |
| 1469 | return ret; |
| 1470 | } |
| 1471 | |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1472 | static int coda_encoder_open(struct file *file) |
| 1473 | { |
Philipp Zabel | 79924ca | 2014-07-23 12:28:45 -0300 | [diff] [blame] | 1474 | return coda_open(file, CODA_INST_ENCODER, &coda_bit_encode_ops); |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | static int coda_decoder_open(struct file *file) |
| 1478 | { |
Philipp Zabel | 79924ca | 2014-07-23 12:28:45 -0300 | [diff] [blame] | 1479 | return coda_open(file, CODA_INST_DECODER, &coda_bit_decode_ops); |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1480 | } |
| 1481 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1482 | static int coda_release(struct file *file) |
| 1483 | { |
| 1484 | struct coda_dev *dev = video_drvdata(file); |
| 1485 | struct coda_ctx *ctx = fh_to_ctx(file->private_data); |
| 1486 | |
| 1487 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Releasing instance %p\n", |
| 1488 | ctx); |
| 1489 | |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame] | 1490 | debugfs_remove_recursive(ctx->debugfs_entry); |
| 1491 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1492 | /* If this instance is running, call .job_abort and wait for it to end */ |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 1493 | v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1494 | |
| 1495 | /* In case the instance was not running, we still need to call SEQ_END */ |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 1496 | if (ctx->initialized) { |
| 1497 | queue_work(dev->workqueue, &ctx->seq_end_work); |
| 1498 | flush_work(&ctx->seq_end_work); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1499 | } |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1500 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1501 | coda_lock(ctx); |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 1502 | list_del(&ctx->list); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1503 | coda_unlock(ctx); |
| 1504 | |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 1505 | dma_free_writecombine(&dev->plat_dev->dev, ctx->bitstream.size, |
| 1506 | ctx->bitstream.vaddr, ctx->bitstream.paddr); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1507 | if (ctx->dev->devtype->product == CODA_DX6) |
| 1508 | coda_free_aux_buf(dev, &ctx->workbuf); |
| 1509 | |
| 1510 | coda_free_aux_buf(dev, &ctx->parabuf); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1511 | v4l2_ctrl_handler_free(&ctx->ctrls); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1512 | clk_disable_unprepare(dev->clk_ahb); |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 1513 | clk_disable_unprepare(dev->clk_per); |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 1514 | pm_runtime_put_sync(&dev->plat_dev->dev); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1515 | v4l2_fh_del(&ctx->fh); |
| 1516 | v4l2_fh_exit(&ctx->fh); |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 1517 | clear_bit(ctx->idx, &dev->instance_mask); |
Philipp Zabel | 58b7677 | 2014-07-23 12:28:43 -0300 | [diff] [blame] | 1518 | if (ctx->ops->release) |
| 1519 | ctx->ops->release(ctx); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1520 | kfree(ctx); |
| 1521 | |
| 1522 | return 0; |
| 1523 | } |
| 1524 | |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1525 | static const struct v4l2_file_operations coda_encoder_fops = { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1526 | .owner = THIS_MODULE, |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1527 | .open = coda_encoder_open, |
| 1528 | .release = coda_release, |
| 1529 | .poll = v4l2_m2m_fop_poll, |
| 1530 | .unlocked_ioctl = video_ioctl2, |
| 1531 | .mmap = v4l2_m2m_fop_mmap, |
| 1532 | }; |
| 1533 | |
| 1534 | static const struct v4l2_file_operations coda_decoder_fops = { |
| 1535 | .owner = THIS_MODULE, |
| 1536 | .open = coda_decoder_open, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1537 | .release = coda_release, |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 1538 | .poll = v4l2_m2m_fop_poll, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1539 | .unlocked_ioctl = video_ioctl2, |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 1540 | .mmap = v4l2_m2m_fop_mmap, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1541 | }; |
| 1542 | |
Philipp Zabel | 87048bb | 2012-07-02 07:03:43 -0300 | [diff] [blame] | 1543 | static int coda_hw_init(struct coda_dev *dev) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1544 | { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1545 | u32 data; |
| 1546 | u16 *p; |
Fabio Estevam | 79830db | 2013-08-21 11:14:17 -0300 | [diff] [blame] | 1547 | int i, ret; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1548 | |
Fabio Estevam | 79830db | 2013-08-21 11:14:17 -0300 | [diff] [blame] | 1549 | ret = clk_prepare_enable(dev->clk_per); |
| 1550 | if (ret) |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 1551 | goto err_clk_per; |
Fabio Estevam | 79830db | 2013-08-21 11:14:17 -0300 | [diff] [blame] | 1552 | |
| 1553 | ret = clk_prepare_enable(dev->clk_ahb); |
| 1554 | if (ret) |
| 1555 | goto err_clk_ahb; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1556 | |
Philipp Zabel | 8f45284 | 2014-07-11 06:36:35 -0300 | [diff] [blame] | 1557 | if (dev->rstc) |
| 1558 | reset_control_reset(dev->rstc); |
| 1559 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1560 | /* |
| 1561 | * Copy the first CODA_ISRAM_SIZE in the internal SRAM. |
Philipp Zabel | 87048bb | 2012-07-02 07:03:43 -0300 | [diff] [blame] | 1562 | * The 16-bit chars in the code buffer are in memory access |
| 1563 | * order, re-sort them to CODA order for register download. |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1564 | * Data in this SRAM survives a reboot. |
| 1565 | */ |
Philipp Zabel | 87048bb | 2012-07-02 07:03:43 -0300 | [diff] [blame] | 1566 | p = (u16 *)dev->codebuf.vaddr; |
| 1567 | if (dev->devtype->product == CODA_DX6) { |
| 1568 | for (i = 0; i < (CODA_ISRAM_SIZE / 2); i++) { |
| 1569 | data = CODA_DOWN_ADDRESS_SET(i) | |
| 1570 | CODA_DOWN_DATA_SET(p[i ^ 1]); |
| 1571 | coda_write(dev, data, CODA_REG_BIT_CODE_DOWN); |
| 1572 | } |
| 1573 | } else { |
| 1574 | for (i = 0; i < (CODA_ISRAM_SIZE / 2); i++) { |
| 1575 | data = CODA_DOWN_ADDRESS_SET(i) | |
| 1576 | CODA_DOWN_DATA_SET(p[round_down(i, 4) + |
| 1577 | 3 - (i % 4)]); |
| 1578 | coda_write(dev, data, CODA_REG_BIT_CODE_DOWN); |
| 1579 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1580 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1581 | |
Philipp Zabel | 9acf769 | 2013-05-23 10:42:56 -0300 | [diff] [blame] | 1582 | /* Clear registers */ |
| 1583 | for (i = 0; i < 64; i++) |
| 1584 | coda_write(dev, 0, CODA_REG_BIT_CODE_BUF_ADDR + i * 4); |
| 1585 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1586 | /* Tell the BIT where to find everything it needs */ |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1587 | if (dev->devtype->product == CODA_960 || |
| 1588 | dev->devtype->product == CODA_7541) { |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1589 | coda_write(dev, dev->tempbuf.paddr, |
| 1590 | CODA_REG_BIT_TEMP_BUF_ADDR); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1591 | coda_write(dev, 0, CODA_REG_BIT_BIT_STREAM_PARAM); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1592 | } else { |
| 1593 | coda_write(dev, dev->workbuf.paddr, |
| 1594 | CODA_REG_BIT_WORK_BUF_ADDR); |
| 1595 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1596 | coda_write(dev, dev->codebuf.paddr, |
| 1597 | CODA_REG_BIT_CODE_BUF_ADDR); |
| 1598 | coda_write(dev, 0, CODA_REG_BIT_CODE_RUN); |
| 1599 | |
| 1600 | /* Set default values */ |
| 1601 | switch (dev->devtype->product) { |
| 1602 | case CODA_DX6: |
| 1603 | coda_write(dev, CODADX6_STREAM_BUF_PIC_FLUSH, CODA_REG_BIT_STREAM_CTRL); |
| 1604 | break; |
| 1605 | default: |
| 1606 | coda_write(dev, CODA7_STREAM_BUF_PIC_FLUSH, CODA_REG_BIT_STREAM_CTRL); |
| 1607 | } |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1608 | if (dev->devtype->product == CODA_960) |
| 1609 | coda_write(dev, 1 << 12, CODA_REG_BIT_FRAME_MEM_CTRL); |
| 1610 | else |
| 1611 | coda_write(dev, 0, CODA_REG_BIT_FRAME_MEM_CTRL); |
Philipp Zabel | 1043667 | 2012-07-02 09:03:55 -0300 | [diff] [blame] | 1612 | |
| 1613 | if (dev->devtype->product != CODA_DX6) |
| 1614 | coda_write(dev, 0, CODA7_REG_BIT_AXI_SRAM_USE); |
| 1615 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1616 | coda_write(dev, CODA_INT_INTERRUPT_ENABLE, |
| 1617 | CODA_REG_BIT_INT_ENABLE); |
| 1618 | |
| 1619 | /* Reset VPU and start processor */ |
| 1620 | data = coda_read(dev, CODA_REG_BIT_CODE_RESET); |
| 1621 | data |= CODA_REG_RESET_ENABLE; |
| 1622 | coda_write(dev, data, CODA_REG_BIT_CODE_RESET); |
| 1623 | udelay(10); |
| 1624 | data &= ~CODA_REG_RESET_ENABLE; |
| 1625 | coda_write(dev, data, CODA_REG_BIT_CODE_RESET); |
| 1626 | coda_write(dev, CODA_REG_RUN_ENABLE, CODA_REG_BIT_CODE_RUN); |
| 1627 | |
Philipp Zabel | fe7554e | 2014-07-11 06:36:24 -0300 | [diff] [blame] | 1628 | clk_disable_unprepare(dev->clk_ahb); |
| 1629 | clk_disable_unprepare(dev->clk_per); |
| 1630 | |
| 1631 | return 0; |
| 1632 | |
| 1633 | err_clk_ahb: |
| 1634 | clk_disable_unprepare(dev->clk_per); |
| 1635 | err_clk_per: |
| 1636 | return ret; |
| 1637 | } |
| 1638 | |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1639 | static int coda_register_device(struct coda_dev *dev, struct video_device *vfd) |
| 1640 | { |
| 1641 | vfd->release = video_device_release_empty, |
| 1642 | vfd->lock = &dev->dev_mutex; |
| 1643 | vfd->v4l2_dev = &dev->v4l2_dev; |
| 1644 | vfd->vfl_dir = VFL_DIR_M2M; |
| 1645 | video_set_drvdata(vfd, dev); |
| 1646 | |
| 1647 | return video_register_device(vfd, VFL_TYPE_GRABBER, 0); |
| 1648 | } |
| 1649 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1650 | static void coda_fw_callback(const struct firmware *fw, void *context) |
| 1651 | { |
| 1652 | struct coda_dev *dev = context; |
| 1653 | struct platform_device *pdev = dev->plat_dev; |
| 1654 | int ret; |
| 1655 | |
| 1656 | if (!fw) { |
| 1657 | v4l2_err(&dev->v4l2_dev, "firmware request failed\n"); |
| 1658 | return; |
| 1659 | } |
| 1660 | |
| 1661 | /* allocate auxiliary per-device code buffer for the BIT processor */ |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame] | 1662 | ret = coda_alloc_aux_buf(dev, &dev->codebuf, fw->size, "codebuf", |
| 1663 | dev->debugfs_root); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1664 | if (ret < 0) { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1665 | dev_err(&pdev->dev, "failed to allocate code buffer\n"); |
| 1666 | return; |
| 1667 | } |
| 1668 | |
Philipp Zabel | 87048bb | 2012-07-02 07:03:43 -0300 | [diff] [blame] | 1669 | /* Copy the whole firmware image to the code buffer */ |
| 1670 | memcpy(dev->codebuf.vaddr, fw->data, fw->size); |
| 1671 | release_firmware(fw); |
| 1672 | |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 1673 | if (pm_runtime_enabled(&pdev->dev) && pdev->dev.pm_domain) { |
| 1674 | /* |
| 1675 | * Enabling power temporarily will cause coda_hw_init to be |
| 1676 | * called via coda_runtime_resume by the pm domain. |
| 1677 | */ |
| 1678 | ret = pm_runtime_get_sync(&dev->plat_dev->dev); |
| 1679 | if (ret < 0) { |
| 1680 | v4l2_err(&dev->v4l2_dev, "failed to power on: %d\n", |
| 1681 | ret); |
| 1682 | return; |
| 1683 | } |
| 1684 | |
Philipp Zabel | fe7554e | 2014-07-11 06:36:24 -0300 | [diff] [blame] | 1685 | ret = coda_check_firmware(dev); |
| 1686 | if (ret < 0) |
| 1687 | return; |
| 1688 | |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 1689 | pm_runtime_put_sync(&dev->plat_dev->dev); |
| 1690 | } else { |
| 1691 | /* |
| 1692 | * If runtime pm is disabled or pm_domain is not set, |
| 1693 | * initialize once manually. |
| 1694 | */ |
| 1695 | ret = coda_hw_init(dev); |
| 1696 | if (ret < 0) { |
| 1697 | v4l2_err(&dev->v4l2_dev, "HW initialization failed\n"); |
| 1698 | return; |
| 1699 | } |
Philipp Zabel | fe7554e | 2014-07-11 06:36:24 -0300 | [diff] [blame] | 1700 | |
| 1701 | ret = coda_check_firmware(dev); |
| 1702 | if (ret < 0) |
| 1703 | return; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1704 | } |
| 1705 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1706 | dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); |
| 1707 | if (IS_ERR(dev->alloc_ctx)) { |
| 1708 | v4l2_err(&dev->v4l2_dev, "Failed to alloc vb2 context\n"); |
| 1709 | return; |
| 1710 | } |
| 1711 | |
| 1712 | dev->m2m_dev = v4l2_m2m_init(&coda_m2m_ops); |
| 1713 | if (IS_ERR(dev->m2m_dev)) { |
| 1714 | v4l2_err(&dev->v4l2_dev, "Failed to init mem2mem device\n"); |
| 1715 | goto rel_ctx; |
| 1716 | } |
| 1717 | |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1718 | dev->vfd[0].fops = &coda_encoder_fops, |
| 1719 | dev->vfd[0].ioctl_ops = &coda_ioctl_ops; |
| 1720 | snprintf(dev->vfd[0].name, sizeof(dev->vfd[0].name), "coda-encoder"); |
| 1721 | ret = coda_register_device(dev, &dev->vfd[0]); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1722 | if (ret) { |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1723 | v4l2_err(&dev->v4l2_dev, |
| 1724 | "Failed to register encoder video device\n"); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1725 | goto rel_m2m; |
| 1726 | } |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1727 | |
| 1728 | dev->vfd[1].fops = &coda_decoder_fops, |
| 1729 | dev->vfd[1].ioctl_ops = &coda_ioctl_ops; |
| 1730 | snprintf(dev->vfd[1].name, sizeof(dev->vfd[1].name), "coda-decoder"); |
| 1731 | ret = coda_register_device(dev, &dev->vfd[1]); |
| 1732 | if (ret) { |
| 1733 | v4l2_err(&dev->v4l2_dev, |
| 1734 | "Failed to register decoder video device\n"); |
| 1735 | goto rel_m2m; |
| 1736 | } |
| 1737 | |
| 1738 | v4l2_info(&dev->v4l2_dev, "codec registered as /dev/video[%d-%d]\n", |
| 1739 | dev->vfd[0].num, dev->vfd[1].num); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1740 | |
| 1741 | return; |
| 1742 | |
| 1743 | rel_m2m: |
| 1744 | v4l2_m2m_release(dev->m2m_dev); |
| 1745 | rel_ctx: |
| 1746 | vb2_dma_contig_cleanup_ctx(dev->alloc_ctx); |
| 1747 | } |
| 1748 | |
| 1749 | static int coda_firmware_request(struct coda_dev *dev) |
| 1750 | { |
| 1751 | char *fw = dev->devtype->firmware; |
| 1752 | |
| 1753 | dev_dbg(&dev->plat_dev->dev, "requesting firmware '%s' for %s\n", fw, |
| 1754 | coda_product_name(dev->devtype->product)); |
| 1755 | |
| 1756 | return request_firmware_nowait(THIS_MODULE, true, |
| 1757 | fw, &dev->plat_dev->dev, GFP_KERNEL, dev, coda_fw_callback); |
| 1758 | } |
| 1759 | |
| 1760 | enum coda_platform { |
| 1761 | CODA_IMX27, |
Philipp Zabel | df1e74c | 2012-07-02 06:07:10 -0300 | [diff] [blame] | 1762 | CODA_IMX53, |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1763 | CODA_IMX6Q, |
| 1764 | CODA_IMX6DL, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1765 | }; |
| 1766 | |
Emil Goode | c06d875 | 2012-08-14 17:44:42 -0300 | [diff] [blame] | 1767 | static const struct coda_devtype coda_devdata[] = { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1768 | [CODA_IMX27] = { |
Philipp Zabel | e5b0d1c | 2014-07-11 06:36:41 -0300 | [diff] [blame] | 1769 | .firmware = "v4l-codadx6-imx27.bin", |
| 1770 | .product = CODA_DX6, |
| 1771 | .codecs = codadx6_codecs, |
| 1772 | .num_codecs = ARRAY_SIZE(codadx6_codecs), |
| 1773 | .workbuf_size = 288 * 1024 + FMO_SLICE_SAVE_BUF_SIZE * 8 * 1024, |
Philipp Zabel | 401e972 | 2014-07-11 06:36:43 -0300 | [diff] [blame] | 1774 | .iram_size = 0xb000, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1775 | }, |
Philipp Zabel | df1e74c | 2012-07-02 06:07:10 -0300 | [diff] [blame] | 1776 | [CODA_IMX53] = { |
Philipp Zabel | e5b0d1c | 2014-07-11 06:36:41 -0300 | [diff] [blame] | 1777 | .firmware = "v4l-coda7541-imx53.bin", |
| 1778 | .product = CODA_7541, |
| 1779 | .codecs = coda7_codecs, |
| 1780 | .num_codecs = ARRAY_SIZE(coda7_codecs), |
| 1781 | .workbuf_size = 128 * 1024, |
Philipp Zabel | 5d73fad | 2014-07-11 06:36:42 -0300 | [diff] [blame] | 1782 | .tempbuf_size = 304 * 1024, |
Philipp Zabel | 401e972 | 2014-07-11 06:36:43 -0300 | [diff] [blame] | 1783 | .iram_size = 0x14000, |
Philipp Zabel | df1e74c | 2012-07-02 06:07:10 -0300 | [diff] [blame] | 1784 | }, |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1785 | [CODA_IMX6Q] = { |
Philipp Zabel | e5b0d1c | 2014-07-11 06:36:41 -0300 | [diff] [blame] | 1786 | .firmware = "v4l-coda960-imx6q.bin", |
| 1787 | .product = CODA_960, |
| 1788 | .codecs = coda9_codecs, |
| 1789 | .num_codecs = ARRAY_SIZE(coda9_codecs), |
| 1790 | .workbuf_size = 80 * 1024, |
Philipp Zabel | 5d73fad | 2014-07-11 06:36:42 -0300 | [diff] [blame] | 1791 | .tempbuf_size = 204 * 1024, |
Philipp Zabel | 401e972 | 2014-07-11 06:36:43 -0300 | [diff] [blame] | 1792 | .iram_size = 0x21000, |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1793 | }, |
| 1794 | [CODA_IMX6DL] = { |
Philipp Zabel | e5b0d1c | 2014-07-11 06:36:41 -0300 | [diff] [blame] | 1795 | .firmware = "v4l-coda960-imx6dl.bin", |
| 1796 | .product = CODA_960, |
| 1797 | .codecs = coda9_codecs, |
| 1798 | .num_codecs = ARRAY_SIZE(coda9_codecs), |
| 1799 | .workbuf_size = 80 * 1024, |
Philipp Zabel | 5d73fad | 2014-07-11 06:36:42 -0300 | [diff] [blame] | 1800 | .tempbuf_size = 204 * 1024, |
Philipp Zabel | 401e972 | 2014-07-11 06:36:43 -0300 | [diff] [blame] | 1801 | .iram_size = 0x20000, |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1802 | }, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1803 | }; |
| 1804 | |
| 1805 | static struct platform_device_id coda_platform_ids[] = { |
| 1806 | { .name = "coda-imx27", .driver_data = CODA_IMX27 }, |
Fabio Estevam | 4e44cd0 | 2012-10-10 00:07:38 -0300 | [diff] [blame] | 1807 | { .name = "coda-imx53", .driver_data = CODA_IMX53 }, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1808 | { /* sentinel */ } |
| 1809 | }; |
| 1810 | MODULE_DEVICE_TABLE(platform, coda_platform_ids); |
| 1811 | |
| 1812 | #ifdef CONFIG_OF |
| 1813 | static const struct of_device_id coda_dt_ids[] = { |
Alexander Shiyan | 7b0dd9e | 2013-06-15 08:09:57 -0300 | [diff] [blame] | 1814 | { .compatible = "fsl,imx27-vpu", .data = &coda_devdata[CODA_IMX27] }, |
Philipp Zabel | df1e74c | 2012-07-02 06:07:10 -0300 | [diff] [blame] | 1815 | { .compatible = "fsl,imx53-vpu", .data = &coda_devdata[CODA_IMX53] }, |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1816 | { .compatible = "fsl,imx6q-vpu", .data = &coda_devdata[CODA_IMX6Q] }, |
| 1817 | { .compatible = "fsl,imx6dl-vpu", .data = &coda_devdata[CODA_IMX6DL] }, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1818 | { /* sentinel */ } |
| 1819 | }; |
| 1820 | MODULE_DEVICE_TABLE(of, coda_dt_ids); |
| 1821 | #endif |
| 1822 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1823 | static int coda_probe(struct platform_device *pdev) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1824 | { |
| 1825 | const struct of_device_id *of_id = |
| 1826 | of_match_device(of_match_ptr(coda_dt_ids), &pdev->dev); |
| 1827 | const struct platform_device_id *pdev_id; |
Philipp Zabel | 657eee7 | 2013-04-29 16:17:14 -0700 | [diff] [blame] | 1828 | struct coda_platform_data *pdata = pdev->dev.platform_data; |
| 1829 | struct device_node *np = pdev->dev.of_node; |
| 1830 | struct gen_pool *pool; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1831 | struct coda_dev *dev; |
| 1832 | struct resource *res; |
| 1833 | int ret, irq; |
| 1834 | |
| 1835 | dev = devm_kzalloc(&pdev->dev, sizeof *dev, GFP_KERNEL); |
| 1836 | if (!dev) { |
| 1837 | dev_err(&pdev->dev, "Not enough memory for %s\n", |
| 1838 | CODA_NAME); |
| 1839 | return -ENOMEM; |
| 1840 | } |
| 1841 | |
| 1842 | spin_lock_init(&dev->irqlock); |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 1843 | INIT_LIST_HEAD(&dev->instances); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1844 | |
| 1845 | dev->plat_dev = pdev; |
| 1846 | dev->clk_per = devm_clk_get(&pdev->dev, "per"); |
| 1847 | if (IS_ERR(dev->clk_per)) { |
| 1848 | dev_err(&pdev->dev, "Could not get per clock\n"); |
| 1849 | return PTR_ERR(dev->clk_per); |
| 1850 | } |
| 1851 | |
| 1852 | dev->clk_ahb = devm_clk_get(&pdev->dev, "ahb"); |
| 1853 | if (IS_ERR(dev->clk_ahb)) { |
| 1854 | dev_err(&pdev->dev, "Could not get ahb clock\n"); |
| 1855 | return PTR_ERR(dev->clk_ahb); |
| 1856 | } |
| 1857 | |
| 1858 | /* Get memory for physical registers */ |
| 1859 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Philipp Zabel | 611cbbf | 2013-05-21 04:19:27 -0300 | [diff] [blame] | 1860 | dev->regs_base = devm_ioremap_resource(&pdev->dev, res); |
| 1861 | if (IS_ERR(dev->regs_base)) |
| 1862 | return PTR_ERR(dev->regs_base); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1863 | |
| 1864 | /* IRQ */ |
Philipp Zabel | 540b72e | 2014-08-05 14:00:09 -0300 | [diff] [blame] | 1865 | irq = platform_get_irq_byname(pdev, "bit"); |
| 1866 | if (irq < 0) |
| 1867 | irq = platform_get_irq(pdev, 0); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1868 | if (irq < 0) { |
| 1869 | dev_err(&pdev->dev, "failed to get irq resource\n"); |
Fabio Estevam | 7d37743 | 2014-06-04 15:46:23 -0300 | [diff] [blame] | 1870 | return irq; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1871 | } |
| 1872 | |
Fabio Estevam | 08c8d14 | 2014-06-04 15:46:24 -0300 | [diff] [blame] | 1873 | ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, coda_irq_handler, |
| 1874 | IRQF_ONESHOT, dev_name(&pdev->dev), dev); |
| 1875 | if (ret < 0) { |
| 1876 | dev_err(&pdev->dev, "failed to request irq: %d\n", ret); |
| 1877 | return ret; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1878 | } |
| 1879 | |
Philipp Zabel | ee27aa9 | 2014-07-24 16:50:03 -0300 | [diff] [blame] | 1880 | dev->rstc = devm_reset_control_get_optional(&pdev->dev, NULL); |
Philipp Zabel | 8f45284 | 2014-07-11 06:36:35 -0300 | [diff] [blame] | 1881 | if (IS_ERR(dev->rstc)) { |
| 1882 | ret = PTR_ERR(dev->rstc); |
Philipp Zabel | ee27aa9 | 2014-07-24 16:50:03 -0300 | [diff] [blame] | 1883 | if (ret == -ENOENT || ret == -ENOSYS) { |
Philipp Zabel | 8f45284 | 2014-07-11 06:36:35 -0300 | [diff] [blame] | 1884 | dev->rstc = NULL; |
| 1885 | } else { |
| 1886 | dev_err(&pdev->dev, "failed get reset control: %d\n", ret); |
| 1887 | return ret; |
| 1888 | } |
| 1889 | } |
| 1890 | |
Philipp Zabel | 657eee7 | 2013-04-29 16:17:14 -0700 | [diff] [blame] | 1891 | /* Get IRAM pool from device tree or platform data */ |
| 1892 | pool = of_get_named_gen_pool(np, "iram", 0); |
| 1893 | if (!pool && pdata) |
| 1894 | pool = dev_get_gen_pool(pdata->iram_dev); |
| 1895 | if (!pool) { |
| 1896 | dev_err(&pdev->dev, "iram pool not available\n"); |
| 1897 | return -ENOMEM; |
| 1898 | } |
| 1899 | dev->iram_pool = pool; |
| 1900 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1901 | ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev); |
| 1902 | if (ret) |
| 1903 | return ret; |
| 1904 | |
| 1905 | mutex_init(&dev->dev_mutex); |
Philipp Zabel | fcb6282 | 2013-05-23 10:43:00 -0300 | [diff] [blame] | 1906 | mutex_init(&dev->coda_mutex); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1907 | |
| 1908 | pdev_id = of_id ? of_id->data : platform_get_device_id(pdev); |
| 1909 | |
| 1910 | if (of_id) { |
| 1911 | dev->devtype = of_id->data; |
| 1912 | } else if (pdev_id) { |
| 1913 | dev->devtype = &coda_devdata[pdev_id->driver_data]; |
| 1914 | } else { |
| 1915 | v4l2_device_unregister(&dev->v4l2_dev); |
| 1916 | return -EINVAL; |
| 1917 | } |
| 1918 | |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame] | 1919 | dev->debugfs_root = debugfs_create_dir("coda", NULL); |
| 1920 | if (!dev->debugfs_root) |
| 1921 | dev_warn(&pdev->dev, "failed to create debugfs root\n"); |
| 1922 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1923 | /* allocate auxiliary per-device buffers for the BIT processor */ |
Philipp Zabel | 5d73fad | 2014-07-11 06:36:42 -0300 | [diff] [blame] | 1924 | if (dev->devtype->product == CODA_DX6) { |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1925 | ret = coda_alloc_aux_buf(dev, &dev->workbuf, |
Philipp Zabel | e5b0d1c | 2014-07-11 06:36:41 -0300 | [diff] [blame] | 1926 | dev->devtype->workbuf_size, "workbuf", |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame] | 1927 | dev->debugfs_root); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1928 | if (ret < 0) { |
| 1929 | dev_err(&pdev->dev, "failed to allocate work buffer\n"); |
| 1930 | v4l2_device_unregister(&dev->v4l2_dev); |
| 1931 | return ret; |
| 1932 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1933 | } |
Philipp Zabel | 5d73fad | 2014-07-11 06:36:42 -0300 | [diff] [blame] | 1934 | |
| 1935 | if (dev->devtype->tempbuf_size) { |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1936 | ret = coda_alloc_aux_buf(dev, &dev->tempbuf, |
Philipp Zabel | 5d73fad | 2014-07-11 06:36:42 -0300 | [diff] [blame] | 1937 | dev->devtype->tempbuf_size, "tempbuf", |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame] | 1938 | dev->debugfs_root); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1939 | if (ret < 0) { |
| 1940 | dev_err(&pdev->dev, "failed to allocate temp buffer\n"); |
| 1941 | v4l2_device_unregister(&dev->v4l2_dev); |
| 1942 | return ret; |
| 1943 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1944 | } |
| 1945 | |
Philipp Zabel | 401e972 | 2014-07-11 06:36:43 -0300 | [diff] [blame] | 1946 | dev->iram.size = dev->devtype->iram_size; |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1947 | dev->iram.vaddr = gen_pool_dma_alloc(dev->iram_pool, dev->iram.size, |
| 1948 | &dev->iram.paddr); |
| 1949 | if (!dev->iram.vaddr) { |
Philipp Zabel | 8be31c8 | 2014-08-05 14:00:13 -0300 | [diff] [blame^] | 1950 | dev_warn(&pdev->dev, "unable to alloc iram\n"); |
| 1951 | } else { |
| 1952 | dev->iram.blob.data = dev->iram.vaddr; |
| 1953 | dev->iram.blob.size = dev->iram.size; |
| 1954 | dev->iram.dentry = debugfs_create_blob("iram", 0644, |
| 1955 | dev->debugfs_root, |
| 1956 | &dev->iram.blob); |
Philipp Zabel | 1043667 | 2012-07-02 09:03:55 -0300 | [diff] [blame] | 1957 | } |
| 1958 | |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 1959 | dev->workqueue = alloc_workqueue("coda", WQ_UNBOUND | WQ_MEM_RECLAIM, 1); |
| 1960 | if (!dev->workqueue) { |
| 1961 | dev_err(&pdev->dev, "unable to alloc workqueue\n"); |
| 1962 | return -ENOMEM; |
| 1963 | } |
| 1964 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1965 | platform_set_drvdata(pdev, dev); |
| 1966 | |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 1967 | pm_runtime_enable(&pdev->dev); |
| 1968 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1969 | return coda_firmware_request(dev); |
| 1970 | } |
| 1971 | |
| 1972 | static int coda_remove(struct platform_device *pdev) |
| 1973 | { |
| 1974 | struct coda_dev *dev = platform_get_drvdata(pdev); |
| 1975 | |
Philipp Zabel | 121cacf | 2014-07-18 07:22:42 -0300 | [diff] [blame] | 1976 | video_unregister_device(&dev->vfd[0]); |
| 1977 | video_unregister_device(&dev->vfd[1]); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1978 | if (dev->m2m_dev) |
| 1979 | v4l2_m2m_release(dev->m2m_dev); |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 1980 | pm_runtime_disable(&pdev->dev); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1981 | if (dev->alloc_ctx) |
| 1982 | vb2_dma_contig_cleanup_ctx(dev->alloc_ctx); |
| 1983 | v4l2_device_unregister(&dev->v4l2_dev); |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 1984 | destroy_workqueue(dev->workqueue); |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1985 | if (dev->iram.vaddr) |
| 1986 | gen_pool_free(dev->iram_pool, (unsigned long)dev->iram.vaddr, |
| 1987 | dev->iram.size); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1988 | coda_free_aux_buf(dev, &dev->codebuf); |
| 1989 | coda_free_aux_buf(dev, &dev->tempbuf); |
| 1990 | coda_free_aux_buf(dev, &dev->workbuf); |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame] | 1991 | debugfs_remove_recursive(dev->debugfs_root); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1992 | return 0; |
| 1993 | } |
| 1994 | |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 1995 | #ifdef CONFIG_PM_RUNTIME |
| 1996 | static int coda_runtime_resume(struct device *dev) |
| 1997 | { |
| 1998 | struct coda_dev *cdev = dev_get_drvdata(dev); |
| 1999 | int ret = 0; |
| 2000 | |
Philipp Zabel | 65919e6 | 2014-07-18 07:22:36 -0300 | [diff] [blame] | 2001 | if (dev->pm_domain && cdev->codebuf.vaddr) { |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 2002 | ret = coda_hw_init(cdev); |
| 2003 | if (ret) |
| 2004 | v4l2_err(&cdev->v4l2_dev, "HW initialization failed\n"); |
| 2005 | } |
| 2006 | |
| 2007 | return ret; |
| 2008 | } |
| 2009 | #endif |
| 2010 | |
| 2011 | static const struct dev_pm_ops coda_pm_ops = { |
| 2012 | SET_RUNTIME_PM_OPS(NULL, coda_runtime_resume, NULL) |
| 2013 | }; |
| 2014 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2015 | static struct platform_driver coda_driver = { |
| 2016 | .probe = coda_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 2017 | .remove = coda_remove, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2018 | .driver = { |
| 2019 | .name = CODA_NAME, |
| 2020 | .owner = THIS_MODULE, |
| 2021 | .of_match_table = of_match_ptr(coda_dt_ids), |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 2022 | .pm = &coda_pm_ops, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2023 | }, |
| 2024 | .id_table = coda_platform_ids, |
| 2025 | }; |
| 2026 | |
| 2027 | module_platform_driver(coda_driver); |
| 2028 | |
| 2029 | MODULE_LICENSE("GPL"); |
| 2030 | MODULE_AUTHOR("Javier Martin <javier.martin@vista-silicon.com>"); |
| 2031 | MODULE_DESCRIPTION("Coda multi-standard codec V4L2 driver"); |