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