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