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