Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Samsung S5P Multi Format Codec v 5.1 |
| 3 | * |
| 4 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. |
| 5 | * Kamil Debski, <k.debski@samsung.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/clk.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/io.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/slab.h> |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 21 | #include <linux/videodev2.h> |
Andrzej Hajda | f9f715a | 2012-08-21 08:05:32 -0300 | [diff] [blame] | 22 | #include <media/v4l2-event.h> |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 23 | #include <linux/workqueue.h> |
Arun Kumar K | b27a23b | 2012-10-25 05:24:14 -0300 | [diff] [blame] | 24 | #include <linux/of.h> |
Junghak Sung | c139990 | 2015-09-22 10:30:29 -0300 | [diff] [blame] | 25 | #include <media/videobuf2-v4l2.h> |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 26 | #include "s5p_mfc_common.h" |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 27 | #include "s5p_mfc_ctrl.h" |
| 28 | #include "s5p_mfc_debug.h" |
| 29 | #include "s5p_mfc_dec.h" |
| 30 | #include "s5p_mfc_enc.h" |
| 31 | #include "s5p_mfc_intr.h" |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 32 | #include "s5p_mfc_opr.h" |
| 33 | #include "s5p_mfc_cmd.h" |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 34 | #include "s5p_mfc_pm.h" |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 35 | |
| 36 | #define S5P_MFC_NAME "s5p-mfc" |
| 37 | #define S5P_MFC_DEC_NAME "s5p-mfc-dec" |
| 38 | #define S5P_MFC_ENC_NAME "s5p-mfc-enc" |
| 39 | |
Mauro Carvalho Chehab | 139adba | 2014-08-22 06:07:57 -0500 | [diff] [blame] | 40 | int mfc_debug_level; |
| 41 | module_param_named(debug, mfc_debug_level, int, S_IRUGO | S_IWUSR); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 42 | MODULE_PARM_DESC(debug, "Debug level - higher value produces more verbose messages"); |
| 43 | |
| 44 | /* Helper functions for interrupt processing */ |
Andrzej Hajda | 7fb89ec | 2012-08-14 06:13:40 -0300 | [diff] [blame] | 45 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 46 | /* Remove from hw execution round robin */ |
Andrzej Hajda | 7fb89ec | 2012-08-14 06:13:40 -0300 | [diff] [blame] | 47 | void clear_work_bit(struct s5p_mfc_ctx *ctx) |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 48 | { |
| 49 | struct s5p_mfc_dev *dev = ctx->dev; |
| 50 | |
| 51 | spin_lock(&dev->condlock); |
Andrzej Hajda | 7fb89ec | 2012-08-14 06:13:40 -0300 | [diff] [blame] | 52 | __clear_bit(ctx->num, &dev->ctx_work_bits); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 53 | spin_unlock(&dev->condlock); |
| 54 | } |
| 55 | |
Andrzej Hajda | 7fb89ec | 2012-08-14 06:13:40 -0300 | [diff] [blame] | 56 | /* Add to hw execution round robin */ |
| 57 | void set_work_bit(struct s5p_mfc_ctx *ctx) |
| 58 | { |
| 59 | struct s5p_mfc_dev *dev = ctx->dev; |
| 60 | |
| 61 | spin_lock(&dev->condlock); |
| 62 | __set_bit(ctx->num, &dev->ctx_work_bits); |
| 63 | spin_unlock(&dev->condlock); |
| 64 | } |
| 65 | |
| 66 | /* Remove from hw execution round robin */ |
| 67 | void clear_work_bit_irqsave(struct s5p_mfc_ctx *ctx) |
| 68 | { |
| 69 | struct s5p_mfc_dev *dev = ctx->dev; |
| 70 | unsigned long flags; |
| 71 | |
| 72 | spin_lock_irqsave(&dev->condlock, flags); |
| 73 | __clear_bit(ctx->num, &dev->ctx_work_bits); |
| 74 | spin_unlock_irqrestore(&dev->condlock, flags); |
| 75 | } |
| 76 | |
| 77 | /* Add to hw execution round robin */ |
| 78 | void set_work_bit_irqsave(struct s5p_mfc_ctx *ctx) |
| 79 | { |
| 80 | struct s5p_mfc_dev *dev = ctx->dev; |
| 81 | unsigned long flags; |
| 82 | |
| 83 | spin_lock_irqsave(&dev->condlock, flags); |
| 84 | __set_bit(ctx->num, &dev->ctx_work_bits); |
| 85 | spin_unlock_irqrestore(&dev->condlock, flags); |
| 86 | } |
| 87 | |
Andrzej Hajda | 05d1d0f | 2015-12-02 06:22:28 -0200 | [diff] [blame] | 88 | int s5p_mfc_get_new_ctx(struct s5p_mfc_dev *dev) |
| 89 | { |
| 90 | unsigned long flags; |
| 91 | int ctx; |
| 92 | |
| 93 | spin_lock_irqsave(&dev->condlock, flags); |
| 94 | ctx = dev->curr_ctx; |
| 95 | do { |
| 96 | ctx = (ctx + 1) % MFC_NUM_CONTEXTS; |
| 97 | if (ctx == dev->curr_ctx) { |
| 98 | if (!test_bit(ctx, &dev->ctx_work_bits)) |
| 99 | ctx = -EAGAIN; |
| 100 | break; |
| 101 | } |
| 102 | } while (!test_bit(ctx, &dev->ctx_work_bits)); |
| 103 | spin_unlock_irqrestore(&dev->condlock, flags); |
| 104 | |
| 105 | return ctx; |
| 106 | } |
| 107 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 108 | /* Wake up context wait_queue */ |
| 109 | static void wake_up_ctx(struct s5p_mfc_ctx *ctx, unsigned int reason, |
| 110 | unsigned int err) |
| 111 | { |
| 112 | ctx->int_cond = 1; |
| 113 | ctx->int_type = reason; |
| 114 | ctx->int_err = err; |
| 115 | wake_up(&ctx->queue); |
| 116 | } |
| 117 | |
| 118 | /* Wake up device wait_queue */ |
| 119 | static void wake_up_dev(struct s5p_mfc_dev *dev, unsigned int reason, |
| 120 | unsigned int err) |
| 121 | { |
| 122 | dev->int_cond = 1; |
| 123 | dev->int_type = reason; |
| 124 | dev->int_err = err; |
| 125 | wake_up(&dev->queue); |
| 126 | } |
| 127 | |
Andrzej Hajda | 62bbd72 | 2015-12-02 06:22:29 -0200 | [diff] [blame^] | 128 | void s5p_mfc_cleanup_queue(struct list_head *lh, struct vb2_queue *vq) |
| 129 | { |
| 130 | struct s5p_mfc_buf *b; |
| 131 | int i; |
| 132 | |
| 133 | while (!list_empty(lh)) { |
| 134 | b = list_entry(lh->next, struct s5p_mfc_buf, list); |
| 135 | for (i = 0; i < b->b->vb2_buf.num_planes; i++) |
| 136 | vb2_set_plane_payload(&b->b->vb2_buf, i, 0); |
| 137 | vb2_buffer_done(&b->b->vb2_buf, VB2_BUF_STATE_ERROR); |
| 138 | list_del(&b->list); |
| 139 | } |
| 140 | } |
| 141 | |
Sachin Kamat | a13bba4 | 2012-05-10 03:32:01 -0300 | [diff] [blame] | 142 | static void s5p_mfc_watchdog(unsigned long arg) |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 143 | { |
| 144 | struct s5p_mfc_dev *dev = (struct s5p_mfc_dev *)arg; |
| 145 | |
| 146 | if (test_bit(0, &dev->hw_lock)) |
| 147 | atomic_inc(&dev->watchdog_cnt); |
| 148 | if (atomic_read(&dev->watchdog_cnt) >= MFC_WATCHDOG_CNT) { |
| 149 | /* This means that hw is busy and no interrupts were |
| 150 | * generated by hw for the Nth time of running this |
| 151 | * watchdog timer. This usually means a serious hw |
| 152 | * error. Now it is time to kill all instances and |
| 153 | * reset the MFC. */ |
| 154 | mfc_err("Time out during waiting for HW\n"); |
| 155 | queue_work(dev->watchdog_workqueue, &dev->watchdog_work); |
| 156 | } |
| 157 | dev->watchdog_timer.expires = jiffies + |
| 158 | msecs_to_jiffies(MFC_WATCHDOG_INTERVAL); |
| 159 | add_timer(&dev->watchdog_timer); |
| 160 | } |
| 161 | |
| 162 | static void s5p_mfc_watchdog_worker(struct work_struct *work) |
| 163 | { |
| 164 | struct s5p_mfc_dev *dev; |
| 165 | struct s5p_mfc_ctx *ctx; |
| 166 | unsigned long flags; |
| 167 | int mutex_locked; |
| 168 | int i, ret; |
| 169 | |
| 170 | dev = container_of(work, struct s5p_mfc_dev, watchdog_work); |
| 171 | |
| 172 | mfc_err("Driver timeout error handling\n"); |
| 173 | /* Lock the mutex that protects open and release. |
| 174 | * This is necessary as they may load and unload firmware. */ |
| 175 | mutex_locked = mutex_trylock(&dev->mfc_mutex); |
| 176 | if (!mutex_locked) |
| 177 | mfc_err("Error: some instance may be closing/opening\n"); |
| 178 | spin_lock_irqsave(&dev->irqlock, flags); |
| 179 | |
| 180 | s5p_mfc_clock_off(); |
| 181 | |
| 182 | for (i = 0; i < MFC_NUM_CONTEXTS; i++) { |
| 183 | ctx = dev->ctx[i]; |
| 184 | if (!ctx) |
| 185 | continue; |
| 186 | ctx->state = MFCINST_ERROR; |
Andrzej Hajda | 62bbd72 | 2015-12-02 06:22:29 -0200 | [diff] [blame^] | 187 | s5p_mfc_cleanup_queue(&ctx->dst_queue, &ctx->vq_dst); |
| 188 | s5p_mfc_cleanup_queue(&ctx->src_queue, &ctx->vq_src); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 189 | clear_work_bit(ctx); |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 190 | wake_up_ctx(ctx, S5P_MFC_R2H_CMD_ERR_RET, 0); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 191 | } |
| 192 | clear_bit(0, &dev->hw_lock); |
| 193 | spin_unlock_irqrestore(&dev->irqlock, flags); |
Arun Mankuzhi | b16e644 | 2014-10-21 08:07:03 -0300 | [diff] [blame] | 194 | |
| 195 | /* De-init MFC */ |
| 196 | s5p_mfc_deinit_hw(dev); |
| 197 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 198 | /* Double check if there is at least one instance running. |
| 199 | * If no instance is in memory than no firmware should be present */ |
| 200 | if (dev->num_inst > 0) { |
Arun Kumar K | 4607500 | 2014-05-21 06:29:29 -0300 | [diff] [blame] | 201 | ret = s5p_mfc_load_firmware(dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 202 | if (ret) { |
| 203 | mfc_err("Failed to reload FW\n"); |
| 204 | goto unlock; |
| 205 | } |
| 206 | s5p_mfc_clock_on(); |
| 207 | ret = s5p_mfc_init_hw(dev); |
| 208 | if (ret) |
| 209 | mfc_err("Failed to reinit FW\n"); |
| 210 | } |
| 211 | unlock: |
| 212 | if (mutex_locked) |
| 213 | mutex_unlock(&dev->mfc_mutex); |
| 214 | } |
| 215 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 216 | static void s5p_mfc_handle_frame_all_extracted(struct s5p_mfc_ctx *ctx) |
| 217 | { |
| 218 | struct s5p_mfc_buf *dst_buf; |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 219 | struct s5p_mfc_dev *dev = ctx->dev; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 220 | |
| 221 | ctx->state = MFCINST_FINISHED; |
| 222 | ctx->sequence++; |
| 223 | while (!list_empty(&ctx->dst_queue)) { |
| 224 | dst_buf = list_entry(ctx->dst_queue.next, |
| 225 | struct s5p_mfc_buf, list); |
| 226 | mfc_debug(2, "Cleaning up buffer: %d\n", |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 227 | dst_buf->b->vb2_buf.index); |
| 228 | vb2_set_plane_payload(&dst_buf->b->vb2_buf, 0, 0); |
| 229 | vb2_set_plane_payload(&dst_buf->b->vb2_buf, 1, 0); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 230 | list_del(&dst_buf->list); |
Andrzej Hajda | 4d0b0ed | 2015-10-07 07:13:45 -0300 | [diff] [blame] | 231 | dst_buf->flags |= MFC_BUF_FLAG_EOS; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 232 | ctx->dst_queue_cnt--; |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 233 | dst_buf->b->sequence = (ctx->sequence++); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 234 | |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 235 | if (s5p_mfc_hw_call(dev->mfc_ops, get_pic_type_top, ctx) == |
| 236 | s5p_mfc_hw_call(dev->mfc_ops, get_pic_type_bot, ctx)) |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 237 | dst_buf->b->field = V4L2_FIELD_NONE; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 238 | else |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 239 | dst_buf->b->field = V4L2_FIELD_INTERLACED; |
| 240 | dst_buf->b->flags |= V4L2_BUF_FLAG_LAST; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 241 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 242 | ctx->dec_dst_flag &= ~(1 << dst_buf->b->vb2_buf.index); |
| 243 | vb2_buffer_done(&dst_buf->b->vb2_buf, VB2_BUF_STATE_DONE); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
| 247 | static void s5p_mfc_handle_frame_copy_time(struct s5p_mfc_ctx *ctx) |
| 248 | { |
| 249 | struct s5p_mfc_dev *dev = ctx->dev; |
| 250 | struct s5p_mfc_buf *dst_buf, *src_buf; |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 251 | size_t dec_y_addr; |
| 252 | unsigned int frame_type; |
| 253 | |
Ilja Friedel | bb21c54 | 2014-10-21 08:06:58 -0300 | [diff] [blame] | 254 | /* Make sure we actually have a new frame before continuing. */ |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 255 | frame_type = s5p_mfc_hw_call(dev->mfc_ops, get_dec_frame_type, dev); |
Ilja Friedel | bb21c54 | 2014-10-21 08:06:58 -0300 | [diff] [blame] | 256 | if (frame_type == S5P_FIMV_DECODE_FRAME_SKIPPED) |
| 257 | return; |
| 258 | dec_y_addr = s5p_mfc_hw_call(dev->mfc_ops, get_dec_y_adr, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 259 | |
| 260 | /* Copy timestamp / timecode from decoded src to dst and set |
Ilja Friedel | bb21c54 | 2014-10-21 08:06:58 -0300 | [diff] [blame] | 261 | appropriate flags. */ |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 262 | src_buf = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list); |
| 263 | list_for_each_entry(dst_buf, &ctx->dst_queue, list) { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 264 | if (vb2_dma_contig_plane_dma_addr(&dst_buf->b->vb2_buf, 0) |
| 265 | == dec_y_addr) { |
| 266 | dst_buf->b->timecode = |
| 267 | src_buf->b->timecode; |
Junghak Sung | d6dd645 | 2015-11-03 08:16:37 -0200 | [diff] [blame] | 268 | dst_buf->b->vb2_buf.timestamp = |
| 269 | src_buf->b->vb2_buf.timestamp; |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 270 | dst_buf->b->flags &= |
Sakari Ailus | 309f4d6 | 2014-02-08 14:21:35 -0300 | [diff] [blame] | 271 | ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK; |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 272 | dst_buf->b->flags |= |
| 273 | src_buf->b->flags |
Sakari Ailus | 309f4d6 | 2014-02-08 14:21:35 -0300 | [diff] [blame] | 274 | & V4L2_BUF_FLAG_TSTAMP_SRC_MASK; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 275 | switch (frame_type) { |
| 276 | case S5P_FIMV_DECODE_FRAME_I_FRAME: |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 277 | dst_buf->b->flags |= |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 278 | V4L2_BUF_FLAG_KEYFRAME; |
| 279 | break; |
| 280 | case S5P_FIMV_DECODE_FRAME_P_FRAME: |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 281 | dst_buf->b->flags |= |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 282 | V4L2_BUF_FLAG_PFRAME; |
| 283 | break; |
| 284 | case S5P_FIMV_DECODE_FRAME_B_FRAME: |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 285 | dst_buf->b->flags |= |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 286 | V4L2_BUF_FLAG_BFRAME; |
| 287 | break; |
Ilja Friedel | bb21c54 | 2014-10-21 08:06:58 -0300 | [diff] [blame] | 288 | default: |
| 289 | /* Don't know how to handle |
| 290 | S5P_FIMV_DECODE_FRAME_OTHER_FRAME. */ |
| 291 | mfc_debug(2, "Unexpected frame type: %d\n", |
| 292 | frame_type); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 293 | } |
| 294 | break; |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | static void s5p_mfc_handle_frame_new(struct s5p_mfc_ctx *ctx, unsigned int err) |
| 300 | { |
| 301 | struct s5p_mfc_dev *dev = ctx->dev; |
| 302 | struct s5p_mfc_buf *dst_buf; |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 303 | size_t dspl_y_addr; |
| 304 | unsigned int frame_type; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 305 | |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 306 | dspl_y_addr = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_y_adr, dev); |
Sjoerd Simons | 7c67281 | 2014-09-22 09:52:02 -0300 | [diff] [blame] | 307 | if (IS_MFCV6_PLUS(dev)) |
| 308 | frame_type = s5p_mfc_hw_call(dev->mfc_ops, |
| 309 | get_disp_frame_type, ctx); |
| 310 | else |
| 311 | frame_type = s5p_mfc_hw_call(dev->mfc_ops, |
| 312 | get_dec_frame_type, dev); |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 313 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 314 | /* If frame is same as previous then skip and do not dequeue */ |
| 315 | if (frame_type == S5P_FIMV_DECODE_FRAME_SKIPPED) { |
| 316 | if (!ctx->after_packed_pb) |
| 317 | ctx->sequence++; |
| 318 | ctx->after_packed_pb = 0; |
| 319 | return; |
| 320 | } |
| 321 | ctx->sequence++; |
| 322 | /* The MFC returns address of the buffer, now we have to |
| 323 | * check which videobuf does it correspond to */ |
| 324 | list_for_each_entry(dst_buf, &ctx->dst_queue, list) { |
| 325 | /* Check if this is the buffer we're looking for */ |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 326 | if (vb2_dma_contig_plane_dma_addr(&dst_buf->b->vb2_buf, 0) |
| 327 | == dspl_y_addr) { |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 328 | list_del(&dst_buf->list); |
| 329 | ctx->dst_queue_cnt--; |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 330 | dst_buf->b->sequence = ctx->sequence; |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 331 | if (s5p_mfc_hw_call(dev->mfc_ops, |
| 332 | get_pic_type_top, ctx) == |
| 333 | s5p_mfc_hw_call(dev->mfc_ops, |
| 334 | get_pic_type_bot, ctx)) |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 335 | dst_buf->b->field = V4L2_FIELD_NONE; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 336 | else |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 337 | dst_buf->b->field = |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 338 | V4L2_FIELD_INTERLACED; |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 339 | vb2_set_plane_payload(&dst_buf->b->vb2_buf, 0, |
| 340 | ctx->luma_size); |
| 341 | vb2_set_plane_payload(&dst_buf->b->vb2_buf, 1, |
| 342 | ctx->chroma_size); |
| 343 | clear_bit(dst_buf->b->vb2_buf.index, |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 344 | &ctx->dec_dst_flag); |
| 345 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 346 | vb2_buffer_done(&dst_buf->b->vb2_buf, err ? |
| 347 | VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 348 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 349 | break; |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | /* Handle frame decoding interrupt */ |
| 355 | static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx, |
| 356 | unsigned int reason, unsigned int err) |
| 357 | { |
| 358 | struct s5p_mfc_dev *dev = ctx->dev; |
| 359 | unsigned int dst_frame_status; |
Pawel Osciak | a0517f5 | 2014-05-19 09:32:57 -0300 | [diff] [blame] | 360 | unsigned int dec_frame_status; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 361 | struct s5p_mfc_buf *src_buf; |
| 362 | unsigned long flags; |
| 363 | unsigned int res_change; |
| 364 | |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 365 | dst_frame_status = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev) |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 366 | & S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK; |
Pawel Osciak | a0517f5 | 2014-05-19 09:32:57 -0300 | [diff] [blame] | 367 | dec_frame_status = s5p_mfc_hw_call(dev->mfc_ops, get_dec_status, dev) |
| 368 | & S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK; |
Jeongtae Park | f96f3cf | 2012-10-03 22:19:11 -0300 | [diff] [blame] | 369 | res_change = (s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev) |
| 370 | & S5P_FIMV_DEC_STATUS_RESOLUTION_MASK) |
| 371 | >> S5P_FIMV_DEC_STATUS_RESOLUTION_SHIFT; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 372 | mfc_debug(2, "Frame Status: %x\n", dst_frame_status); |
| 373 | if (ctx->state == MFCINST_RES_CHANGE_INIT) |
| 374 | ctx->state = MFCINST_RES_CHANGE_FLUSH; |
Jeongtae Park | f96f3cf | 2012-10-03 22:19:11 -0300 | [diff] [blame] | 375 | if (res_change == S5P_FIMV_RES_INCREASE || |
| 376 | res_change == S5P_FIMV_RES_DECREASE) { |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 377 | ctx->state = MFCINST_RES_CHANGE_INIT; |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 378 | s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 379 | wake_up_ctx(ctx, reason, err); |
Pawel Osciak | 9a7bc6b | 2014-10-21 08:07:01 -0300 | [diff] [blame] | 380 | WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 381 | s5p_mfc_clock_off(); |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 382 | s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 383 | return; |
| 384 | } |
| 385 | if (ctx->dpb_flush_flag) |
| 386 | ctx->dpb_flush_flag = 0; |
| 387 | |
| 388 | spin_lock_irqsave(&dev->irqlock, flags); |
| 389 | /* All frames remaining in the buffer have been extracted */ |
| 390 | if (dst_frame_status == S5P_FIMV_DEC_STATUS_DECODING_EMPTY) { |
| 391 | if (ctx->state == MFCINST_RES_CHANGE_FLUSH) { |
Pawel Osciak | 0520e4c | 2014-05-14 03:59:43 -0300 | [diff] [blame] | 392 | static const struct v4l2_event ev_src_ch = { |
| 393 | .type = V4L2_EVENT_SOURCE_CHANGE, |
| 394 | .u.src_change.changes = |
| 395 | V4L2_EVENT_SRC_CH_RESOLUTION, |
| 396 | }; |
| 397 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 398 | s5p_mfc_handle_frame_all_extracted(ctx); |
| 399 | ctx->state = MFCINST_RES_CHANGE_END; |
Pawel Osciak | 0520e4c | 2014-05-14 03:59:43 -0300 | [diff] [blame] | 400 | v4l2_event_queue_fh(&ctx->fh, &ev_src_ch); |
| 401 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 402 | goto leave_handle_frame; |
| 403 | } else { |
| 404 | s5p_mfc_handle_frame_all_extracted(ctx); |
| 405 | } |
| 406 | } |
| 407 | |
Pawel Osciak | a0517f5 | 2014-05-19 09:32:57 -0300 | [diff] [blame] | 408 | if (dec_frame_status == S5P_FIMV_DEC_STATUS_DECODING_DISPLAY) |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 409 | s5p_mfc_handle_frame_copy_time(ctx); |
| 410 | |
| 411 | /* A frame has been decoded and is in the buffer */ |
| 412 | if (dst_frame_status == S5P_FIMV_DEC_STATUS_DISPLAY_ONLY || |
| 413 | dst_frame_status == S5P_FIMV_DEC_STATUS_DECODING_DISPLAY) { |
| 414 | s5p_mfc_handle_frame_new(ctx, err); |
| 415 | } else { |
| 416 | mfc_debug(2, "No frame decode\n"); |
| 417 | } |
| 418 | /* Mark source buffer as complete */ |
| 419 | if (dst_frame_status != S5P_FIMV_DEC_STATUS_DISPLAY_ONLY |
| 420 | && !list_empty(&ctx->src_queue)) { |
| 421 | src_buf = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, |
| 422 | list); |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 423 | ctx->consumed_stream += s5p_mfc_hw_call(dev->mfc_ops, |
| 424 | get_consumed_stream, dev); |
| 425 | if (ctx->codec_mode != S5P_MFC_CODEC_H264_DEC && |
Pawel Osciak | f49f3ed | 2014-05-19 09:33:02 -0300 | [diff] [blame] | 426 | ctx->codec_mode != S5P_MFC_CODEC_VP8_DEC && |
Arun Kumar K | d2a0db1 | 2012-11-14 09:26:45 -0300 | [diff] [blame] | 427 | ctx->consumed_stream + STUFF_BYTE < |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 428 | src_buf->b->vb2_buf.planes[0].bytesused) { |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 429 | /* Run MFC again on the same buffer */ |
| 430 | mfc_debug(2, "Running again the same buffer\n"); |
| 431 | ctx->after_packed_pb = 1; |
| 432 | } else { |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 433 | mfc_debug(2, "MFC needs next buffer\n"); |
| 434 | ctx->consumed_stream = 0; |
Kamil Debski | a34026e | 2013-01-11 12:29:33 -0300 | [diff] [blame] | 435 | if (src_buf->flags & MFC_BUF_FLAG_EOS) |
| 436 | ctx->state = MFCINST_FINISHING; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 437 | list_del(&src_buf->list); |
| 438 | ctx->src_queue_cnt--; |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 439 | if (s5p_mfc_hw_call(dev->mfc_ops, err_dec, err) > 0) |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 440 | vb2_buffer_done(&src_buf->b->vb2_buf, |
| 441 | VB2_BUF_STATE_ERROR); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 442 | else |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 443 | vb2_buffer_done(&src_buf->b->vb2_buf, |
| 444 | VB2_BUF_STATE_DONE); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | leave_handle_frame: |
| 448 | spin_unlock_irqrestore(&dev->irqlock, flags); |
| 449 | if ((ctx->src_queue_cnt == 0 && ctx->state != MFCINST_FINISHING) |
Arun Kumar K | e9d98dd | 2013-04-24 09:41:53 -0300 | [diff] [blame] | 450 | || ctx->dst_queue_cnt < ctx->pb_count) |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 451 | clear_work_bit(ctx); |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 452 | s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 453 | wake_up_ctx(ctx, reason, err); |
Pawel Osciak | 9a7bc6b | 2014-10-21 08:07:01 -0300 | [diff] [blame] | 454 | WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 455 | s5p_mfc_clock_off(); |
Prathyush K | 76a4ddb | 2013-10-04 01:47:19 -0300 | [diff] [blame] | 456 | /* if suspending, wake up device and do not try_run again*/ |
| 457 | if (test_bit(0, &dev->enter_suspend)) |
| 458 | wake_up_dev(dev, reason, err); |
| 459 | else |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 460 | s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | /* Error handling for interrupt */ |
Kamil Debski | 7296e25 | 2012-12-21 05:32:59 -0300 | [diff] [blame] | 464 | static void s5p_mfc_handle_error(struct s5p_mfc_dev *dev, |
| 465 | struct s5p_mfc_ctx *ctx, unsigned int reason, unsigned int err) |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 466 | { |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 467 | unsigned long flags; |
| 468 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 469 | mfc_err("Interrupt Error: %08x\n", err); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 470 | |
Kamil Debski | 7296e25 | 2012-12-21 05:32:59 -0300 | [diff] [blame] | 471 | if (ctx != NULL) { |
| 472 | /* Error recovery is dependent on the state of context */ |
| 473 | switch (ctx->state) { |
| 474 | case MFCINST_RES_CHANGE_INIT: |
| 475 | case MFCINST_RES_CHANGE_FLUSH: |
| 476 | case MFCINST_RES_CHANGE_END: |
| 477 | case MFCINST_FINISHING: |
| 478 | case MFCINST_FINISHED: |
| 479 | case MFCINST_RUNNING: |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 480 | /* It is highly probable that an error occurred |
Kamil Debski | 7296e25 | 2012-12-21 05:32:59 -0300 | [diff] [blame] | 481 | * while decoding a frame */ |
| 482 | clear_work_bit(ctx); |
| 483 | ctx->state = MFCINST_ERROR; |
| 484 | /* Mark all dst buffers as having an error */ |
| 485 | spin_lock_irqsave(&dev->irqlock, flags); |
Andrzej Hajda | 62bbd72 | 2015-12-02 06:22:29 -0200 | [diff] [blame^] | 486 | s5p_mfc_cleanup_queue(&ctx->dst_queue, &ctx->vq_dst); |
Kamil Debski | 7296e25 | 2012-12-21 05:32:59 -0300 | [diff] [blame] | 487 | /* Mark all src buffers as having an error */ |
Andrzej Hajda | 62bbd72 | 2015-12-02 06:22:29 -0200 | [diff] [blame^] | 488 | s5p_mfc_cleanup_queue(&ctx->src_queue, &ctx->vq_src); |
Kamil Debski | 7296e25 | 2012-12-21 05:32:59 -0300 | [diff] [blame] | 489 | spin_unlock_irqrestore(&dev->irqlock, flags); |
| 490 | wake_up_ctx(ctx, reason, err); |
| 491 | break; |
| 492 | default: |
| 493 | clear_work_bit(ctx); |
| 494 | ctx->state = MFCINST_ERROR; |
| 495 | wake_up_ctx(ctx, reason, err); |
| 496 | break; |
| 497 | } |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 498 | } |
Pawel Osciak | 9a7bc6b | 2014-10-21 08:07:01 -0300 | [diff] [blame] | 499 | WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0); |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 500 | s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev); |
Kamil Debski | 7296e25 | 2012-12-21 05:32:59 -0300 | [diff] [blame] | 501 | s5p_mfc_clock_off(); |
| 502 | wake_up_dev(dev, reason, err); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 503 | return; |
| 504 | } |
| 505 | |
| 506 | /* Header parsing interrupt handling */ |
| 507 | static void s5p_mfc_handle_seq_done(struct s5p_mfc_ctx *ctx, |
| 508 | unsigned int reason, unsigned int err) |
| 509 | { |
| 510 | struct s5p_mfc_dev *dev; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 511 | |
Sachin Kamat | 1259762 | 2012-05-10 03:32:00 -0300 | [diff] [blame] | 512 | if (ctx == NULL) |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 513 | return; |
| 514 | dev = ctx->dev; |
| 515 | if (ctx->c_ops->post_seq_start) { |
| 516 | if (ctx->c_ops->post_seq_start(ctx)) |
| 517 | mfc_err("post_seq_start() failed\n"); |
| 518 | } else { |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 519 | ctx->img_width = s5p_mfc_hw_call(dev->mfc_ops, get_img_width, |
| 520 | dev); |
| 521 | ctx->img_height = s5p_mfc_hw_call(dev->mfc_ops, get_img_height, |
| 522 | dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 523 | |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 524 | s5p_mfc_hw_call_void(dev->mfc_ops, dec_calc_dpb_size, ctx); |
Arun Kumar K | 8f532a7 | 2012-10-03 22:19:09 -0300 | [diff] [blame] | 525 | |
Arun Kumar K | e9d98dd | 2013-04-24 09:41:53 -0300 | [diff] [blame] | 526 | ctx->pb_count = s5p_mfc_hw_call(dev->mfc_ops, get_dpb_count, |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 527 | dev); |
Jeongtae Park | f96f3cf | 2012-10-03 22:19:11 -0300 | [diff] [blame] | 528 | ctx->mv_count = s5p_mfc_hw_call(dev->mfc_ops, get_mv_count, |
| 529 | dev); |
Julia Lawall | bb86936 | 2012-01-12 17:49:30 -0300 | [diff] [blame] | 530 | if (ctx->img_width == 0 || ctx->img_height == 0) |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 531 | ctx->state = MFCINST_ERROR; |
| 532 | else |
| 533 | ctx->state = MFCINST_HEAD_PARSED; |
Jeongtae Park | f96f3cf | 2012-10-03 22:19:11 -0300 | [diff] [blame] | 534 | |
| 535 | if ((ctx->codec_mode == S5P_MFC_CODEC_H264_DEC || |
| 536 | ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) && |
| 537 | !list_empty(&ctx->src_queue)) { |
| 538 | struct s5p_mfc_buf *src_buf; |
| 539 | src_buf = list_entry(ctx->src_queue.next, |
| 540 | struct s5p_mfc_buf, list); |
| 541 | if (s5p_mfc_hw_call(dev->mfc_ops, get_consumed_stream, |
| 542 | dev) < |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 543 | src_buf->b->vb2_buf.planes[0].bytesused) |
Jeongtae Park | f96f3cf | 2012-10-03 22:19:11 -0300 | [diff] [blame] | 544 | ctx->head_processed = 0; |
| 545 | else |
| 546 | ctx->head_processed = 1; |
| 547 | } else { |
| 548 | ctx->head_processed = 1; |
| 549 | } |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 550 | } |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 551 | s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 552 | clear_work_bit(ctx); |
Pawel Osciak | 9a7bc6b | 2014-10-21 08:07:01 -0300 | [diff] [blame] | 553 | WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 554 | s5p_mfc_clock_off(); |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 555 | s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 556 | wake_up_ctx(ctx, reason, err); |
| 557 | } |
| 558 | |
| 559 | /* Header parsing interrupt handling */ |
| 560 | static void s5p_mfc_handle_init_buffers(struct s5p_mfc_ctx *ctx, |
| 561 | unsigned int reason, unsigned int err) |
| 562 | { |
| 563 | struct s5p_mfc_buf *src_buf; |
| 564 | struct s5p_mfc_dev *dev; |
| 565 | unsigned long flags; |
| 566 | |
Sachin Kamat | 1259762 | 2012-05-10 03:32:00 -0300 | [diff] [blame] | 567 | if (ctx == NULL) |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 568 | return; |
| 569 | dev = ctx->dev; |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 570 | s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 571 | ctx->int_type = reason; |
| 572 | ctx->int_err = err; |
| 573 | ctx->int_cond = 1; |
Andrzej Hajda | 7fb89ec | 2012-08-14 06:13:40 -0300 | [diff] [blame] | 574 | clear_work_bit(ctx); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 575 | if (err == 0) { |
| 576 | ctx->state = MFCINST_RUNNING; |
Jeongtae Park | f96f3cf | 2012-10-03 22:19:11 -0300 | [diff] [blame] | 577 | if (!ctx->dpb_flush_flag && ctx->head_processed) { |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 578 | spin_lock_irqsave(&dev->irqlock, flags); |
| 579 | if (!list_empty(&ctx->src_queue)) { |
| 580 | src_buf = list_entry(ctx->src_queue.next, |
| 581 | struct s5p_mfc_buf, list); |
| 582 | list_del(&src_buf->list); |
| 583 | ctx->src_queue_cnt--; |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 584 | vb2_buffer_done(&src_buf->b->vb2_buf, |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 585 | VB2_BUF_STATE_DONE); |
| 586 | } |
| 587 | spin_unlock_irqrestore(&dev->irqlock, flags); |
| 588 | } else { |
| 589 | ctx->dpb_flush_flag = 0; |
| 590 | } |
Pawel Osciak | 9a7bc6b | 2014-10-21 08:07:01 -0300 | [diff] [blame] | 591 | WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 592 | |
| 593 | s5p_mfc_clock_off(); |
| 594 | |
| 595 | wake_up(&ctx->queue); |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 596 | s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 597 | } else { |
Pawel Osciak | 9a7bc6b | 2014-10-21 08:07:01 -0300 | [diff] [blame] | 598 | WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 599 | |
| 600 | s5p_mfc_clock_off(); |
| 601 | |
| 602 | wake_up(&ctx->queue); |
| 603 | } |
| 604 | } |
| 605 | |
Andrzej Hajda | 96c5777 | 2015-10-07 07:15:31 -0300 | [diff] [blame] | 606 | static void s5p_mfc_handle_stream_complete(struct s5p_mfc_ctx *ctx) |
Andrzej Hajda | f9f715a | 2012-08-21 08:05:32 -0300 | [diff] [blame] | 607 | { |
| 608 | struct s5p_mfc_dev *dev = ctx->dev; |
| 609 | struct s5p_mfc_buf *mb_entry; |
| 610 | |
Andrzej Hajda | 4130eab | 2013-05-28 03:26:16 -0300 | [diff] [blame] | 611 | mfc_debug(2, "Stream completed\n"); |
Andrzej Hajda | f9f715a | 2012-08-21 08:05:32 -0300 | [diff] [blame] | 612 | |
Andrzej Hajda | f9f715a | 2012-08-21 08:05:32 -0300 | [diff] [blame] | 613 | ctx->state = MFCINST_FINISHED; |
| 614 | |
| 615 | spin_lock(&dev->irqlock); |
| 616 | if (!list_empty(&ctx->dst_queue)) { |
| 617 | mb_entry = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, |
| 618 | list); |
| 619 | list_del(&mb_entry->list); |
| 620 | ctx->dst_queue_cnt--; |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 621 | vb2_set_plane_payload(&mb_entry->b->vb2_buf, 0, 0); |
| 622 | vb2_buffer_done(&mb_entry->b->vb2_buf, VB2_BUF_STATE_DONE); |
Andrzej Hajda | f9f715a | 2012-08-21 08:05:32 -0300 | [diff] [blame] | 623 | } |
| 624 | spin_unlock(&dev->irqlock); |
| 625 | |
| 626 | clear_work_bit(ctx); |
| 627 | |
Sachin Kamat | e825644 | 2013-01-22 01:00:06 -0300 | [diff] [blame] | 628 | WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0); |
Andrzej Hajda | f9f715a | 2012-08-21 08:05:32 -0300 | [diff] [blame] | 629 | |
| 630 | s5p_mfc_clock_off(); |
| 631 | wake_up(&ctx->queue); |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 632 | s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev); |
Andrzej Hajda | f9f715a | 2012-08-21 08:05:32 -0300 | [diff] [blame] | 633 | } |
| 634 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 635 | /* Interrupt processing */ |
| 636 | static irqreturn_t s5p_mfc_irq(int irq, void *priv) |
| 637 | { |
| 638 | struct s5p_mfc_dev *dev = priv; |
| 639 | struct s5p_mfc_ctx *ctx; |
| 640 | unsigned int reason; |
| 641 | unsigned int err; |
| 642 | |
| 643 | mfc_debug_enter(); |
| 644 | /* Reset the timeout watchdog */ |
| 645 | atomic_set(&dev->watchdog_cnt, 0); |
| 646 | ctx = dev->ctx[dev->curr_ctx]; |
| 647 | /* Get the reason of interrupt and the error code */ |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 648 | reason = s5p_mfc_hw_call(dev->mfc_ops, get_int_reason, dev); |
| 649 | err = s5p_mfc_hw_call(dev->mfc_ops, get_int_err, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 650 | mfc_debug(1, "Int reason: %d (err: %08x)\n", reason, err); |
| 651 | switch (reason) { |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 652 | case S5P_MFC_R2H_CMD_ERR_RET: |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 653 | /* An error has occurred */ |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 654 | if (ctx->state == MFCINST_RUNNING && |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 655 | s5p_mfc_hw_call(dev->mfc_ops, err_dec, err) >= |
| 656 | dev->warn_start) |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 657 | s5p_mfc_handle_frame(ctx, reason, err); |
| 658 | else |
Kamil Debski | 7296e25 | 2012-12-21 05:32:59 -0300 | [diff] [blame] | 659 | s5p_mfc_handle_error(dev, ctx, reason, err); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 660 | clear_bit(0, &dev->enter_suspend); |
| 661 | break; |
| 662 | |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 663 | case S5P_MFC_R2H_CMD_SLICE_DONE_RET: |
| 664 | case S5P_MFC_R2H_CMD_FIELD_DONE_RET: |
| 665 | case S5P_MFC_R2H_CMD_FRAME_DONE_RET: |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 666 | if (ctx->c_ops->post_frame_start) { |
| 667 | if (ctx->c_ops->post_frame_start(ctx)) |
| 668 | mfc_err("post_frame_start() failed\n"); |
Andrzej Hajda | 96c5777 | 2015-10-07 07:15:31 -0300 | [diff] [blame] | 669 | |
| 670 | if (ctx->state == MFCINST_FINISHING && |
| 671 | list_empty(&ctx->ref_queue)) { |
| 672 | s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev); |
| 673 | s5p_mfc_handle_stream_complete(ctx); |
| 674 | break; |
| 675 | } |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 676 | s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 677 | wake_up_ctx(ctx, reason, err); |
Pawel Osciak | 9a7bc6b | 2014-10-21 08:07:01 -0300 | [diff] [blame] | 678 | WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 679 | s5p_mfc_clock_off(); |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 680 | s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 681 | } else { |
| 682 | s5p_mfc_handle_frame(ctx, reason, err); |
| 683 | } |
| 684 | break; |
| 685 | |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 686 | case S5P_MFC_R2H_CMD_SEQ_DONE_RET: |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 687 | s5p_mfc_handle_seq_done(ctx, reason, err); |
| 688 | break; |
| 689 | |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 690 | case S5P_MFC_R2H_CMD_OPEN_INSTANCE_RET: |
| 691 | ctx->inst_no = s5p_mfc_hw_call(dev->mfc_ops, get_inst_no, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 692 | ctx->state = MFCINST_GOT_INST; |
| 693 | clear_work_bit(ctx); |
| 694 | wake_up(&ctx->queue); |
| 695 | goto irq_cleanup_hw; |
| 696 | |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 697 | case S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET: |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 698 | clear_work_bit(ctx); |
Pawel Osciak | 9d87e83 | 2014-05-19 09:33:00 -0300 | [diff] [blame] | 699 | ctx->inst_no = MFC_NO_INSTANCE_SET; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 700 | ctx->state = MFCINST_FREE; |
| 701 | wake_up(&ctx->queue); |
| 702 | goto irq_cleanup_hw; |
| 703 | |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 704 | case S5P_MFC_R2H_CMD_SYS_INIT_RET: |
| 705 | case S5P_MFC_R2H_CMD_FW_STATUS_RET: |
| 706 | case S5P_MFC_R2H_CMD_SLEEP_RET: |
| 707 | case S5P_MFC_R2H_CMD_WAKEUP_RET: |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 708 | if (ctx) |
| 709 | clear_work_bit(ctx); |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 710 | s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 711 | wake_up_dev(dev, reason, err); |
| 712 | clear_bit(0, &dev->hw_lock); |
| 713 | clear_bit(0, &dev->enter_suspend); |
| 714 | break; |
| 715 | |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 716 | case S5P_MFC_R2H_CMD_INIT_BUFFERS_RET: |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 717 | s5p_mfc_handle_init_buffers(ctx, reason, err); |
| 718 | break; |
Andrzej Hajda | f9f715a | 2012-08-21 08:05:32 -0300 | [diff] [blame] | 719 | |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 720 | case S5P_MFC_R2H_CMD_COMPLETE_SEQ_RET: |
Andrzej Hajda | 96c5777 | 2015-10-07 07:15:31 -0300 | [diff] [blame] | 721 | s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev); |
| 722 | ctx->int_type = reason; |
| 723 | ctx->int_err = err; |
| 724 | s5p_mfc_handle_stream_complete(ctx); |
Andrzej Hajda | f9f715a | 2012-08-21 08:05:32 -0300 | [diff] [blame] | 725 | break; |
| 726 | |
Arun Kumar K | 8f23cc0 | 2012-11-22 06:15:55 -0300 | [diff] [blame] | 727 | case S5P_MFC_R2H_CMD_DPB_FLUSH_RET: |
| 728 | clear_work_bit(ctx); |
| 729 | ctx->state = MFCINST_RUNNING; |
| 730 | wake_up(&ctx->queue); |
| 731 | goto irq_cleanup_hw; |
| 732 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 733 | default: |
| 734 | mfc_debug(2, "Unknown int reason\n"); |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 735 | s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 736 | } |
| 737 | mfc_debug_leave(); |
| 738 | return IRQ_HANDLED; |
| 739 | irq_cleanup_hw: |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 740 | s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 741 | ctx->int_type = reason; |
| 742 | ctx->int_err = err; |
| 743 | ctx->int_cond = 1; |
| 744 | if (test_and_clear_bit(0, &dev->hw_lock) == 0) |
| 745 | mfc_err("Failed to unlock hw\n"); |
| 746 | |
| 747 | s5p_mfc_clock_off(); |
| 748 | |
Kamil Debski | e2c3be2 | 2014-09-11 10:27:20 -0300 | [diff] [blame] | 749 | s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 750 | mfc_debug(2, "Exit via irq_cleanup_hw\n"); |
| 751 | return IRQ_HANDLED; |
| 752 | } |
| 753 | |
| 754 | /* Open an MFC node */ |
| 755 | static int s5p_mfc_open(struct file *file) |
| 756 | { |
Marek Szyprowski | b80cb8d | 2013-12-03 10:12:51 -0300 | [diff] [blame] | 757 | struct video_device *vdev = video_devdata(file); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 758 | struct s5p_mfc_dev *dev = video_drvdata(file); |
| 759 | struct s5p_mfc_ctx *ctx = NULL; |
| 760 | struct vb2_queue *q; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 761 | int ret = 0; |
| 762 | |
| 763 | mfc_debug_enter(); |
Hans Verkuil | bc73830 | 2012-06-24 07:13:33 -0300 | [diff] [blame] | 764 | if (mutex_lock_interruptible(&dev->mfc_mutex)) |
| 765 | return -ERESTARTSYS; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 766 | dev->num_inst++; /* It is guarded by mfc_mutex in vfd */ |
| 767 | /* Allocate memory for context */ |
Sachin Kamat | bae061b | 2012-08-17 03:22:55 -0300 | [diff] [blame] | 768 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 769 | if (!ctx) { |
| 770 | mfc_err("Not enough memory\n"); |
| 771 | ret = -ENOMEM; |
| 772 | goto err_alloc; |
| 773 | } |
Zhaowei Yuan | 55647a9 | 2014-07-23 01:06:12 -0300 | [diff] [blame] | 774 | v4l2_fh_init(&ctx->fh, vdev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 775 | file->private_data = &ctx->fh; |
| 776 | v4l2_fh_add(&ctx->fh); |
| 777 | ctx->dev = dev; |
| 778 | INIT_LIST_HEAD(&ctx->src_queue); |
| 779 | INIT_LIST_HEAD(&ctx->dst_queue); |
| 780 | ctx->src_queue_cnt = 0; |
| 781 | ctx->dst_queue_cnt = 0; |
| 782 | /* Get context number */ |
| 783 | ctx->num = 0; |
| 784 | while (dev->ctx[ctx->num]) { |
| 785 | ctx->num++; |
| 786 | if (ctx->num >= MFC_NUM_CONTEXTS) { |
| 787 | mfc_err("Too many open contexts\n"); |
| 788 | ret = -EBUSY; |
| 789 | goto err_no_ctx; |
| 790 | } |
| 791 | } |
| 792 | /* Mark context as idle */ |
Andrzej Hajda | 7fb89ec | 2012-08-14 06:13:40 -0300 | [diff] [blame] | 793 | clear_work_bit_irqsave(ctx); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 794 | dev->ctx[ctx->num] = ctx; |
Marek Szyprowski | b80cb8d | 2013-12-03 10:12:51 -0300 | [diff] [blame] | 795 | if (vdev == dev->vfd_dec) { |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 796 | ctx->type = MFCINST_DECODER; |
| 797 | ctx->c_ops = get_dec_codec_ops(); |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 798 | s5p_mfc_dec_init(ctx); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 799 | /* Setup ctrl handler */ |
| 800 | ret = s5p_mfc_dec_ctrls_setup(ctx); |
| 801 | if (ret) { |
| 802 | mfc_err("Failed to setup mfc controls\n"); |
| 803 | goto err_ctrls_setup; |
| 804 | } |
Marek Szyprowski | b80cb8d | 2013-12-03 10:12:51 -0300 | [diff] [blame] | 805 | } else if (vdev == dev->vfd_enc) { |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 806 | ctx->type = MFCINST_ENCODER; |
| 807 | ctx->c_ops = get_enc_codec_ops(); |
| 808 | /* only for encoder */ |
| 809 | INIT_LIST_HEAD(&ctx->ref_queue); |
| 810 | ctx->ref_queue_cnt = 0; |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 811 | s5p_mfc_enc_init(ctx); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 812 | /* Setup ctrl handler */ |
| 813 | ret = s5p_mfc_enc_ctrls_setup(ctx); |
| 814 | if (ret) { |
| 815 | mfc_err("Failed to setup mfc controls\n"); |
| 816 | goto err_ctrls_setup; |
| 817 | } |
| 818 | } else { |
| 819 | ret = -ENOENT; |
| 820 | goto err_bad_node; |
| 821 | } |
| 822 | ctx->fh.ctrl_handler = &ctx->ctrl_handler; |
Pawel Osciak | 9d87e83 | 2014-05-19 09:33:00 -0300 | [diff] [blame] | 823 | ctx->inst_no = MFC_NO_INSTANCE_SET; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 824 | /* Load firmware if this is the first instance */ |
| 825 | if (dev->num_inst == 1) { |
| 826 | dev->watchdog_timer.expires = jiffies + |
| 827 | msecs_to_jiffies(MFC_WATCHDOG_INTERVAL); |
| 828 | add_timer(&dev->watchdog_timer); |
| 829 | ret = s5p_mfc_power_on(); |
| 830 | if (ret < 0) { |
| 831 | mfc_err("power on failed\n"); |
| 832 | goto err_pwr_enable; |
| 833 | } |
| 834 | s5p_mfc_clock_on(); |
Kamil Debski | 2e731e4 | 2013-01-03 11:02:07 -0300 | [diff] [blame] | 835 | ret = s5p_mfc_load_firmware(dev); |
| 836 | if (ret) { |
| 837 | s5p_mfc_clock_off(); |
| 838 | goto err_load_fw; |
| 839 | } |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 840 | /* Init the FW */ |
| 841 | ret = s5p_mfc_init_hw(dev); |
Kamil Debski | 2e731e4 | 2013-01-03 11:02:07 -0300 | [diff] [blame] | 842 | s5p_mfc_clock_off(); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 843 | if (ret) |
| 844 | goto err_init_hw; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 845 | } |
| 846 | /* Init videobuf2 queue for CAPTURE */ |
| 847 | q = &ctx->vq_dst; |
| 848 | q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 849 | q->drv_priv = &ctx->fh; |
Prabhakar Lad | 654a731 | 2014-11-26 19:42:32 -0300 | [diff] [blame] | 850 | q->lock = &dev->mfc_mutex; |
Marek Szyprowski | b80cb8d | 2013-12-03 10:12:51 -0300 | [diff] [blame] | 851 | if (vdev == dev->vfd_dec) { |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 852 | q->io_modes = VB2_MMAP; |
| 853 | q->ops = get_dec_queue_ops(); |
Marek Szyprowski | b80cb8d | 2013-12-03 10:12:51 -0300 | [diff] [blame] | 854 | } else if (vdev == dev->vfd_enc) { |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 855 | q->io_modes = VB2_MMAP | VB2_USERPTR; |
| 856 | q->ops = get_enc_queue_ops(); |
| 857 | } else { |
| 858 | ret = -ENOENT; |
| 859 | goto err_queue_init; |
| 860 | } |
Rasmus Villemoes | 749ae71 | 2014-10-21 11:55:35 -0300 | [diff] [blame] | 861 | q->mem_ops = &vb2_dma_contig_memops; |
Sakari Ailus | ade4868 | 2014-02-25 19:12:19 -0300 | [diff] [blame] | 862 | q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 863 | ret = vb2_queue_init(q); |
| 864 | if (ret) { |
| 865 | mfc_err("Failed to initialize videobuf2 queue(capture)\n"); |
| 866 | goto err_queue_init; |
| 867 | } |
| 868 | /* Init videobuf2 queue for OUTPUT */ |
| 869 | q = &ctx->vq_src; |
| 870 | q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 871 | q->io_modes = VB2_MMAP; |
| 872 | q->drv_priv = &ctx->fh; |
Kamil Debski | 41f03a0 | 2015-03-03 11:32:58 -0300 | [diff] [blame] | 873 | q->lock = &dev->mfc_mutex; |
Marek Szyprowski | b80cb8d | 2013-12-03 10:12:51 -0300 | [diff] [blame] | 874 | if (vdev == dev->vfd_dec) { |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 875 | q->io_modes = VB2_MMAP; |
| 876 | q->ops = get_dec_queue_ops(); |
Marek Szyprowski | b80cb8d | 2013-12-03 10:12:51 -0300 | [diff] [blame] | 877 | } else if (vdev == dev->vfd_enc) { |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 878 | q->io_modes = VB2_MMAP | VB2_USERPTR; |
| 879 | q->ops = get_enc_queue_ops(); |
| 880 | } else { |
| 881 | ret = -ENOENT; |
| 882 | goto err_queue_init; |
| 883 | } |
Kamil Debski | e6c9dec | 2015-02-23 09:26:19 -0300 | [diff] [blame] | 884 | /* One way to indicate end-of-stream for MFC is to set the |
| 885 | * bytesused == 0. However by default videobuf2 handles bytesused |
| 886 | * equal to 0 as a special case and changes its value to the size |
| 887 | * of the buffer. Set the allow_zero_bytesused flag so that videobuf2 |
| 888 | * will keep the value of bytesused intact. |
| 889 | */ |
| 890 | q->allow_zero_bytesused = 1; |
Rasmus Villemoes | 749ae71 | 2014-10-21 11:55:35 -0300 | [diff] [blame] | 891 | q->mem_ops = &vb2_dma_contig_memops; |
Sakari Ailus | ade4868 | 2014-02-25 19:12:19 -0300 | [diff] [blame] | 892 | q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 893 | ret = vb2_queue_init(q); |
| 894 | if (ret) { |
| 895 | mfc_err("Failed to initialize videobuf2 queue(output)\n"); |
| 896 | goto err_queue_init; |
| 897 | } |
| 898 | init_waitqueue_head(&ctx->queue); |
Hans Verkuil | bc73830 | 2012-06-24 07:13:33 -0300 | [diff] [blame] | 899 | mutex_unlock(&dev->mfc_mutex); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 900 | mfc_debug_leave(); |
| 901 | return ret; |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 902 | /* Deinit when failure occurred */ |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 903 | err_queue_init: |
Kamil Debski | 2e731e4 | 2013-01-03 11:02:07 -0300 | [diff] [blame] | 904 | if (dev->num_inst == 1) |
| 905 | s5p_mfc_deinit_hw(dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 906 | err_init_hw: |
Kamil Debski | 2e731e4 | 2013-01-03 11:02:07 -0300 | [diff] [blame] | 907 | err_load_fw: |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 908 | err_pwr_enable: |
| 909 | if (dev->num_inst == 1) { |
| 910 | if (s5p_mfc_power_off() < 0) |
| 911 | mfc_err("power off failed\n"); |
Kamil Debski | 1b73ba0 | 2012-11-22 10:00:28 -0300 | [diff] [blame] | 912 | del_timer_sync(&dev->watchdog_timer); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 913 | } |
| 914 | err_ctrls_setup: |
| 915 | s5p_mfc_dec_ctrls_delete(ctx); |
| 916 | err_bad_node: |
Kamil Debski | 1b73ba0 | 2012-11-22 10:00:28 -0300 | [diff] [blame] | 917 | dev->ctx[ctx->num] = NULL; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 918 | err_no_ctx: |
| 919 | v4l2_fh_del(&ctx->fh); |
| 920 | v4l2_fh_exit(&ctx->fh); |
| 921 | kfree(ctx); |
| 922 | err_alloc: |
| 923 | dev->num_inst--; |
Hans Verkuil | bc73830 | 2012-06-24 07:13:33 -0300 | [diff] [blame] | 924 | mutex_unlock(&dev->mfc_mutex); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 925 | mfc_debug_leave(); |
| 926 | return ret; |
| 927 | } |
| 928 | |
| 929 | /* Release MFC context */ |
| 930 | static int s5p_mfc_release(struct file *file) |
| 931 | { |
| 932 | struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data); |
| 933 | struct s5p_mfc_dev *dev = ctx->dev; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 934 | |
| 935 | mfc_debug_enter(); |
Hans Verkuil | bc73830 | 2012-06-24 07:13:33 -0300 | [diff] [blame] | 936 | mutex_lock(&dev->mfc_mutex); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 937 | s5p_mfc_clock_on(); |
| 938 | vb2_queue_release(&ctx->vq_src); |
| 939 | vb2_queue_release(&ctx->vq_dst); |
| 940 | /* Mark context as idle */ |
Andrzej Hajda | 7fb89ec | 2012-08-14 06:13:40 -0300 | [diff] [blame] | 941 | clear_work_bit_irqsave(ctx); |
Pawel Osciak | 9d87e83 | 2014-05-19 09:33:00 -0300 | [diff] [blame] | 942 | /* If instance was initialised and not yet freed, |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 943 | * return instance and free resources */ |
Pawel Osciak | 9d87e83 | 2014-05-19 09:33:00 -0300 | [diff] [blame] | 944 | if (ctx->state != MFCINST_FREE && ctx->state != MFCINST_INIT) { |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 945 | mfc_debug(2, "Has to free instance\n"); |
Pawel Osciak | 818cd91 | 2014-05-19 09:32:59 -0300 | [diff] [blame] | 946 | s5p_mfc_close_mfc_inst(dev, ctx); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 947 | } |
| 948 | /* hardware locking scheme */ |
| 949 | if (dev->curr_ctx == ctx->num) |
| 950 | clear_bit(0, &dev->hw_lock); |
| 951 | dev->num_inst--; |
| 952 | if (dev->num_inst == 0) { |
Kamil Debski | 2e731e4 | 2013-01-03 11:02:07 -0300 | [diff] [blame] | 953 | mfc_debug(2, "Last instance\n"); |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 954 | s5p_mfc_deinit_hw(dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 955 | del_timer_sync(&dev->watchdog_timer); |
| 956 | if (s5p_mfc_power_off() < 0) |
| 957 | mfc_err("Power off failed\n"); |
| 958 | } |
| 959 | mfc_debug(2, "Shutting down clock\n"); |
| 960 | s5p_mfc_clock_off(); |
Sachin Kamat | 1259762 | 2012-05-10 03:32:00 -0300 | [diff] [blame] | 961 | dev->ctx[ctx->num] = NULL; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 962 | s5p_mfc_dec_ctrls_delete(ctx); |
| 963 | v4l2_fh_del(&ctx->fh); |
| 964 | v4l2_fh_exit(&ctx->fh); |
| 965 | kfree(ctx); |
| 966 | mfc_debug_leave(); |
Hans Verkuil | bc73830 | 2012-06-24 07:13:33 -0300 | [diff] [blame] | 967 | mutex_unlock(&dev->mfc_mutex); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 968 | return 0; |
| 969 | } |
| 970 | |
| 971 | /* Poll */ |
| 972 | static unsigned int s5p_mfc_poll(struct file *file, |
| 973 | struct poll_table_struct *wait) |
| 974 | { |
| 975 | struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data); |
| 976 | struct s5p_mfc_dev *dev = ctx->dev; |
| 977 | struct vb2_queue *src_q, *dst_q; |
| 978 | struct vb2_buffer *src_vb = NULL, *dst_vb = NULL; |
| 979 | unsigned int rc = 0; |
| 980 | unsigned long flags; |
| 981 | |
Hans Verkuil | bc73830 | 2012-06-24 07:13:33 -0300 | [diff] [blame] | 982 | mutex_lock(&dev->mfc_mutex); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 983 | src_q = &ctx->vq_src; |
| 984 | dst_q = &ctx->vq_dst; |
| 985 | /* |
| 986 | * There has to be at least one buffer queued on each queued_list, which |
| 987 | * means either in driver already or waiting for driver to claim it |
| 988 | * and start processing. |
| 989 | */ |
| 990 | if ((!src_q->streaming || list_empty(&src_q->queued_list)) |
| 991 | && (!dst_q->streaming || list_empty(&dst_q->queued_list))) { |
| 992 | rc = POLLERR; |
| 993 | goto end; |
| 994 | } |
| 995 | mutex_unlock(&dev->mfc_mutex); |
Andrzej Hajda | f9f715a | 2012-08-21 08:05:32 -0300 | [diff] [blame] | 996 | poll_wait(file, &ctx->fh.wait, wait); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 997 | poll_wait(file, &src_q->done_wq, wait); |
| 998 | poll_wait(file, &dst_q->done_wq, wait); |
| 999 | mutex_lock(&dev->mfc_mutex); |
Andrzej Hajda | f9f715a | 2012-08-21 08:05:32 -0300 | [diff] [blame] | 1000 | if (v4l2_event_pending(&ctx->fh)) |
| 1001 | rc |= POLLPRI; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1002 | spin_lock_irqsave(&src_q->done_lock, flags); |
| 1003 | if (!list_empty(&src_q->done_list)) |
| 1004 | src_vb = list_first_entry(&src_q->done_list, struct vb2_buffer, |
| 1005 | done_entry); |
| 1006 | if (src_vb && (src_vb->state == VB2_BUF_STATE_DONE |
| 1007 | || src_vb->state == VB2_BUF_STATE_ERROR)) |
| 1008 | rc |= POLLOUT | POLLWRNORM; |
| 1009 | spin_unlock_irqrestore(&src_q->done_lock, flags); |
| 1010 | spin_lock_irqsave(&dst_q->done_lock, flags); |
| 1011 | if (!list_empty(&dst_q->done_list)) |
| 1012 | dst_vb = list_first_entry(&dst_q->done_list, struct vb2_buffer, |
| 1013 | done_entry); |
| 1014 | if (dst_vb && (dst_vb->state == VB2_BUF_STATE_DONE |
| 1015 | || dst_vb->state == VB2_BUF_STATE_ERROR)) |
| 1016 | rc |= POLLIN | POLLRDNORM; |
| 1017 | spin_unlock_irqrestore(&dst_q->done_lock, flags); |
| 1018 | end: |
Hans Verkuil | bc73830 | 2012-06-24 07:13:33 -0300 | [diff] [blame] | 1019 | mutex_unlock(&dev->mfc_mutex); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1020 | return rc; |
| 1021 | } |
| 1022 | |
| 1023 | /* Mmap */ |
| 1024 | static int s5p_mfc_mmap(struct file *file, struct vm_area_struct *vma) |
| 1025 | { |
| 1026 | struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data); |
Hans Verkuil | bc73830 | 2012-06-24 07:13:33 -0300 | [diff] [blame] | 1027 | struct s5p_mfc_dev *dev = ctx->dev; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1028 | unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; |
| 1029 | int ret; |
Hans Verkuil | bc73830 | 2012-06-24 07:13:33 -0300 | [diff] [blame] | 1030 | |
| 1031 | if (mutex_lock_interruptible(&dev->mfc_mutex)) |
| 1032 | return -ERESTARTSYS; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1033 | if (offset < DST_QUEUE_OFF_BASE) { |
| 1034 | mfc_debug(2, "mmaping source\n"); |
| 1035 | ret = vb2_mmap(&ctx->vq_src, vma); |
| 1036 | } else { /* capture */ |
| 1037 | mfc_debug(2, "mmaping destination\n"); |
| 1038 | vma->vm_pgoff -= (DST_QUEUE_OFF_BASE >> PAGE_SHIFT); |
| 1039 | ret = vb2_mmap(&ctx->vq_dst, vma); |
| 1040 | } |
Hans Verkuil | bc73830 | 2012-06-24 07:13:33 -0300 | [diff] [blame] | 1041 | mutex_unlock(&dev->mfc_mutex); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1042 | return ret; |
| 1043 | } |
| 1044 | |
| 1045 | /* v4l2 ops */ |
| 1046 | static const struct v4l2_file_operations s5p_mfc_fops = { |
| 1047 | .owner = THIS_MODULE, |
| 1048 | .open = s5p_mfc_open, |
| 1049 | .release = s5p_mfc_release, |
| 1050 | .poll = s5p_mfc_poll, |
| 1051 | .unlocked_ioctl = video_ioctl2, |
| 1052 | .mmap = s5p_mfc_mmap, |
| 1053 | }; |
| 1054 | |
| 1055 | static int match_child(struct device *dev, void *data) |
| 1056 | { |
| 1057 | if (!dev_name(dev)) |
| 1058 | return 0; |
| 1059 | return !strcmp(dev_name(dev), (char *)data); |
| 1060 | } |
| 1061 | |
Arun Kumar K | b27a23b | 2012-10-25 05:24:14 -0300 | [diff] [blame] | 1062 | static void *mfc_get_drv_data(struct platform_device *pdev); |
| 1063 | |
Arun Kumar K | 6e83e6e | 2013-01-18 15:42:34 -0300 | [diff] [blame] | 1064 | static int s5p_mfc_alloc_memdevs(struct s5p_mfc_dev *dev) |
| 1065 | { |
Sylwester Nawrocki | 65fccab | 2013-04-10 07:17:52 -0300 | [diff] [blame] | 1066 | unsigned int mem_info[2] = { }; |
Arun Kumar K | 6e83e6e | 2013-01-18 15:42:34 -0300 | [diff] [blame] | 1067 | |
| 1068 | dev->mem_dev_l = devm_kzalloc(&dev->plat_dev->dev, |
| 1069 | sizeof(struct device), GFP_KERNEL); |
| 1070 | if (!dev->mem_dev_l) { |
| 1071 | mfc_err("Not enough memory\n"); |
| 1072 | return -ENOMEM; |
| 1073 | } |
| 1074 | device_initialize(dev->mem_dev_l); |
| 1075 | of_property_read_u32_array(dev->plat_dev->dev.of_node, |
| 1076 | "samsung,mfc-l", mem_info, 2); |
| 1077 | if (dma_declare_coherent_memory(dev->mem_dev_l, mem_info[0], |
| 1078 | mem_info[0], mem_info[1], |
| 1079 | DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE) == 0) { |
| 1080 | mfc_err("Failed to declare coherent memory for\n" |
| 1081 | "MFC device\n"); |
| 1082 | return -ENOMEM; |
| 1083 | } |
| 1084 | |
| 1085 | dev->mem_dev_r = devm_kzalloc(&dev->plat_dev->dev, |
| 1086 | sizeof(struct device), GFP_KERNEL); |
| 1087 | if (!dev->mem_dev_r) { |
| 1088 | mfc_err("Not enough memory\n"); |
| 1089 | return -ENOMEM; |
| 1090 | } |
| 1091 | device_initialize(dev->mem_dev_r); |
| 1092 | of_property_read_u32_array(dev->plat_dev->dev.of_node, |
| 1093 | "samsung,mfc-r", mem_info, 2); |
| 1094 | if (dma_declare_coherent_memory(dev->mem_dev_r, mem_info[0], |
| 1095 | mem_info[0], mem_info[1], |
| 1096 | DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE) == 0) { |
| 1097 | pr_err("Failed to declare coherent memory for\n" |
| 1098 | "MFC device\n"); |
| 1099 | return -ENOMEM; |
| 1100 | } |
| 1101 | return 0; |
| 1102 | } |
| 1103 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1104 | /* MFC probe function */ |
Kamil Debski | 1e393e9 | 2011-08-08 13:12:51 -0300 | [diff] [blame] | 1105 | static int s5p_mfc_probe(struct platform_device *pdev) |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1106 | { |
| 1107 | struct s5p_mfc_dev *dev; |
| 1108 | struct video_device *vfd; |
| 1109 | struct resource *res; |
| 1110 | int ret; |
| 1111 | |
| 1112 | pr_debug("%s++\n", __func__); |
Sachin Kamat | bae061b | 2012-08-17 03:22:55 -0300 | [diff] [blame] | 1113 | dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1114 | if (!dev) { |
| 1115 | dev_err(&pdev->dev, "Not enough memory for MFC device\n"); |
| 1116 | return -ENOMEM; |
| 1117 | } |
| 1118 | |
| 1119 | spin_lock_init(&dev->irqlock); |
| 1120 | spin_lock_init(&dev->condlock); |
| 1121 | dev->plat_dev = pdev; |
| 1122 | if (!dev->plat_dev) { |
| 1123 | dev_err(&pdev->dev, "No platform data specified\n"); |
Sachin Kamat | d310f47 | 2012-05-14 08:22:27 -0300 | [diff] [blame] | 1124 | return -ENODEV; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1125 | } |
| 1126 | |
Arun Kumar K | b27a23b | 2012-10-25 05:24:14 -0300 | [diff] [blame] | 1127 | dev->variant = mfc_get_drv_data(pdev); |
Arun Kumar K | 8f532a7 | 2012-10-03 22:19:09 -0300 | [diff] [blame] | 1128 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1129 | ret = s5p_mfc_init_pm(dev); |
| 1130 | if (ret < 0) { |
| 1131 | dev_err(&pdev->dev, "failed to get mfc clock source\n"); |
Sachin Kamat | d310f47 | 2012-05-14 08:22:27 -0300 | [diff] [blame] | 1132 | return ret; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1136 | |
Thierry Reding | f23999e | 2013-01-21 06:09:07 -0300 | [diff] [blame] | 1137 | dev->regs_base = devm_ioremap_resource(&pdev->dev, res); |
| 1138 | if (IS_ERR(dev->regs_base)) |
| 1139 | return PTR_ERR(dev->regs_base); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1140 | |
| 1141 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 1142 | if (res == NULL) { |
| 1143 | dev_err(&pdev->dev, "failed to get irq resource\n"); |
| 1144 | ret = -ENOENT; |
Sachin Kamat | d310f47 | 2012-05-14 08:22:27 -0300 | [diff] [blame] | 1145 | goto err_res; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1146 | } |
| 1147 | dev->irq = res->start; |
Sachin Kamat | d310f47 | 2012-05-14 08:22:27 -0300 | [diff] [blame] | 1148 | ret = devm_request_irq(&pdev->dev, dev->irq, s5p_mfc_irq, |
Michael Opdenacker | 1957f0d | 2013-10-13 02:58:39 -0300 | [diff] [blame] | 1149 | 0, pdev->name, dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1150 | if (ret) { |
| 1151 | dev_err(&pdev->dev, "Failed to install irq (%d)\n", ret); |
Sachin Kamat | d310f47 | 2012-05-14 08:22:27 -0300 | [diff] [blame] | 1152 | goto err_res; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1153 | } |
| 1154 | |
Arun Kumar K | b27a23b | 2012-10-25 05:24:14 -0300 | [diff] [blame] | 1155 | if (pdev->dev.of_node) { |
Wei Yongjun | d68b44e | 2013-04-17 23:18:19 -0300 | [diff] [blame] | 1156 | ret = s5p_mfc_alloc_memdevs(dev); |
| 1157 | if (ret < 0) |
Arun Kumar K | b27a23b | 2012-10-25 05:24:14 -0300 | [diff] [blame] | 1158 | goto err_res; |
Arun Kumar K | b27a23b | 2012-10-25 05:24:14 -0300 | [diff] [blame] | 1159 | } else { |
| 1160 | dev->mem_dev_l = device_find_child(&dev->plat_dev->dev, |
| 1161 | "s5p-mfc-l", match_child); |
| 1162 | if (!dev->mem_dev_l) { |
| 1163 | mfc_err("Mem child (L) device get failed\n"); |
| 1164 | ret = -ENODEV; |
| 1165 | goto err_res; |
| 1166 | } |
| 1167 | dev->mem_dev_r = device_find_child(&dev->plat_dev->dev, |
| 1168 | "s5p-mfc-r", match_child); |
| 1169 | if (!dev->mem_dev_r) { |
| 1170 | mfc_err("Mem child (R) device get failed\n"); |
| 1171 | ret = -ENODEV; |
| 1172 | goto err_res; |
| 1173 | } |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | dev->alloc_ctx[0] = vb2_dma_contig_init_ctx(dev->mem_dev_l); |
Kamil Debski | ef89fff | 2013-01-03 07:06:03 -0300 | [diff] [blame] | 1177 | if (IS_ERR(dev->alloc_ctx[0])) { |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1178 | ret = PTR_ERR(dev->alloc_ctx[0]); |
Sachin Kamat | d310f47 | 2012-05-14 08:22:27 -0300 | [diff] [blame] | 1179 | goto err_res; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1180 | } |
| 1181 | dev->alloc_ctx[1] = vb2_dma_contig_init_ctx(dev->mem_dev_r); |
Kamil Debski | ef89fff | 2013-01-03 07:06:03 -0300 | [diff] [blame] | 1182 | if (IS_ERR(dev->alloc_ctx[1])) { |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1183 | ret = PTR_ERR(dev->alloc_ctx[1]); |
| 1184 | goto err_mem_init_ctx_1; |
| 1185 | } |
| 1186 | |
| 1187 | mutex_init(&dev->mfc_mutex); |
| 1188 | |
Kamil Debski | 2e731e4 | 2013-01-03 11:02:07 -0300 | [diff] [blame] | 1189 | ret = s5p_mfc_alloc_firmware(dev); |
| 1190 | if (ret) |
| 1191 | goto err_alloc_fw; |
| 1192 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1193 | ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev); |
| 1194 | if (ret) |
| 1195 | goto err_v4l2_dev_reg; |
| 1196 | init_waitqueue_head(&dev->queue); |
| 1197 | |
| 1198 | /* decoder */ |
| 1199 | vfd = video_device_alloc(); |
| 1200 | if (!vfd) { |
| 1201 | v4l2_err(&dev->v4l2_dev, "Failed to allocate video device\n"); |
| 1202 | ret = -ENOMEM; |
| 1203 | goto err_dec_alloc; |
| 1204 | } |
Joonyoung Shim | d0ce898 | 2014-02-20 23:22:12 -0300 | [diff] [blame] | 1205 | vfd->fops = &s5p_mfc_fops; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1206 | vfd->ioctl_ops = get_dec_v4l2_ioctl_ops(); |
Joonyoung Shim | d0ce898 | 2014-02-20 23:22:12 -0300 | [diff] [blame] | 1207 | vfd->release = video_device_release; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1208 | vfd->lock = &dev->mfc_mutex; |
| 1209 | vfd->v4l2_dev = &dev->v4l2_dev; |
Hans Verkuil | 954f340 | 2012-09-05 06:05:50 -0300 | [diff] [blame] | 1210 | vfd->vfl_dir = VFL_DIR_M2M; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1211 | snprintf(vfd->name, sizeof(vfd->name), "%s", S5P_MFC_DEC_NAME); |
| 1212 | dev->vfd_dec = vfd; |
| 1213 | ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0); |
| 1214 | if (ret) { |
| 1215 | v4l2_err(&dev->v4l2_dev, "Failed to register video device\n"); |
| 1216 | video_device_release(vfd); |
| 1217 | goto err_dec_reg; |
| 1218 | } |
| 1219 | v4l2_info(&dev->v4l2_dev, |
| 1220 | "decoder registered as /dev/video%d\n", vfd->num); |
| 1221 | video_set_drvdata(vfd, dev); |
| 1222 | |
| 1223 | /* encoder */ |
| 1224 | vfd = video_device_alloc(); |
| 1225 | if (!vfd) { |
| 1226 | v4l2_err(&dev->v4l2_dev, "Failed to allocate video device\n"); |
| 1227 | ret = -ENOMEM; |
| 1228 | goto err_enc_alloc; |
| 1229 | } |
Joonyoung Shim | d0ce898 | 2014-02-20 23:22:12 -0300 | [diff] [blame] | 1230 | vfd->fops = &s5p_mfc_fops; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1231 | vfd->ioctl_ops = get_enc_v4l2_ioctl_ops(); |
Joonyoung Shim | d0ce898 | 2014-02-20 23:22:12 -0300 | [diff] [blame] | 1232 | vfd->release = video_device_release; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1233 | vfd->lock = &dev->mfc_mutex; |
| 1234 | vfd->v4l2_dev = &dev->v4l2_dev; |
Arun Kumar K | cdcf45e | 2012-10-04 16:14:56 -0300 | [diff] [blame] | 1235 | vfd->vfl_dir = VFL_DIR_M2M; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1236 | snprintf(vfd->name, sizeof(vfd->name), "%s", S5P_MFC_ENC_NAME); |
| 1237 | dev->vfd_enc = vfd; |
| 1238 | ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0); |
| 1239 | if (ret) { |
| 1240 | v4l2_err(&dev->v4l2_dev, "Failed to register video device\n"); |
| 1241 | video_device_release(vfd); |
| 1242 | goto err_enc_reg; |
| 1243 | } |
| 1244 | v4l2_info(&dev->v4l2_dev, |
| 1245 | "encoder registered as /dev/video%d\n", vfd->num); |
| 1246 | video_set_drvdata(vfd, dev); |
| 1247 | platform_set_drvdata(pdev, dev); |
| 1248 | |
| 1249 | dev->hw_lock = 0; |
| 1250 | dev->watchdog_workqueue = create_singlethread_workqueue(S5P_MFC_NAME); |
| 1251 | INIT_WORK(&dev->watchdog_work, s5p_mfc_watchdog_worker); |
| 1252 | atomic_set(&dev->watchdog_cnt, 0); |
| 1253 | init_timer(&dev->watchdog_timer); |
| 1254 | dev->watchdog_timer.data = (unsigned long)dev; |
| 1255 | dev->watchdog_timer.function = s5p_mfc_watchdog; |
| 1256 | |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 1257 | /* Initialize HW ops and commands based on MFC version */ |
| 1258 | s5p_mfc_init_hw_ops(dev); |
| 1259 | s5p_mfc_init_hw_cmds(dev); |
Kiran AVND | 6a9c6f68 | 2014-05-19 09:33:05 -0300 | [diff] [blame] | 1260 | s5p_mfc_init_regs(dev); |
Arun Kumar K | 43a1ea1 | 2012-10-03 22:19:08 -0300 | [diff] [blame] | 1261 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1262 | pr_debug("%s--\n", __func__); |
| 1263 | return 0; |
| 1264 | |
| 1265 | /* Deinit MFC if probe had failed */ |
| 1266 | err_enc_reg: |
| 1267 | video_device_release(dev->vfd_enc); |
| 1268 | err_enc_alloc: |
| 1269 | video_unregister_device(dev->vfd_dec); |
| 1270 | err_dec_reg: |
| 1271 | video_device_release(dev->vfd_dec); |
| 1272 | err_dec_alloc: |
| 1273 | v4l2_device_unregister(&dev->v4l2_dev); |
| 1274 | err_v4l2_dev_reg: |
Kamil Debski | 2e731e4 | 2013-01-03 11:02:07 -0300 | [diff] [blame] | 1275 | s5p_mfc_release_firmware(dev); |
| 1276 | err_alloc_fw: |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1277 | vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[1]); |
| 1278 | err_mem_init_ctx_1: |
| 1279 | vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[0]); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1280 | err_res: |
| 1281 | s5p_mfc_final_pm(dev); |
Sachin Kamat | d310f47 | 2012-05-14 08:22:27 -0300 | [diff] [blame] | 1282 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1283 | pr_debug("%s-- with error\n", __func__); |
| 1284 | return ret; |
| 1285 | |
| 1286 | } |
| 1287 | |
| 1288 | /* Remove the driver */ |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1289 | static int s5p_mfc_remove(struct platform_device *pdev) |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1290 | { |
| 1291 | struct s5p_mfc_dev *dev = platform_get_drvdata(pdev); |
| 1292 | |
| 1293 | v4l2_info(&dev->v4l2_dev, "Removing %s\n", pdev->name); |
| 1294 | |
| 1295 | del_timer_sync(&dev->watchdog_timer); |
| 1296 | flush_workqueue(dev->watchdog_workqueue); |
| 1297 | destroy_workqueue(dev->watchdog_workqueue); |
| 1298 | |
| 1299 | video_unregister_device(dev->vfd_enc); |
| 1300 | video_unregister_device(dev->vfd_dec); |
| 1301 | v4l2_device_unregister(&dev->v4l2_dev); |
Kamil Debski | 2e731e4 | 2013-01-03 11:02:07 -0300 | [diff] [blame] | 1302 | s5p_mfc_release_firmware(dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1303 | vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[0]); |
| 1304 | vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[1]); |
Arun Kumar K | 6e83e6e | 2013-01-18 15:42:34 -0300 | [diff] [blame] | 1305 | if (pdev->dev.of_node) { |
| 1306 | put_device(dev->mem_dev_l); |
| 1307 | put_device(dev->mem_dev_r); |
| 1308 | } |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1309 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1310 | s5p_mfc_final_pm(dev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1311 | return 0; |
| 1312 | } |
| 1313 | |
| 1314 | #ifdef CONFIG_PM_SLEEP |
| 1315 | |
| 1316 | static int s5p_mfc_suspend(struct device *dev) |
| 1317 | { |
| 1318 | struct platform_device *pdev = to_platform_device(dev); |
| 1319 | struct s5p_mfc_dev *m_dev = platform_get_drvdata(pdev); |
| 1320 | int ret; |
| 1321 | |
| 1322 | if (m_dev->num_inst == 0) |
| 1323 | return 0; |
Sachin Kamat | 81c9bcf | 2012-09-28 04:01:35 -0300 | [diff] [blame] | 1324 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1325 | if (test_and_set_bit(0, &m_dev->enter_suspend) != 0) { |
| 1326 | mfc_err("Error: going to suspend for a second time\n"); |
| 1327 | return -EIO; |
| 1328 | } |
| 1329 | |
| 1330 | /* Check if we're processing then wait if it necessary. */ |
| 1331 | while (test_and_set_bit(0, &m_dev->hw_lock) != 0) { |
| 1332 | /* Try and lock the HW */ |
| 1333 | /* Wait on the interrupt waitqueue */ |
| 1334 | ret = wait_event_interruptible_timeout(m_dev->queue, |
Prathyush K | 76a4ddb | 2013-10-04 01:47:19 -0300 | [diff] [blame] | 1335 | m_dev->int_cond, msecs_to_jiffies(MFC_INT_TIMEOUT)); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1336 | if (ret == 0) { |
| 1337 | mfc_err("Waiting for hardware to finish timed out\n"); |
Prathyush K | 6437099 | 2014-10-21 08:06:57 -0300 | [diff] [blame] | 1338 | clear_bit(0, &m_dev->enter_suspend); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1339 | return -EIO; |
| 1340 | } |
| 1341 | } |
Sachin Kamat | 81c9bcf | 2012-09-28 04:01:35 -0300 | [diff] [blame] | 1342 | |
Prathyush K | 6437099 | 2014-10-21 08:06:57 -0300 | [diff] [blame] | 1343 | ret = s5p_mfc_sleep(m_dev); |
| 1344 | if (ret) { |
| 1345 | clear_bit(0, &m_dev->enter_suspend); |
| 1346 | clear_bit(0, &m_dev->hw_lock); |
| 1347 | } |
| 1348 | return ret; |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | static int s5p_mfc_resume(struct device *dev) |
| 1352 | { |
| 1353 | struct platform_device *pdev = to_platform_device(dev); |
| 1354 | struct s5p_mfc_dev *m_dev = platform_get_drvdata(pdev); |
| 1355 | |
| 1356 | if (m_dev->num_inst == 0) |
| 1357 | return 0; |
| 1358 | return s5p_mfc_wakeup(m_dev); |
| 1359 | } |
| 1360 | #endif |
| 1361 | |
Rafael J. Wysocki | e243c7c | 2014-12-04 01:10:10 +0100 | [diff] [blame] | 1362 | #ifdef CONFIG_PM |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1363 | static int s5p_mfc_runtime_suspend(struct device *dev) |
| 1364 | { |
| 1365 | struct platform_device *pdev = to_platform_device(dev); |
| 1366 | struct s5p_mfc_dev *m_dev = platform_get_drvdata(pdev); |
| 1367 | |
| 1368 | atomic_set(&m_dev->pm.power, 0); |
| 1369 | return 0; |
| 1370 | } |
| 1371 | |
| 1372 | static int s5p_mfc_runtime_resume(struct device *dev) |
| 1373 | { |
| 1374 | struct platform_device *pdev = to_platform_device(dev); |
| 1375 | struct s5p_mfc_dev *m_dev = platform_get_drvdata(pdev); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1376 | |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1377 | atomic_set(&m_dev->pm.power, 1); |
| 1378 | return 0; |
| 1379 | } |
| 1380 | #endif |
| 1381 | |
| 1382 | /* Power management */ |
| 1383 | static const struct dev_pm_ops s5p_mfc_pm_ops = { |
| 1384 | SET_SYSTEM_SLEEP_PM_OPS(s5p_mfc_suspend, s5p_mfc_resume) |
| 1385 | SET_RUNTIME_PM_OPS(s5p_mfc_runtime_suspend, s5p_mfc_runtime_resume, |
| 1386 | NULL) |
| 1387 | }; |
| 1388 | |
Mauro Carvalho Chehab | ca5ea0c | 2014-09-24 09:08:10 -0300 | [diff] [blame] | 1389 | static struct s5p_mfc_buf_size_v5 mfc_buf_size_v5 = { |
Arun Kumar K | 8f532a7 | 2012-10-03 22:19:09 -0300 | [diff] [blame] | 1390 | .h264_ctx = MFC_H264_CTX_BUF_SIZE, |
| 1391 | .non_h264_ctx = MFC_CTX_BUF_SIZE, |
| 1392 | .dsc = DESC_BUF_SIZE, |
| 1393 | .shm = SHARED_BUF_SIZE, |
| 1394 | }; |
| 1395 | |
Mauro Carvalho Chehab | ca5ea0c | 2014-09-24 09:08:10 -0300 | [diff] [blame] | 1396 | static struct s5p_mfc_buf_size buf_size_v5 = { |
Arun Kumar K | 8f532a7 | 2012-10-03 22:19:09 -0300 | [diff] [blame] | 1397 | .fw = MAX_FW_SIZE, |
| 1398 | .cpb = MAX_CPB_SIZE, |
| 1399 | .priv = &mfc_buf_size_v5, |
| 1400 | }; |
| 1401 | |
Mauro Carvalho Chehab | ca5ea0c | 2014-09-24 09:08:10 -0300 | [diff] [blame] | 1402 | static struct s5p_mfc_buf_align mfc_buf_align_v5 = { |
Arun Kumar K | 8f532a7 | 2012-10-03 22:19:09 -0300 | [diff] [blame] | 1403 | .base = MFC_BASE_ALIGN_ORDER, |
| 1404 | }; |
| 1405 | |
| 1406 | static struct s5p_mfc_variant mfc_drvdata_v5 = { |
| 1407 | .version = MFC_VERSION, |
Kamil Debski | 9aa5f00 | 2014-05-20 10:15:13 -0300 | [diff] [blame] | 1408 | .version_bit = MFC_V5_BIT, |
Arun Kumar K | 8f532a7 | 2012-10-03 22:19:09 -0300 | [diff] [blame] | 1409 | .port_num = MFC_NUM_PORTS, |
| 1410 | .buf_size = &buf_size_v5, |
| 1411 | .buf_align = &mfc_buf_align_v5, |
Arun Kumar K | 77ba6b7 | 2014-05-21 06:29:30 -0300 | [diff] [blame] | 1412 | .fw_name[0] = "s5p-mfc.fw", |
Jeongtae Park | f96f3cf | 2012-10-03 22:19:11 -0300 | [diff] [blame] | 1413 | }; |
| 1414 | |
Mauro Carvalho Chehab | ca5ea0c | 2014-09-24 09:08:10 -0300 | [diff] [blame] | 1415 | static struct s5p_mfc_buf_size_v6 mfc_buf_size_v6 = { |
Jeongtae Park | f96f3cf | 2012-10-03 22:19:11 -0300 | [diff] [blame] | 1416 | .dev_ctx = MFC_CTX_BUF_SIZE_V6, |
| 1417 | .h264_dec_ctx = MFC_H264_DEC_CTX_BUF_SIZE_V6, |
| 1418 | .other_dec_ctx = MFC_OTHER_DEC_CTX_BUF_SIZE_V6, |
| 1419 | .h264_enc_ctx = MFC_H264_ENC_CTX_BUF_SIZE_V6, |
| 1420 | .other_enc_ctx = MFC_OTHER_ENC_CTX_BUF_SIZE_V6, |
| 1421 | }; |
| 1422 | |
Mauro Carvalho Chehab | ca5ea0c | 2014-09-24 09:08:10 -0300 | [diff] [blame] | 1423 | static struct s5p_mfc_buf_size buf_size_v6 = { |
Jeongtae Park | f96f3cf | 2012-10-03 22:19:11 -0300 | [diff] [blame] | 1424 | .fw = MAX_FW_SIZE_V6, |
| 1425 | .cpb = MAX_CPB_SIZE_V6, |
| 1426 | .priv = &mfc_buf_size_v6, |
| 1427 | }; |
| 1428 | |
Mauro Carvalho Chehab | ca5ea0c | 2014-09-24 09:08:10 -0300 | [diff] [blame] | 1429 | static struct s5p_mfc_buf_align mfc_buf_align_v6 = { |
Jeongtae Park | f96f3cf | 2012-10-03 22:19:11 -0300 | [diff] [blame] | 1430 | .base = 0, |
| 1431 | }; |
| 1432 | |
| 1433 | static struct s5p_mfc_variant mfc_drvdata_v6 = { |
| 1434 | .version = MFC_VERSION_V6, |
Kamil Debski | 9aa5f00 | 2014-05-20 10:15:13 -0300 | [diff] [blame] | 1435 | .version_bit = MFC_V6_BIT, |
Jeongtae Park | f96f3cf | 2012-10-03 22:19:11 -0300 | [diff] [blame] | 1436 | .port_num = MFC_NUM_PORTS_V6, |
| 1437 | .buf_size = &buf_size_v6, |
| 1438 | .buf_align = &mfc_buf_align_v6, |
Arun Kumar K | 77ba6b7 | 2014-05-21 06:29:30 -0300 | [diff] [blame] | 1439 | .fw_name[0] = "s5p-mfc-v6.fw", |
| 1440 | /* |
| 1441 | * v6-v2 firmware contains bug fixes and interface change |
| 1442 | * for init buffer command |
| 1443 | */ |
| 1444 | .fw_name[1] = "s5p-mfc-v6-v2.fw", |
Arun Kumar K | 8f532a7 | 2012-10-03 22:19:09 -0300 | [diff] [blame] | 1445 | }; |
| 1446 | |
Mauro Carvalho Chehab | ca5ea0c | 2014-09-24 09:08:10 -0300 | [diff] [blame] | 1447 | static struct s5p_mfc_buf_size_v6 mfc_buf_size_v7 = { |
Arun Kumar K | 5441e9d | 2013-07-09 01:24:38 -0300 | [diff] [blame] | 1448 | .dev_ctx = MFC_CTX_BUF_SIZE_V7, |
| 1449 | .h264_dec_ctx = MFC_H264_DEC_CTX_BUF_SIZE_V7, |
| 1450 | .other_dec_ctx = MFC_OTHER_DEC_CTX_BUF_SIZE_V7, |
| 1451 | .h264_enc_ctx = MFC_H264_ENC_CTX_BUF_SIZE_V7, |
| 1452 | .other_enc_ctx = MFC_OTHER_ENC_CTX_BUF_SIZE_V7, |
| 1453 | }; |
| 1454 | |
Mauro Carvalho Chehab | ca5ea0c | 2014-09-24 09:08:10 -0300 | [diff] [blame] | 1455 | static struct s5p_mfc_buf_size buf_size_v7 = { |
Arun Kumar K | 5441e9d | 2013-07-09 01:24:38 -0300 | [diff] [blame] | 1456 | .fw = MAX_FW_SIZE_V7, |
| 1457 | .cpb = MAX_CPB_SIZE_V7, |
| 1458 | .priv = &mfc_buf_size_v7, |
| 1459 | }; |
| 1460 | |
Mauro Carvalho Chehab | ca5ea0c | 2014-09-24 09:08:10 -0300 | [diff] [blame] | 1461 | static struct s5p_mfc_buf_align mfc_buf_align_v7 = { |
Arun Kumar K | 5441e9d | 2013-07-09 01:24:38 -0300 | [diff] [blame] | 1462 | .base = 0, |
| 1463 | }; |
| 1464 | |
| 1465 | static struct s5p_mfc_variant mfc_drvdata_v7 = { |
| 1466 | .version = MFC_VERSION_V7, |
Kamil Debski | 9aa5f00 | 2014-05-20 10:15:13 -0300 | [diff] [blame] | 1467 | .version_bit = MFC_V7_BIT, |
Arun Kumar K | 5441e9d | 2013-07-09 01:24:38 -0300 | [diff] [blame] | 1468 | .port_num = MFC_NUM_PORTS_V7, |
| 1469 | .buf_size = &buf_size_v7, |
| 1470 | .buf_align = &mfc_buf_align_v7, |
Arun Kumar K | 77ba6b7 | 2014-05-21 06:29:30 -0300 | [diff] [blame] | 1471 | .fw_name[0] = "s5p-mfc-v7.fw", |
Arun Kumar K | 5441e9d | 2013-07-09 01:24:38 -0300 | [diff] [blame] | 1472 | }; |
| 1473 | |
Mauro Carvalho Chehab | ca5ea0c | 2014-09-24 09:08:10 -0300 | [diff] [blame] | 1474 | static struct s5p_mfc_buf_size_v6 mfc_buf_size_v8 = { |
Kiran AVND | e2b9deb | 2014-05-19 09:50:01 -0300 | [diff] [blame] | 1475 | .dev_ctx = MFC_CTX_BUF_SIZE_V8, |
| 1476 | .h264_dec_ctx = MFC_H264_DEC_CTX_BUF_SIZE_V8, |
| 1477 | .other_dec_ctx = MFC_OTHER_DEC_CTX_BUF_SIZE_V8, |
Kiran AVND | 3e594ce7 | 2014-05-19 09:50:02 -0300 | [diff] [blame] | 1478 | .h264_enc_ctx = MFC_H264_ENC_CTX_BUF_SIZE_V8, |
| 1479 | .other_enc_ctx = MFC_OTHER_ENC_CTX_BUF_SIZE_V8, |
Kiran AVND | e2b9deb | 2014-05-19 09:50:01 -0300 | [diff] [blame] | 1480 | }; |
| 1481 | |
Mauro Carvalho Chehab | ca5ea0c | 2014-09-24 09:08:10 -0300 | [diff] [blame] | 1482 | static struct s5p_mfc_buf_size buf_size_v8 = { |
Kiran AVND | e2b9deb | 2014-05-19 09:50:01 -0300 | [diff] [blame] | 1483 | .fw = MAX_FW_SIZE_V8, |
| 1484 | .cpb = MAX_CPB_SIZE_V8, |
| 1485 | .priv = &mfc_buf_size_v8, |
| 1486 | }; |
| 1487 | |
Mauro Carvalho Chehab | ca5ea0c | 2014-09-24 09:08:10 -0300 | [diff] [blame] | 1488 | static struct s5p_mfc_buf_align mfc_buf_align_v8 = { |
Kiran AVND | e2b9deb | 2014-05-19 09:50:01 -0300 | [diff] [blame] | 1489 | .base = 0, |
| 1490 | }; |
| 1491 | |
| 1492 | static struct s5p_mfc_variant mfc_drvdata_v8 = { |
| 1493 | .version = MFC_VERSION_V8, |
| 1494 | .version_bit = MFC_V8_BIT, |
| 1495 | .port_num = MFC_NUM_PORTS_V8, |
| 1496 | .buf_size = &buf_size_v8, |
| 1497 | .buf_align = &mfc_buf_align_v8, |
Arun Kumar K | 77ba6b7 | 2014-05-21 06:29:30 -0300 | [diff] [blame] | 1498 | .fw_name[0] = "s5p-mfc-v8.fw", |
Kiran AVND | e2b9deb | 2014-05-19 09:50:01 -0300 | [diff] [blame] | 1499 | }; |
| 1500 | |
Krzysztof Kozlowski | 6425f64 | 2015-05-01 12:51:03 -0300 | [diff] [blame] | 1501 | static const struct platform_device_id mfc_driver_ids[] = { |
Arun Kumar K | 8f532a7 | 2012-10-03 22:19:09 -0300 | [diff] [blame] | 1502 | { |
| 1503 | .name = "s5p-mfc", |
| 1504 | .driver_data = (unsigned long)&mfc_drvdata_v5, |
Jeongtae Park | f96f3cf | 2012-10-03 22:19:11 -0300 | [diff] [blame] | 1505 | }, { |
| 1506 | .name = "s5p-mfc-v5", |
| 1507 | .driver_data = (unsigned long)&mfc_drvdata_v5, |
| 1508 | }, { |
| 1509 | .name = "s5p-mfc-v6", |
| 1510 | .driver_data = (unsigned long)&mfc_drvdata_v6, |
Arun Kumar K | 5441e9d | 2013-07-09 01:24:38 -0300 | [diff] [blame] | 1511 | }, { |
| 1512 | .name = "s5p-mfc-v7", |
| 1513 | .driver_data = (unsigned long)&mfc_drvdata_v7, |
Kiran AVND | e2b9deb | 2014-05-19 09:50:01 -0300 | [diff] [blame] | 1514 | }, { |
| 1515 | .name = "s5p-mfc-v8", |
| 1516 | .driver_data = (unsigned long)&mfc_drvdata_v8, |
Arun Kumar K | 8f532a7 | 2012-10-03 22:19:09 -0300 | [diff] [blame] | 1517 | }, |
| 1518 | {}, |
| 1519 | }; |
| 1520 | MODULE_DEVICE_TABLE(platform, mfc_driver_ids); |
| 1521 | |
Arun Kumar K | b27a23b | 2012-10-25 05:24:14 -0300 | [diff] [blame] | 1522 | static const struct of_device_id exynos_mfc_match[] = { |
| 1523 | { |
| 1524 | .compatible = "samsung,mfc-v5", |
| 1525 | .data = &mfc_drvdata_v5, |
| 1526 | }, { |
| 1527 | .compatible = "samsung,mfc-v6", |
| 1528 | .data = &mfc_drvdata_v6, |
Arun Kumar K | 5441e9d | 2013-07-09 01:24:38 -0300 | [diff] [blame] | 1529 | }, { |
| 1530 | .compatible = "samsung,mfc-v7", |
| 1531 | .data = &mfc_drvdata_v7, |
Kiran AVND | e2b9deb | 2014-05-19 09:50:01 -0300 | [diff] [blame] | 1532 | }, { |
| 1533 | .compatible = "samsung,mfc-v8", |
| 1534 | .data = &mfc_drvdata_v8, |
Arun Kumar K | b27a23b | 2012-10-25 05:24:14 -0300 | [diff] [blame] | 1535 | }, |
| 1536 | {}, |
| 1537 | }; |
| 1538 | MODULE_DEVICE_TABLE(of, exynos_mfc_match); |
| 1539 | |
| 1540 | static void *mfc_get_drv_data(struct platform_device *pdev) |
| 1541 | { |
| 1542 | struct s5p_mfc_variant *driver_data = NULL; |
| 1543 | |
| 1544 | if (pdev->dev.of_node) { |
| 1545 | const struct of_device_id *match; |
Sachin Kamat | a40a138 | 2013-05-23 00:51:19 -0300 | [diff] [blame] | 1546 | match = of_match_node(exynos_mfc_match, |
Arun Kumar K | b27a23b | 2012-10-25 05:24:14 -0300 | [diff] [blame] | 1547 | pdev->dev.of_node); |
| 1548 | if (match) |
| 1549 | driver_data = (struct s5p_mfc_variant *)match->data; |
| 1550 | } else { |
| 1551 | driver_data = (struct s5p_mfc_variant *) |
| 1552 | platform_get_device_id(pdev)->driver_data; |
| 1553 | } |
| 1554 | return driver_data; |
| 1555 | } |
| 1556 | |
Kamil Debski | 1e393e9 | 2011-08-08 13:12:51 -0300 | [diff] [blame] | 1557 | static struct platform_driver s5p_mfc_driver = { |
Arun Kumar K | 8f532a7 | 2012-10-03 22:19:09 -0300 | [diff] [blame] | 1558 | .probe = s5p_mfc_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1559 | .remove = s5p_mfc_remove, |
Arun Kumar K | 8f532a7 | 2012-10-03 22:19:09 -0300 | [diff] [blame] | 1560 | .id_table = mfc_driver_ids, |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1561 | .driver = { |
| 1562 | .name = S5P_MFC_NAME, |
Arun Kumar K | b27a23b | 2012-10-25 05:24:14 -0300 | [diff] [blame] | 1563 | .pm = &s5p_mfc_pm_ops, |
| 1564 | .of_match_table = exynos_mfc_match, |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1565 | }, |
| 1566 | }; |
| 1567 | |
Axel Lin | 1d6629b | 2012-01-10 03:21:49 -0300 | [diff] [blame] | 1568 | module_platform_driver(s5p_mfc_driver); |
Kamil Debski | af93574 | 2011-06-21 10:51:26 -0300 | [diff] [blame] | 1569 | |
| 1570 | MODULE_LICENSE("GPL"); |
| 1571 | MODULE_AUTHOR("Kamil Debski <k.debski@samsung.com>"); |
| 1572 | MODULE_DESCRIPTION("Samsung S5P Multi Format Codec V4L2 driver"); |
| 1573 | |