blob: 27e7cf65c2a77a367fa1c8ce0537ab29040fac9d [file] [log] [blame]
Kamil Debskiaf935742011-06-21 10:51:26 -03001/*
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 Debskiaf935742011-06-21 10:51:26 -030021#include <linux/videodev2.h>
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -030022#include <media/v4l2-event.h>
Kamil Debskiaf935742011-06-21 10:51:26 -030023#include <linux/workqueue.h>
Arun Kumar Kb27a23b2012-10-25 05:24:14 -030024#include <linux/of.h>
Marek Szyprowskic79667d2016-05-24 15:31:26 +020025#include <linux/of_reserved_mem.h>
Junghak Sungc1399902015-09-22 10:30:29 -030026#include <media/videobuf2-v4l2.h>
Arun Kumar K43a1ea12012-10-03 22:19:08 -030027#include "s5p_mfc_common.h"
Kamil Debskiaf935742011-06-21 10:51:26 -030028#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 Szyprowski04f77672016-05-24 15:31:27 +020033#include "s5p_mfc_iommu.h"
Arun Kumar K43a1ea12012-10-03 22:19:08 -030034#include "s5p_mfc_opr.h"
35#include "s5p_mfc_cmd.h"
Kamil Debskiaf935742011-06-21 10:51:26 -030036#include "s5p_mfc_pm.h"
Kamil Debskiaf935742011-06-21 10:51:26 -030037
Kamil Debskiaf935742011-06-21 10:51:26 -030038#define S5P_MFC_DEC_NAME "s5p-mfc-dec"
39#define S5P_MFC_ENC_NAME "s5p-mfc-enc"
40
Mauro Carvalho Chehab139adba2014-08-22 06:07:57 -050041int mfc_debug_level;
42module_param_named(debug, mfc_debug_level, int, S_IRUGO | S_IWUSR);
Kamil Debskiaf935742011-06-21 10:51:26 -030043MODULE_PARM_DESC(debug, "Debug level - higher value produces more verbose messages");
44
45/* Helper functions for interrupt processing */
Andrzej Hajda7fb89ec2012-08-14 06:13:40 -030046
Kamil Debskiaf935742011-06-21 10:51:26 -030047/* Remove from hw execution round robin */
Andrzej Hajda7fb89ec2012-08-14 06:13:40 -030048void clear_work_bit(struct s5p_mfc_ctx *ctx)
Kamil Debskiaf935742011-06-21 10:51:26 -030049{
50 struct s5p_mfc_dev *dev = ctx->dev;
51
52 spin_lock(&dev->condlock);
Andrzej Hajda7fb89ec2012-08-14 06:13:40 -030053 __clear_bit(ctx->num, &dev->ctx_work_bits);
Kamil Debskiaf935742011-06-21 10:51:26 -030054 spin_unlock(&dev->condlock);
55}
56
Andrzej Hajda7fb89ec2012-08-14 06:13:40 -030057/* Add to hw execution round robin */
58void 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 */
68void 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 */
79void 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 Hajda05d1d0f2015-12-02 06:22:28 -020089int 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 Debskiaf935742011-06-21 10:51:26 -0300109/* Wake up context wait_queue */
110static 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 */
120static 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 Hajda62bbd722015-12-02 06:22:29 -0200129void 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 Kamata13bba42012-05-10 03:32:01 -0300143static void s5p_mfc_watchdog(unsigned long arg)
Kamil Debskiaf935742011-06-21 10:51:26 -0300144{
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 Shridhared900132016-07-16 05:30:25 -0300156 schedule_work(&dev->watchdog_work);
Kamil Debskiaf935742011-06-21 10:51:26 -0300157 }
158 dev->watchdog_timer.expires = jiffies +
159 msecs_to_jiffies(MFC_WATCHDOG_INTERVAL);
160 add_timer(&dev->watchdog_timer);
161}
162
163static 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 Hajda62bbd722015-12-02 06:22:29 -0200188 s5p_mfc_cleanup_queue(&ctx->dst_queue, &ctx->vq_dst);
189 s5p_mfc_cleanup_queue(&ctx->src_queue, &ctx->vq_src);
Kamil Debskiaf935742011-06-21 10:51:26 -0300190 clear_work_bit(ctx);
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300191 wake_up_ctx(ctx, S5P_MFC_R2H_CMD_ERR_RET, 0);
Kamil Debskiaf935742011-06-21 10:51:26 -0300192 }
193 clear_bit(0, &dev->hw_lock);
194 spin_unlock_irqrestore(&dev->irqlock, flags);
Arun Mankuzhib16e6442014-10-21 08:07:03 -0300195
196 /* De-init MFC */
197 s5p_mfc_deinit_hw(dev);
198
Kamil Debskiaf935742011-06-21 10:51:26 -0300199 /* 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 K46075002014-05-21 06:29:29 -0300202 ret = s5p_mfc_load_firmware(dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300203 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 }
212unlock:
213 if (mutex_locked)
214 mutex_unlock(&dev->mfc_mutex);
215}
216
Kamil Debskiaf935742011-06-21 10:51:26 -0300217static void s5p_mfc_handle_frame_all_extracted(struct s5p_mfc_ctx *ctx)
218{
219 struct s5p_mfc_buf *dst_buf;
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300220 struct s5p_mfc_dev *dev = ctx->dev;
Kamil Debskiaf935742011-06-21 10:51:26 -0300221
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 Sung2d700712015-09-22 10:30:30 -0300228 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 Debskiaf935742011-06-21 10:51:26 -0300231 list_del(&dst_buf->list);
Andrzej Hajda4d0b0ed2015-10-07 07:13:45 -0300232 dst_buf->flags |= MFC_BUF_FLAG_EOS;
Kamil Debskiaf935742011-06-21 10:51:26 -0300233 ctx->dst_queue_cnt--;
Junghak Sung2d700712015-09-22 10:30:30 -0300234 dst_buf->b->sequence = (ctx->sequence++);
Kamil Debskiaf935742011-06-21 10:51:26 -0300235
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300236 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 Sung2d700712015-09-22 10:30:30 -0300238 dst_buf->b->field = V4L2_FIELD_NONE;
Kamil Debskiaf935742011-06-21 10:51:26 -0300239 else
Junghak Sung2d700712015-09-22 10:30:30 -0300240 dst_buf->b->field = V4L2_FIELD_INTERLACED;
241 dst_buf->b->flags |= V4L2_BUF_FLAG_LAST;
Kamil Debskiaf935742011-06-21 10:51:26 -0300242
Junghak Sung2d700712015-09-22 10:30:30 -0300243 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 Debskiaf935742011-06-21 10:51:26 -0300245 }
246}
247
248static 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 K43a1ea12012-10-03 22:19:08 -0300252 size_t dec_y_addr;
253 unsigned int frame_type;
254
Ilja Friedelbb21c542014-10-21 08:06:58 -0300255 /* Make sure we actually have a new frame before continuing. */
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300256 frame_type = s5p_mfc_hw_call(dev->mfc_ops, get_dec_frame_type, dev);
Ilja Friedelbb21c542014-10-21 08:06:58 -0300257 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 Debskiaf935742011-06-21 10:51:26 -0300260
261 /* Copy timestamp / timecode from decoded src to dst and set
Ilja Friedelbb21c542014-10-21 08:06:58 -0300262 appropriate flags. */
Kamil Debskiaf935742011-06-21 10:51:26 -0300263 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 Sung2d700712015-09-22 10:30:30 -0300265 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 Sungd6dd6452015-11-03 08:16:37 -0200269 dst_buf->b->vb2_buf.timestamp =
270 src_buf->b->vb2_buf.timestamp;
Junghak Sung2d700712015-09-22 10:30:30 -0300271 dst_buf->b->flags &=
Sakari Ailus309f4d62014-02-08 14:21:35 -0300272 ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
Junghak Sung2d700712015-09-22 10:30:30 -0300273 dst_buf->b->flags |=
274 src_buf->b->flags
Sakari Ailus309f4d62014-02-08 14:21:35 -0300275 & V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
Kamil Debskiaf935742011-06-21 10:51:26 -0300276 switch (frame_type) {
277 case S5P_FIMV_DECODE_FRAME_I_FRAME:
Junghak Sung2d700712015-09-22 10:30:30 -0300278 dst_buf->b->flags |=
Kamil Debskiaf935742011-06-21 10:51:26 -0300279 V4L2_BUF_FLAG_KEYFRAME;
280 break;
281 case S5P_FIMV_DECODE_FRAME_P_FRAME:
Junghak Sung2d700712015-09-22 10:30:30 -0300282 dst_buf->b->flags |=
Kamil Debskiaf935742011-06-21 10:51:26 -0300283 V4L2_BUF_FLAG_PFRAME;
284 break;
285 case S5P_FIMV_DECODE_FRAME_B_FRAME:
Junghak Sung2d700712015-09-22 10:30:30 -0300286 dst_buf->b->flags |=
Kamil Debskiaf935742011-06-21 10:51:26 -0300287 V4L2_BUF_FLAG_BFRAME;
288 break;
Ilja Friedelbb21c542014-10-21 08:06:58 -0300289 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 Debskiaf935742011-06-21 10:51:26 -0300294 }
295 break;
296 }
297 }
298}
299
300static 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 K43a1ea12012-10-03 22:19:08 -0300304 size_t dspl_y_addr;
305 unsigned int frame_type;
Kamil Debskiaf935742011-06-21 10:51:26 -0300306
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300307 dspl_y_addr = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_y_adr, dev);
Sjoerd Simons7c672812014-09-22 09:52:02 -0300308 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 K43a1ea12012-10-03 22:19:08 -0300314
Kamil Debskiaf935742011-06-21 10:51:26 -0300315 /* 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 Sung2d700712015-09-22 10:30:30 -0300327 if (vb2_dma_contig_plane_dma_addr(&dst_buf->b->vb2_buf, 0)
328 == dspl_y_addr) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300329 list_del(&dst_buf->list);
330 ctx->dst_queue_cnt--;
Junghak Sung2d700712015-09-22 10:30:30 -0300331 dst_buf->b->sequence = ctx->sequence;
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300332 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 Sung2d700712015-09-22 10:30:30 -0300336 dst_buf->b->field = V4L2_FIELD_NONE;
Kamil Debskiaf935742011-06-21 10:51:26 -0300337 else
Junghak Sung2d700712015-09-22 10:30:30 -0300338 dst_buf->b->field =
Kamil Debskiaf935742011-06-21 10:51:26 -0300339 V4L2_FIELD_INTERLACED;
Junghak Sung2d700712015-09-22 10:30:30 -0300340 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 Debskiaf935742011-06-21 10:51:26 -0300345 &ctx->dec_dst_flag);
346
Junghak Sung2d700712015-09-22 10:30:30 -0300347 vb2_buffer_done(&dst_buf->b->vb2_buf, err ?
348 VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
Kamil Debskiaf935742011-06-21 10:51:26 -0300349
Kamil Debskiaf935742011-06-21 10:51:26 -0300350 break;
351 }
352 }
353}
354
355/* Handle frame decoding interrupt */
356static 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 Osciaka0517f52014-05-19 09:32:57 -0300361 unsigned int dec_frame_status;
Kamil Debskiaf935742011-06-21 10:51:26 -0300362 struct s5p_mfc_buf *src_buf;
Kamil Debskiaf935742011-06-21 10:51:26 -0300363 unsigned int res_change;
364
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300365 dst_frame_status = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev)
Kamil Debskiaf935742011-06-21 10:51:26 -0300366 & S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK;
Pawel Osciaka0517f52014-05-19 09:32:57 -0300367 dec_frame_status = s5p_mfc_hw_call(dev->mfc_ops, get_dec_status, dev)
368 & S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK;
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -0300369 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 Debskiaf935742011-06-21 10:51:26 -0300372 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 Parkf96f3cf2012-10-03 22:19:11 -0300375 if (res_change == S5P_FIMV_RES_INCREASE ||
376 res_change == S5P_FIMV_RES_DECREASE) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300377 ctx->state = MFCINST_RES_CHANGE_INIT;
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200378 s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300379 wake_up_ctx(ctx, reason, err);
Pawel Osciak9a7bc6b2014-10-21 08:07:01 -0300380 WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
Kamil Debskiaf935742011-06-21 10:51:26 -0300381 s5p_mfc_clock_off();
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200382 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300383 return;
384 }
385 if (ctx->dpb_flush_flag)
386 ctx->dpb_flush_flag = 0;
387
Kamil Debskiaf935742011-06-21 10:51:26 -0300388 /* 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 Osciak0520e4c2014-05-14 03:59:43 -0300391 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 Debskiaf935742011-06-21 10:51:26 -0300397 s5p_mfc_handle_frame_all_extracted(ctx);
398 ctx->state = MFCINST_RES_CHANGE_END;
Pawel Osciak0520e4c2014-05-14 03:59:43 -0300399 v4l2_event_queue_fh(&ctx->fh, &ev_src_ch);
400
Kamil Debskiaf935742011-06-21 10:51:26 -0300401 goto leave_handle_frame;
402 } else {
403 s5p_mfc_handle_frame_all_extracted(ctx);
404 }
405 }
406
Pawel Osciaka0517f52014-05-19 09:32:57 -0300407 if (dec_frame_status == S5P_FIMV_DEC_STATUS_DECODING_DISPLAY)
Kamil Debskiaf935742011-06-21 10:51:26 -0300408 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 K43a1ea12012-10-03 22:19:08 -0300422 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 Osciakf49f3ed2014-05-19 09:33:02 -0300425 ctx->codec_mode != S5P_MFC_CODEC_VP8_DEC &&
Arun Kumar Kd2a0db12012-11-14 09:26:45 -0300426 ctx->consumed_stream + STUFF_BYTE <
Junghak Sung2d700712015-09-22 10:30:30 -0300427 src_buf->b->vb2_buf.planes[0].bytesused) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300428 /* 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 Debskiaf935742011-06-21 10:51:26 -0300432 mfc_debug(2, "MFC needs next buffer\n");
433 ctx->consumed_stream = 0;
Kamil Debskia34026e2013-01-11 12:29:33 -0300434 if (src_buf->flags & MFC_BUF_FLAG_EOS)
435 ctx->state = MFCINST_FINISHING;
Kamil Debskiaf935742011-06-21 10:51:26 -0300436 list_del(&src_buf->list);
437 ctx->src_queue_cnt--;
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300438 if (s5p_mfc_hw_call(dev->mfc_ops, err_dec, err) > 0)
Junghak Sung2d700712015-09-22 10:30:30 -0300439 vb2_buffer_done(&src_buf->b->vb2_buf,
440 VB2_BUF_STATE_ERROR);
Kamil Debskiaf935742011-06-21 10:51:26 -0300441 else
Junghak Sung2d700712015-09-22 10:30:30 -0300442 vb2_buffer_done(&src_buf->b->vb2_buf,
443 VB2_BUF_STATE_DONE);
Kamil Debskiaf935742011-06-21 10:51:26 -0300444 }
445 }
446leave_handle_frame:
Kamil Debskiaf935742011-06-21 10:51:26 -0300447 if ((ctx->src_queue_cnt == 0 && ctx->state != MFCINST_FINISHING)
Arun Kumar Ke9d98dd2013-04-24 09:41:53 -0300448 || ctx->dst_queue_cnt < ctx->pb_count)
Kamil Debskiaf935742011-06-21 10:51:26 -0300449 clear_work_bit(ctx);
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200450 s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300451 wake_up_ctx(ctx, reason, err);
Pawel Osciak9a7bc6b2014-10-21 08:07:01 -0300452 WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
Kamil Debskiaf935742011-06-21 10:51:26 -0300453 s5p_mfc_clock_off();
Prathyush K76a4ddb2013-10-04 01:47:19 -0300454 /* 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 Hajdafdd1d4b2015-12-02 06:22:32 -0200458 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300459}
460
461/* Error handling for interrupt */
Kamil Debski7296e252012-12-21 05:32:59 -0300462static void s5p_mfc_handle_error(struct s5p_mfc_dev *dev,
463 struct s5p_mfc_ctx *ctx, unsigned int reason, unsigned int err)
Kamil Debskiaf935742011-06-21 10:51:26 -0300464{
Kamil Debskiaf935742011-06-21 10:51:26 -0300465 mfc_err("Interrupt Error: %08x\n", err);
Kamil Debskiaf935742011-06-21 10:51:26 -0300466
Kamil Debski7296e252012-12-21 05:32:59 -0300467 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 McCrohan39c1cb22013-10-20 21:34:01 -0300476 /* It is highly probable that an error occurred
Kamil Debski7296e252012-12-21 05:32:59 -0300477 * while decoding a frame */
478 clear_work_bit(ctx);
479 ctx->state = MFCINST_ERROR;
480 /* Mark all dst buffers as having an error */
Andrzej Hajda62bbd722015-12-02 06:22:29 -0200481 s5p_mfc_cleanup_queue(&ctx->dst_queue, &ctx->vq_dst);
Kamil Debski7296e252012-12-21 05:32:59 -0300482 /* Mark all src buffers as having an error */
Andrzej Hajda62bbd722015-12-02 06:22:29 -0200483 s5p_mfc_cleanup_queue(&ctx->src_queue, &ctx->vq_src);
Kamil Debski7296e252012-12-21 05:32:59 -0300484 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 Debskiaf935742011-06-21 10:51:26 -0300492 }
Pawel Osciak9a7bc6b2014-10-21 08:07:01 -0300493 WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200494 s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev);
Kamil Debski7296e252012-12-21 05:32:59 -0300495 s5p_mfc_clock_off();
496 wake_up_dev(dev, reason, err);
Kamil Debskiaf935742011-06-21 10:51:26 -0300497}
498
499/* Header parsing interrupt handling */
500static 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 Debskiaf935742011-06-21 10:51:26 -0300504
Sachin Kamat12597622012-05-10 03:32:00 -0300505 if (ctx == NULL)
Kamil Debskiaf935742011-06-21 10:51:26 -0300506 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 K43a1ea12012-10-03 22:19:08 -0300512 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 Debskiaf935742011-06-21 10:51:26 -0300516
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200517 s5p_mfc_hw_call(dev->mfc_ops, dec_calc_dpb_size, ctx);
Arun Kumar K8f532a72012-10-03 22:19:09 -0300518
Arun Kumar Ke9d98dd2013-04-24 09:41:53 -0300519 ctx->pb_count = s5p_mfc_hw_call(dev->mfc_ops, get_dpb_count,
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300520 dev);
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -0300521 ctx->mv_count = s5p_mfc_hw_call(dev->mfc_ops, get_mv_count,
522 dev);
Julia Lawallbb869362012-01-12 17:49:30 -0300523 if (ctx->img_width == 0 || ctx->img_height == 0)
Kamil Debskiaf935742011-06-21 10:51:26 -0300524 ctx->state = MFCINST_ERROR;
525 else
526 ctx->state = MFCINST_HEAD_PARSED;
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -0300527
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 Sung2d700712015-09-22 10:30:30 -0300536 src_buf->b->vb2_buf.planes[0].bytesused)
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -0300537 ctx->head_processed = 0;
538 else
539 ctx->head_processed = 1;
540 } else {
541 ctx->head_processed = 1;
542 }
Kamil Debskiaf935742011-06-21 10:51:26 -0300543 }
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200544 s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300545 clear_work_bit(ctx);
Pawel Osciak9a7bc6b2014-10-21 08:07:01 -0300546 WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
Kamil Debskiaf935742011-06-21 10:51:26 -0300547 s5p_mfc_clock_off();
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200548 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300549 wake_up_ctx(ctx, reason, err);
550}
551
552/* Header parsing interrupt handling */
553static 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 Debskiaf935742011-06-21 10:51:26 -0300558
Sachin Kamat12597622012-05-10 03:32:00 -0300559 if (ctx == NULL)
Kamil Debskiaf935742011-06-21 10:51:26 -0300560 return;
561 dev = ctx->dev;
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200562 s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300563 ctx->int_type = reason;
564 ctx->int_err = err;
565 ctx->int_cond = 1;
Andrzej Hajda7fb89ec2012-08-14 06:13:40 -0300566 clear_work_bit(ctx);
Kamil Debskiaf935742011-06-21 10:51:26 -0300567 if (err == 0) {
568 ctx->state = MFCINST_RUNNING;
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -0300569 if (!ctx->dpb_flush_flag && ctx->head_processed) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300570 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 Sung2d700712015-09-22 10:30:30 -0300575 vb2_buffer_done(&src_buf->b->vb2_buf,
Kamil Debskiaf935742011-06-21 10:51:26 -0300576 VB2_BUF_STATE_DONE);
577 }
Kamil Debskiaf935742011-06-21 10:51:26 -0300578 } else {
579 ctx->dpb_flush_flag = 0;
580 }
Pawel Osciak9a7bc6b2014-10-21 08:07:01 -0300581 WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
Kamil Debskiaf935742011-06-21 10:51:26 -0300582
583 s5p_mfc_clock_off();
584
585 wake_up(&ctx->queue);
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200586 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300587 } else {
Pawel Osciak9a7bc6b2014-10-21 08:07:01 -0300588 WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
Kamil Debskiaf935742011-06-21 10:51:26 -0300589
590 s5p_mfc_clock_off();
591
592 wake_up(&ctx->queue);
593 }
594}
595
Andrzej Hajda96c57772015-10-07 07:15:31 -0300596static void s5p_mfc_handle_stream_complete(struct s5p_mfc_ctx *ctx)
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300597{
598 struct s5p_mfc_dev *dev = ctx->dev;
599 struct s5p_mfc_buf *mb_entry;
600
Andrzej Hajda4130eab2013-05-28 03:26:16 -0300601 mfc_debug(2, "Stream completed\n");
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300602
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300603 ctx->state = MFCINST_FINISHED;
604
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300605 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 Sung2d700712015-09-22 10:30:30 -0300610 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 Hajdaf9f715a2012-08-21 08:05:32 -0300612 }
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300613
614 clear_work_bit(ctx);
615
Sachin Kamate8256442013-01-22 01:00:06 -0300616 WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300617
618 s5p_mfc_clock_off();
619 wake_up(&ctx->queue);
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200620 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300621}
622
Kamil Debskiaf935742011-06-21 10:51:26 -0300623/* Interrupt processing */
624static 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 Hajda7969b122015-12-02 06:22:31 -0200634 spin_lock(&dev->irqlock);
Kamil Debskiaf935742011-06-21 10:51:26 -0300635 ctx = dev->ctx[dev->curr_ctx];
636 /* Get the reason of interrupt and the error code */
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300637 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 Debskiaf935742011-06-21 10:51:26 -0300639 mfc_debug(1, "Int reason: %d (err: %08x)\n", reason, err);
640 switch (reason) {
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300641 case S5P_MFC_R2H_CMD_ERR_RET:
Jonathan McCrohan39c1cb22013-10-20 21:34:01 -0300642 /* An error has occurred */
Kamil Debskiaf935742011-06-21 10:51:26 -0300643 if (ctx->state == MFCINST_RUNNING &&
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300644 s5p_mfc_hw_call(dev->mfc_ops, err_dec, err) >=
645 dev->warn_start)
Kamil Debskiaf935742011-06-21 10:51:26 -0300646 s5p_mfc_handle_frame(ctx, reason, err);
647 else
Kamil Debski7296e252012-12-21 05:32:59 -0300648 s5p_mfc_handle_error(dev, ctx, reason, err);
Kamil Debskiaf935742011-06-21 10:51:26 -0300649 clear_bit(0, &dev->enter_suspend);
650 break;
651
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300652 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 Debskiaf935742011-06-21 10:51:26 -0300655 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 Hajda96c57772015-10-07 07:15:31 -0300658
659 if (ctx->state == MFCINST_FINISHING &&
660 list_empty(&ctx->ref_queue)) {
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200661 s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev);
Andrzej Hajda96c57772015-10-07 07:15:31 -0300662 s5p_mfc_handle_stream_complete(ctx);
663 break;
664 }
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200665 s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300666 wake_up_ctx(ctx, reason, err);
Pawel Osciak9a7bc6b2014-10-21 08:07:01 -0300667 WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
Kamil Debskiaf935742011-06-21 10:51:26 -0300668 s5p_mfc_clock_off();
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200669 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300670 } else {
671 s5p_mfc_handle_frame(ctx, reason, err);
672 }
673 break;
674
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300675 case S5P_MFC_R2H_CMD_SEQ_DONE_RET:
Kamil Debskiaf935742011-06-21 10:51:26 -0300676 s5p_mfc_handle_seq_done(ctx, reason, err);
677 break;
678
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300679 case S5P_MFC_R2H_CMD_OPEN_INSTANCE_RET:
680 ctx->inst_no = s5p_mfc_hw_call(dev->mfc_ops, get_inst_no, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300681 ctx->state = MFCINST_GOT_INST;
682 clear_work_bit(ctx);
683 wake_up(&ctx->queue);
684 goto irq_cleanup_hw;
685
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300686 case S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET:
Kamil Debskiaf935742011-06-21 10:51:26 -0300687 clear_work_bit(ctx);
Pawel Osciak9d87e832014-05-19 09:33:00 -0300688 ctx->inst_no = MFC_NO_INSTANCE_SET;
Kamil Debskiaf935742011-06-21 10:51:26 -0300689 ctx->state = MFCINST_FREE;
690 wake_up(&ctx->queue);
691 goto irq_cleanup_hw;
692
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300693 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 Debskiaf935742011-06-21 10:51:26 -0300697 if (ctx)
698 clear_work_bit(ctx);
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200699 s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300700 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 K43a1ea12012-10-03 22:19:08 -0300705 case S5P_MFC_R2H_CMD_INIT_BUFFERS_RET:
Kamil Debskiaf935742011-06-21 10:51:26 -0300706 s5p_mfc_handle_init_buffers(ctx, reason, err);
707 break;
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300708
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300709 case S5P_MFC_R2H_CMD_COMPLETE_SEQ_RET:
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200710 s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev);
Andrzej Hajda96c57772015-10-07 07:15:31 -0300711 ctx->int_type = reason;
712 ctx->int_err = err;
713 s5p_mfc_handle_stream_complete(ctx);
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300714 break;
715
Arun Kumar K8f23cc02012-11-22 06:15:55 -0300716 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 Debskiaf935742011-06-21 10:51:26 -0300722 default:
723 mfc_debug(2, "Unknown int reason\n");
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200724 s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300725 }
Andrzej Hajda7969b122015-12-02 06:22:31 -0200726 spin_unlock(&dev->irqlock);
Kamil Debskiaf935742011-06-21 10:51:26 -0300727 mfc_debug_leave();
728 return IRQ_HANDLED;
729irq_cleanup_hw:
Andrzej Hajdafdd1d4b2015-12-02 06:22:32 -0200730 s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300731 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 Hajdafdd1d4b2015-12-02 06:22:32 -0200739 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
Andrzej Hajda7969b122015-12-02 06:22:31 -0200740 spin_unlock(&dev->irqlock);
Kamil Debskiaf935742011-06-21 10:51:26 -0300741 mfc_debug(2, "Exit via irq_cleanup_hw\n");
742 return IRQ_HANDLED;
743}
744
745/* Open an MFC node */
746static int s5p_mfc_open(struct file *file)
747{
Marek Szyprowskib80cb8d2013-12-03 10:12:51 -0300748 struct video_device *vdev = video_devdata(file);
Kamil Debskiaf935742011-06-21 10:51:26 -0300749 struct s5p_mfc_dev *dev = video_drvdata(file);
750 struct s5p_mfc_ctx *ctx = NULL;
751 struct vb2_queue *q;
Kamil Debskiaf935742011-06-21 10:51:26 -0300752 int ret = 0;
753
754 mfc_debug_enter();
Hans Verkuilbc738302012-06-24 07:13:33 -0300755 if (mutex_lock_interruptible(&dev->mfc_mutex))
756 return -ERESTARTSYS;
Kamil Debskiaf935742011-06-21 10:51:26 -0300757 dev->num_inst++; /* It is guarded by mfc_mutex in vfd */
758 /* Allocate memory for context */
Sachin Kamatbae061b2012-08-17 03:22:55 -0300759 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
Kamil Debskiaf935742011-06-21 10:51:26 -0300760 if (!ctx) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300761 ret = -ENOMEM;
762 goto err_alloc;
763 }
Zhaowei Yuan55647a92014-07-23 01:06:12 -0300764 v4l2_fh_init(&ctx->fh, vdev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300765 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 Khan06f0a572016-07-14 11:40:22 -0300777 mfc_debug(2, "Too many open contexts\n");
Kamil Debskiaf935742011-06-21 10:51:26 -0300778 ret = -EBUSY;
779 goto err_no_ctx;
780 }
781 }
782 /* Mark context as idle */
Andrzej Hajda7fb89ec2012-08-14 06:13:40 -0300783 clear_work_bit_irqsave(ctx);
Kamil Debskiaf935742011-06-21 10:51:26 -0300784 dev->ctx[ctx->num] = ctx;
Marek Szyprowskib80cb8d2013-12-03 10:12:51 -0300785 if (vdev == dev->vfd_dec) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300786 ctx->type = MFCINST_DECODER;
787 ctx->c_ops = get_dec_codec_ops();
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300788 s5p_mfc_dec_init(ctx);
Kamil Debskiaf935742011-06-21 10:51:26 -0300789 /* 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 Szyprowskib80cb8d2013-12-03 10:12:51 -0300795 } else if (vdev == dev->vfd_enc) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300796 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 K43a1ea12012-10-03 22:19:08 -0300801 s5p_mfc_enc_init(ctx);
Kamil Debskiaf935742011-06-21 10:51:26 -0300802 /* 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 Osciak9d87e832014-05-19 09:33:00 -0300813 ctx->inst_no = MFC_NO_INSTANCE_SET;
Kamil Debskiaf935742011-06-21 10:51:26 -0300814 /* 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 Debski2e731e42013-01-03 11:02:07 -0300825 ret = s5p_mfc_load_firmware(dev);
826 if (ret) {
827 s5p_mfc_clock_off();
828 goto err_load_fw;
829 }
Kamil Debskiaf935742011-06-21 10:51:26 -0300830 /* Init the FW */
831 ret = s5p_mfc_init_hw(dev);
Kamil Debski2e731e42013-01-03 11:02:07 -0300832 s5p_mfc_clock_off();
Kamil Debskiaf935742011-06-21 10:51:26 -0300833 if (ret)
834 goto err_init_hw;
Kamil Debskiaf935742011-06-21 10:51:26 -0300835 }
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 Lad654a7312014-11-26 19:42:32 -0300840 q->lock = &dev->mfc_mutex;
Marek Szyprowskib80cb8d2013-12-03 10:12:51 -0300841 if (vdev == dev->vfd_dec) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300842 q->io_modes = VB2_MMAP;
843 q->ops = get_dec_queue_ops();
Marek Szyprowskib80cb8d2013-12-03 10:12:51 -0300844 } else if (vdev == dev->vfd_enc) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300845 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 Villemoes749ae712014-10-21 11:55:35 -0300851 q->mem_ops = &vb2_dma_contig_memops;
Sakari Ailusade48682014-02-25 19:12:19 -0300852 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
Kamil Debskiaf935742011-06-21 10:51:26 -0300853 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 Debski41f03a02015-03-03 11:32:58 -0300863 q->lock = &dev->mfc_mutex;
Marek Szyprowskib80cb8d2013-12-03 10:12:51 -0300864 if (vdev == dev->vfd_dec) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300865 q->io_modes = VB2_MMAP;
866 q->ops = get_dec_queue_ops();
Marek Szyprowskib80cb8d2013-12-03 10:12:51 -0300867 } else if (vdev == dev->vfd_enc) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300868 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 Debskie6c9dec2015-02-23 09:26:19 -0300874 /* 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 Villemoes749ae712014-10-21 11:55:35 -0300881 q->mem_ops = &vb2_dma_contig_memops;
Sakari Ailusade48682014-02-25 19:12:19 -0300882 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
Kamil Debskiaf935742011-06-21 10:51:26 -0300883 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 Verkuilbc738302012-06-24 07:13:33 -0300889 mutex_unlock(&dev->mfc_mutex);
Kamil Debskiaf935742011-06-21 10:51:26 -0300890 mfc_debug_leave();
891 return ret;
Jonathan McCrohan39c1cb22013-10-20 21:34:01 -0300892 /* Deinit when failure occurred */
Kamil Debskiaf935742011-06-21 10:51:26 -0300893err_queue_init:
Kamil Debski2e731e42013-01-03 11:02:07 -0300894 if (dev->num_inst == 1)
895 s5p_mfc_deinit_hw(dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300896err_init_hw:
Kamil Debski2e731e42013-01-03 11:02:07 -0300897err_load_fw:
Kamil Debskiaf935742011-06-21 10:51:26 -0300898err_pwr_enable:
899 if (dev->num_inst == 1) {
900 if (s5p_mfc_power_off() < 0)
901 mfc_err("power off failed\n");
Kamil Debski1b73ba02012-11-22 10:00:28 -0300902 del_timer_sync(&dev->watchdog_timer);
Kamil Debskiaf935742011-06-21 10:51:26 -0300903 }
904err_ctrls_setup:
905 s5p_mfc_dec_ctrls_delete(ctx);
906err_bad_node:
Kamil Debski1b73ba02012-11-22 10:00:28 -0300907 dev->ctx[ctx->num] = NULL;
Kamil Debskiaf935742011-06-21 10:51:26 -0300908err_no_ctx:
909 v4l2_fh_del(&ctx->fh);
910 v4l2_fh_exit(&ctx->fh);
911 kfree(ctx);
912err_alloc:
913 dev->num_inst--;
Hans Verkuilbc738302012-06-24 07:13:33 -0300914 mutex_unlock(&dev->mfc_mutex);
Kamil Debskiaf935742011-06-21 10:51:26 -0300915 mfc_debug_leave();
916 return ret;
917}
918
919/* Release MFC context */
920static 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 Debskiaf935742011-06-21 10:51:26 -0300924
Shuah Khand695c122016-07-08 19:29:25 -0300925 /* if dev is null, do cleanup that doesn't need dev */
Kamil Debskiaf935742011-06-21 10:51:26 -0300926 mfc_debug_enter();
Shuah Khand695c122016-07-08 19:29:25 -0300927 if (dev)
928 mutex_lock(&dev->mfc_mutex);
Kamil Debskiaf935742011-06-21 10:51:26 -0300929 vb2_queue_release(&ctx->vq_src);
930 vb2_queue_release(&ctx->vq_dst);
Shuah Khand695c122016-07-08 19:29:25 -0300931 if (dev) {
Marek Szyprowski3bef7572016-11-14 12:09:26 -0200932 s5p_mfc_clock_on();
933
Shuah Khand695c122016-07-08 19:29:25 -0300934 /* Mark context as idle */
935 clear_work_bit_irqsave(ctx);
936 /*
937 * If instance was initialised and not yet freed,
938 * return instance and free resources
939 */
940 if (ctx->state != MFCINST_FREE && ctx->state != MFCINST_INIT) {
941 mfc_debug(2, "Has to free instance\n");
942 s5p_mfc_close_mfc_inst(dev, ctx);
943 }
944 /* hardware locking scheme */
945 if (dev->curr_ctx == ctx->num)
946 clear_bit(0, &dev->hw_lock);
947 dev->num_inst--;
948 if (dev->num_inst == 0) {
949 mfc_debug(2, "Last instance\n");
950 s5p_mfc_deinit_hw(dev);
951 del_timer_sync(&dev->watchdog_timer);
952 if (s5p_mfc_power_off() < 0)
953 mfc_err("Power off failed\n");
954 }
Marek Szyprowski3bef7572016-11-14 12:09:26 -0200955 mfc_debug(2, "Shutting down clock\n");
956 s5p_mfc_clock_off();
Kamil Debskiaf935742011-06-21 10:51:26 -0300957 }
Shuah Khand695c122016-07-08 19:29:25 -0300958 if (dev)
959 dev->ctx[ctx->num] = NULL;
Kamil Debskiaf935742011-06-21 10:51:26 -0300960 s5p_mfc_dec_ctrls_delete(ctx);
961 v4l2_fh_del(&ctx->fh);
Shuah Khand695c122016-07-08 19:29:25 -0300962 /* vdev is gone if dev is null */
963 if (dev)
964 v4l2_fh_exit(&ctx->fh);
Kamil Debskiaf935742011-06-21 10:51:26 -0300965 kfree(ctx);
966 mfc_debug_leave();
Shuah Khand695c122016-07-08 19:29:25 -0300967 if (dev)
968 mutex_unlock(&dev->mfc_mutex);
969
Kamil Debskiaf935742011-06-21 10:51:26 -0300970 return 0;
971}
972
973/* Poll */
974static unsigned int s5p_mfc_poll(struct file *file,
975 struct poll_table_struct *wait)
976{
977 struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data);
978 struct s5p_mfc_dev *dev = ctx->dev;
979 struct vb2_queue *src_q, *dst_q;
980 struct vb2_buffer *src_vb = NULL, *dst_vb = NULL;
981 unsigned int rc = 0;
982 unsigned long flags;
983
Hans Verkuilbc738302012-06-24 07:13:33 -0300984 mutex_lock(&dev->mfc_mutex);
Kamil Debskiaf935742011-06-21 10:51:26 -0300985 src_q = &ctx->vq_src;
986 dst_q = &ctx->vq_dst;
987 /*
988 * There has to be at least one buffer queued on each queued_list, which
989 * means either in driver already or waiting for driver to claim it
990 * and start processing.
991 */
992 if ((!src_q->streaming || list_empty(&src_q->queued_list))
993 && (!dst_q->streaming || list_empty(&dst_q->queued_list))) {
994 rc = POLLERR;
995 goto end;
996 }
997 mutex_unlock(&dev->mfc_mutex);
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300998 poll_wait(file, &ctx->fh.wait, wait);
Kamil Debskiaf935742011-06-21 10:51:26 -0300999 poll_wait(file, &src_q->done_wq, wait);
1000 poll_wait(file, &dst_q->done_wq, wait);
1001 mutex_lock(&dev->mfc_mutex);
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -03001002 if (v4l2_event_pending(&ctx->fh))
1003 rc |= POLLPRI;
Kamil Debskiaf935742011-06-21 10:51:26 -03001004 spin_lock_irqsave(&src_q->done_lock, flags);
1005 if (!list_empty(&src_q->done_list))
1006 src_vb = list_first_entry(&src_q->done_list, struct vb2_buffer,
1007 done_entry);
1008 if (src_vb && (src_vb->state == VB2_BUF_STATE_DONE
1009 || src_vb->state == VB2_BUF_STATE_ERROR))
1010 rc |= POLLOUT | POLLWRNORM;
1011 spin_unlock_irqrestore(&src_q->done_lock, flags);
1012 spin_lock_irqsave(&dst_q->done_lock, flags);
1013 if (!list_empty(&dst_q->done_list))
1014 dst_vb = list_first_entry(&dst_q->done_list, struct vb2_buffer,
1015 done_entry);
1016 if (dst_vb && (dst_vb->state == VB2_BUF_STATE_DONE
1017 || dst_vb->state == VB2_BUF_STATE_ERROR))
1018 rc |= POLLIN | POLLRDNORM;
1019 spin_unlock_irqrestore(&dst_q->done_lock, flags);
1020end:
Hans Verkuilbc738302012-06-24 07:13:33 -03001021 mutex_unlock(&dev->mfc_mutex);
Kamil Debskiaf935742011-06-21 10:51:26 -03001022 return rc;
1023}
1024
1025/* Mmap */
1026static int s5p_mfc_mmap(struct file *file, struct vm_area_struct *vma)
1027{
1028 struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data);
Hans Verkuilbc738302012-06-24 07:13:33 -03001029 struct s5p_mfc_dev *dev = ctx->dev;
Kamil Debskiaf935742011-06-21 10:51:26 -03001030 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
1031 int ret;
Hans Verkuilbc738302012-06-24 07:13:33 -03001032
1033 if (mutex_lock_interruptible(&dev->mfc_mutex))
1034 return -ERESTARTSYS;
Kamil Debskiaf935742011-06-21 10:51:26 -03001035 if (offset < DST_QUEUE_OFF_BASE) {
1036 mfc_debug(2, "mmaping source\n");
1037 ret = vb2_mmap(&ctx->vq_src, vma);
1038 } else { /* capture */
1039 mfc_debug(2, "mmaping destination\n");
1040 vma->vm_pgoff -= (DST_QUEUE_OFF_BASE >> PAGE_SHIFT);
1041 ret = vb2_mmap(&ctx->vq_dst, vma);
1042 }
Hans Verkuilbc738302012-06-24 07:13:33 -03001043 mutex_unlock(&dev->mfc_mutex);
Kamil Debskiaf935742011-06-21 10:51:26 -03001044 return ret;
1045}
1046
1047/* v4l2 ops */
1048static const struct v4l2_file_operations s5p_mfc_fops = {
1049 .owner = THIS_MODULE,
1050 .open = s5p_mfc_open,
1051 .release = s5p_mfc_release,
1052 .poll = s5p_mfc_poll,
1053 .unlocked_ioctl = video_ioctl2,
1054 .mmap = s5p_mfc_mmap,
1055};
1056
Marek Szyprowskic79667d2016-05-24 15:31:26 +02001057/* DMA memory related helper functions */
Javier Martinez Canillas6311f122016-05-03 16:27:17 -04001058static void s5p_mfc_memdev_release(struct device *dev)
1059{
Marek Szyprowskic79667d2016-05-24 15:31:26 +02001060 of_reserved_mem_device_release(dev);
1061}
1062
1063static struct device *s5p_mfc_alloc_memdev(struct device *dev,
1064 const char *name, unsigned int idx)
1065{
1066 struct device *child;
1067 int ret;
1068
1069 child = devm_kzalloc(dev, sizeof(struct device), GFP_KERNEL);
1070 if (!child)
1071 return NULL;
1072
1073 device_initialize(child);
1074 dev_set_name(child, "%s:%s", dev_name(dev), name);
1075 child->parent = dev;
1076 child->bus = dev->bus;
1077 child->coherent_dma_mask = dev->coherent_dma_mask;
1078 child->dma_mask = dev->dma_mask;
1079 child->release = s5p_mfc_memdev_release;
1080
1081 if (device_add(child) == 0) {
1082 ret = of_reserved_mem_device_init_by_idx(child, dev->of_node,
1083 idx);
1084 if (ret == 0)
1085 return child;
Marek Szyprowski3fbe1402016-09-16 03:14:33 -03001086 device_del(child);
Marek Szyprowskic79667d2016-05-24 15:31:26 +02001087 }
1088
1089 put_device(child);
1090 return NULL;
1091}
1092
1093static int s5p_mfc_configure_dma_memory(struct s5p_mfc_dev *mfc_dev)
1094{
1095 struct device *dev = &mfc_dev->plat_dev->dev;
1096
1097 /*
Marek Szyprowski04f77672016-05-24 15:31:27 +02001098 * When IOMMU is available, we cannot use the default configuration,
1099 * because of MFC firmware requirements: address space limited to
1100 * 256M and non-zero default start address.
1101 * This is still simplified, not optimal configuration, but for now
1102 * IOMMU core doesn't allow to configure device's IOMMUs channel
1103 * separately.
1104 */
1105 if (exynos_is_iommu_available(dev)) {
1106 int ret = exynos_configure_iommu(dev, S5P_MFC_IOMMU_DMA_BASE,
1107 S5P_MFC_IOMMU_DMA_SIZE);
1108 if (ret == 0)
1109 mfc_dev->mem_dev_l = mfc_dev->mem_dev_r = dev;
1110 return ret;
1111 }
1112
1113 /*
Marek Szyprowskic79667d2016-05-24 15:31:26 +02001114 * Create and initialize virtual devices for accessing
1115 * reserved memory regions.
1116 */
1117 mfc_dev->mem_dev_l = s5p_mfc_alloc_memdev(dev, "left",
1118 MFC_BANK1_ALLOC_CTX);
1119 if (!mfc_dev->mem_dev_l)
1120 return -ENODEV;
1121 mfc_dev->mem_dev_r = s5p_mfc_alloc_memdev(dev, "right",
1122 MFC_BANK2_ALLOC_CTX);
1123 if (!mfc_dev->mem_dev_r) {
1124 device_unregister(mfc_dev->mem_dev_l);
1125 return -ENODEV;
1126 }
1127
1128 return 0;
1129}
1130
1131static void s5p_mfc_unconfigure_dma_memory(struct s5p_mfc_dev *mfc_dev)
1132{
Marek Szyprowski04f77672016-05-24 15:31:27 +02001133 struct device *dev = &mfc_dev->plat_dev->dev;
1134
1135 if (exynos_is_iommu_available(dev)) {
1136 exynos_unconfigure_iommu(dev);
1137 return;
1138 }
1139
Marek Szyprowskic79667d2016-05-24 15:31:26 +02001140 device_unregister(mfc_dev->mem_dev_l);
1141 device_unregister(mfc_dev->mem_dev_r);
Javier Martinez Canillas6311f122016-05-03 16:27:17 -04001142}
1143
Arun Kumar Kb27a23b2012-10-25 05:24:14 -03001144static void *mfc_get_drv_data(struct platform_device *pdev);
1145
Kamil Debskiaf935742011-06-21 10:51:26 -03001146/* MFC probe function */
Kamil Debski1e393e92011-08-08 13:12:51 -03001147static int s5p_mfc_probe(struct platform_device *pdev)
Kamil Debskiaf935742011-06-21 10:51:26 -03001148{
1149 struct s5p_mfc_dev *dev;
1150 struct video_device *vfd;
1151 struct resource *res;
1152 int ret;
1153
1154 pr_debug("%s++\n", __func__);
Sachin Kamatbae061b2012-08-17 03:22:55 -03001155 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
Kamil Debskiaf935742011-06-21 10:51:26 -03001156 if (!dev) {
1157 dev_err(&pdev->dev, "Not enough memory for MFC device\n");
1158 return -ENOMEM;
1159 }
1160
1161 spin_lock_init(&dev->irqlock);
1162 spin_lock_init(&dev->condlock);
1163 dev->plat_dev = pdev;
1164 if (!dev->plat_dev) {
1165 dev_err(&pdev->dev, "No platform data specified\n");
Sachin Kamatd310f472012-05-14 08:22:27 -03001166 return -ENODEV;
Kamil Debskiaf935742011-06-21 10:51:26 -03001167 }
1168
Arun Kumar Kb27a23b2012-10-25 05:24:14 -03001169 dev->variant = mfc_get_drv_data(pdev);
Arun Kumar K8f532a72012-10-03 22:19:09 -03001170
Kamil Debskiaf935742011-06-21 10:51:26 -03001171 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Thierry Redingf23999e2013-01-21 06:09:07 -03001172 dev->regs_base = devm_ioremap_resource(&pdev->dev, res);
1173 if (IS_ERR(dev->regs_base))
1174 return PTR_ERR(dev->regs_base);
Kamil Debskiaf935742011-06-21 10:51:26 -03001175
1176 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1177 if (res == NULL) {
1178 dev_err(&pdev->dev, "failed to get irq resource\n");
Marek Szyprowskie4fac742016-06-08 08:33:40 -03001179 return -ENOENT;
Kamil Debskiaf935742011-06-21 10:51:26 -03001180 }
1181 dev->irq = res->start;
Sachin Kamatd310f472012-05-14 08:22:27 -03001182 ret = devm_request_irq(&pdev->dev, dev->irq, s5p_mfc_irq,
Michael Opdenacker1957f0d2013-10-13 02:58:39 -03001183 0, pdev->name, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -03001184 if (ret) {
1185 dev_err(&pdev->dev, "Failed to install irq (%d)\n", ret);
Marek Szyprowskie4fac742016-06-08 08:33:40 -03001186 return ret;
Kamil Debskiaf935742011-06-21 10:51:26 -03001187 }
1188
Marek Szyprowskic79667d2016-05-24 15:31:26 +02001189 ret = s5p_mfc_configure_dma_memory(dev);
1190 if (ret < 0) {
1191 dev_err(&pdev->dev, "failed to configure DMA memory\n");
1192 return ret;
1193 }
1194
1195 ret = s5p_mfc_init_pm(dev);
1196 if (ret < 0) {
1197 dev_err(&pdev->dev, "failed to get mfc clock source\n");
Marek Szyprowskie4fac742016-06-08 08:33:40 -03001198 goto err_dma;
Kamil Debskiaf935742011-06-21 10:51:26 -03001199 }
1200
Marek Szyprowski712b6172016-05-24 09:16:07 +02001201 vb2_dma_contig_set_max_seg_size(dev->mem_dev_l, DMA_BIT_MASK(32));
Marek Szyprowski712b6172016-05-24 09:16:07 +02001202 vb2_dma_contig_set_max_seg_size(dev->mem_dev_r, DMA_BIT_MASK(32));
Kamil Debskiaf935742011-06-21 10:51:26 -03001203
1204 mutex_init(&dev->mfc_mutex);
1205
Kamil Debski2e731e42013-01-03 11:02:07 -03001206 ret = s5p_mfc_alloc_firmware(dev);
1207 if (ret)
Hans Verkuil2548fee2016-02-16 07:30:19 -02001208 goto err_res;
Kamil Debski2e731e42013-01-03 11:02:07 -03001209
Kamil Debskiaf935742011-06-21 10:51:26 -03001210 ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
1211 if (ret)
1212 goto err_v4l2_dev_reg;
1213 init_waitqueue_head(&dev->queue);
1214
1215 /* decoder */
1216 vfd = video_device_alloc();
1217 if (!vfd) {
1218 v4l2_err(&dev->v4l2_dev, "Failed to allocate video device\n");
1219 ret = -ENOMEM;
1220 goto err_dec_alloc;
1221 }
Joonyoung Shimd0ce8982014-02-20 23:22:12 -03001222 vfd->fops = &s5p_mfc_fops;
Kamil Debskiaf935742011-06-21 10:51:26 -03001223 vfd->ioctl_ops = get_dec_v4l2_ioctl_ops();
Joonyoung Shimd0ce8982014-02-20 23:22:12 -03001224 vfd->release = video_device_release;
Kamil Debskiaf935742011-06-21 10:51:26 -03001225 vfd->lock = &dev->mfc_mutex;
1226 vfd->v4l2_dev = &dev->v4l2_dev;
Hans Verkuil954f3402012-09-05 06:05:50 -03001227 vfd->vfl_dir = VFL_DIR_M2M;
Kamil Debskiaf935742011-06-21 10:51:26 -03001228 snprintf(vfd->name, sizeof(vfd->name), "%s", S5P_MFC_DEC_NAME);
1229 dev->vfd_dec = vfd;
Kamil Debskiaf935742011-06-21 10:51:26 -03001230 video_set_drvdata(vfd, dev);
1231
1232 /* encoder */
1233 vfd = video_device_alloc();
1234 if (!vfd) {
1235 v4l2_err(&dev->v4l2_dev, "Failed to allocate video device\n");
1236 ret = -ENOMEM;
1237 goto err_enc_alloc;
1238 }
Joonyoung Shimd0ce8982014-02-20 23:22:12 -03001239 vfd->fops = &s5p_mfc_fops;
Kamil Debskiaf935742011-06-21 10:51:26 -03001240 vfd->ioctl_ops = get_enc_v4l2_ioctl_ops();
Joonyoung Shimd0ce8982014-02-20 23:22:12 -03001241 vfd->release = video_device_release;
Kamil Debskiaf935742011-06-21 10:51:26 -03001242 vfd->lock = &dev->mfc_mutex;
1243 vfd->v4l2_dev = &dev->v4l2_dev;
Arun Kumar Kcdcf45e2012-10-04 16:14:56 -03001244 vfd->vfl_dir = VFL_DIR_M2M;
Kamil Debskiaf935742011-06-21 10:51:26 -03001245 snprintf(vfd->name, sizeof(vfd->name), "%s", S5P_MFC_ENC_NAME);
1246 dev->vfd_enc = vfd;
Kamil Debskiaf935742011-06-21 10:51:26 -03001247 video_set_drvdata(vfd, dev);
1248 platform_set_drvdata(pdev, dev);
1249
1250 dev->hw_lock = 0;
Kamil Debskiaf935742011-06-21 10:51:26 -03001251 INIT_WORK(&dev->watchdog_work, s5p_mfc_watchdog_worker);
1252 atomic_set(&dev->watchdog_cnt, 0);
1253 init_timer(&dev->watchdog_timer);
1254 dev->watchdog_timer.data = (unsigned long)dev;
1255 dev->watchdog_timer.function = s5p_mfc_watchdog;
1256
Arun Kumar K43a1ea12012-10-03 22:19:08 -03001257 /* Initialize HW ops and commands based on MFC version */
1258 s5p_mfc_init_hw_ops(dev);
1259 s5p_mfc_init_hw_cmds(dev);
Kiran AVND6a9c6f682014-05-19 09:33:05 -03001260 s5p_mfc_init_regs(dev);
Arun Kumar K43a1ea12012-10-03 22:19:08 -03001261
Javier Martinez Canillasc974c432016-05-03 16:27:18 -04001262 /* Register decoder and encoder */
1263 ret = video_register_device(dev->vfd_dec, VFL_TYPE_GRABBER, 0);
1264 if (ret) {
1265 v4l2_err(&dev->v4l2_dev, "Failed to register video device\n");
Javier Martinez Canillasc974c432016-05-03 16:27:18 -04001266 goto err_dec_reg;
1267 }
1268 v4l2_info(&dev->v4l2_dev,
1269 "decoder registered as /dev/video%d\n", dev->vfd_dec->num);
1270
1271 ret = video_register_device(dev->vfd_enc, VFL_TYPE_GRABBER, 0);
1272 if (ret) {
1273 v4l2_err(&dev->v4l2_dev, "Failed to register video device\n");
Javier Martinez Canillasc974c432016-05-03 16:27:18 -04001274 goto err_enc_reg;
1275 }
1276 v4l2_info(&dev->v4l2_dev,
1277 "encoder registered as /dev/video%d\n", dev->vfd_enc->num);
1278
Kamil Debskiaf935742011-06-21 10:51:26 -03001279 pr_debug("%s--\n", __func__);
1280 return 0;
1281
1282/* Deinit MFC if probe had failed */
1283err_enc_reg:
Kamil Debskiaf935742011-06-21 10:51:26 -03001284 video_unregister_device(dev->vfd_dec);
1285err_dec_reg:
Javier Martinez Canillasc974c432016-05-03 16:27:18 -04001286 video_device_release(dev->vfd_enc);
1287err_enc_alloc:
Kamil Debskiaf935742011-06-21 10:51:26 -03001288 video_device_release(dev->vfd_dec);
1289err_dec_alloc:
1290 v4l2_device_unregister(&dev->v4l2_dev);
1291err_v4l2_dev_reg:
Kamil Debski2e731e42013-01-03 11:02:07 -03001292 s5p_mfc_release_firmware(dev);
Kamil Debskiaf935742011-06-21 10:51:26 -03001293err_res:
1294 s5p_mfc_final_pm(dev);
Marek Szyprowskie4fac742016-06-08 08:33:40 -03001295err_dma:
1296 s5p_mfc_unconfigure_dma_memory(dev);
Sachin Kamatd310f472012-05-14 08:22:27 -03001297
Kamil Debskiaf935742011-06-21 10:51:26 -03001298 pr_debug("%s-- with error\n", __func__);
1299 return ret;
1300
1301}
1302
1303/* Remove the driver */
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001304static int s5p_mfc_remove(struct platform_device *pdev)
Kamil Debskiaf935742011-06-21 10:51:26 -03001305{
1306 struct s5p_mfc_dev *dev = platform_get_drvdata(pdev);
Shuah Khand695c122016-07-08 19:29:25 -03001307 struct s5p_mfc_ctx *ctx;
1308 int i;
Kamil Debskiaf935742011-06-21 10:51:26 -03001309
1310 v4l2_info(&dev->v4l2_dev, "Removing %s\n", pdev->name);
1311
Shuah Khand695c122016-07-08 19:29:25 -03001312 /*
1313 * Clear ctx dev pointer to avoid races between s5p_mfc_remove()
1314 * and s5p_mfc_release() and s5p_mfc_release() accessing ctx->dev
1315 * after s5p_mfc_remove() is run during unbind.
1316 */
1317 mutex_lock(&dev->mfc_mutex);
1318 for (i = 0; i < MFC_NUM_CONTEXTS; i++) {
1319 ctx = dev->ctx[i];
1320 if (!ctx)
1321 continue;
1322 /* clear ctx->dev */
1323 ctx->dev = NULL;
1324 }
1325 mutex_unlock(&dev->mfc_mutex);
1326
Kamil Debskiaf935742011-06-21 10:51:26 -03001327 del_timer_sync(&dev->watchdog_timer);
Bhaktipriya Shridhared900132016-07-16 05:30:25 -03001328 flush_work(&dev->watchdog_work);
Kamil Debskiaf935742011-06-21 10:51:26 -03001329
1330 video_unregister_device(dev->vfd_enc);
1331 video_unregister_device(dev->vfd_dec);
Shuah Khan6610ef02016-06-28 16:17:17 -03001332 video_device_release(dev->vfd_enc);
1333 video_device_release(dev->vfd_dec);
Kamil Debskiaf935742011-06-21 10:51:26 -03001334 v4l2_device_unregister(&dev->v4l2_dev);
Kamil Debski2e731e42013-01-03 11:02:07 -03001335 s5p_mfc_release_firmware(dev);
Marek Szyprowskic79667d2016-05-24 15:31:26 +02001336 s5p_mfc_unconfigure_dma_memory(dev);
Marek Szyprowski712b6172016-05-24 09:16:07 +02001337 vb2_dma_contig_clear_max_seg_size(dev->mem_dev_l);
1338 vb2_dma_contig_clear_max_seg_size(dev->mem_dev_r);
Kamil Debskiaf935742011-06-21 10:51:26 -03001339
Kamil Debskiaf935742011-06-21 10:51:26 -03001340 s5p_mfc_final_pm(dev);
Kamil Debskiaf935742011-06-21 10:51:26 -03001341 return 0;
1342}
1343
1344#ifdef CONFIG_PM_SLEEP
1345
1346static int s5p_mfc_suspend(struct device *dev)
1347{
1348 struct platform_device *pdev = to_platform_device(dev);
1349 struct s5p_mfc_dev *m_dev = platform_get_drvdata(pdev);
1350 int ret;
1351
1352 if (m_dev->num_inst == 0)
1353 return 0;
Sachin Kamat81c9bcf2012-09-28 04:01:35 -03001354
Kamil Debskiaf935742011-06-21 10:51:26 -03001355 if (test_and_set_bit(0, &m_dev->enter_suspend) != 0) {
1356 mfc_err("Error: going to suspend for a second time\n");
1357 return -EIO;
1358 }
1359
1360 /* Check if we're processing then wait if it necessary. */
1361 while (test_and_set_bit(0, &m_dev->hw_lock) != 0) {
1362 /* Try and lock the HW */
1363 /* Wait on the interrupt waitqueue */
1364 ret = wait_event_interruptible_timeout(m_dev->queue,
Prathyush K76a4ddb2013-10-04 01:47:19 -03001365 m_dev->int_cond, msecs_to_jiffies(MFC_INT_TIMEOUT));
Kamil Debskiaf935742011-06-21 10:51:26 -03001366 if (ret == 0) {
1367 mfc_err("Waiting for hardware to finish timed out\n");
Prathyush K64370992014-10-21 08:06:57 -03001368 clear_bit(0, &m_dev->enter_suspend);
Kamil Debskiaf935742011-06-21 10:51:26 -03001369 return -EIO;
1370 }
1371 }
Sachin Kamat81c9bcf2012-09-28 04:01:35 -03001372
Prathyush K64370992014-10-21 08:06:57 -03001373 ret = s5p_mfc_sleep(m_dev);
1374 if (ret) {
1375 clear_bit(0, &m_dev->enter_suspend);
1376 clear_bit(0, &m_dev->hw_lock);
1377 }
1378 return ret;
Kamil Debskiaf935742011-06-21 10:51:26 -03001379}
1380
1381static int s5p_mfc_resume(struct device *dev)
1382{
1383 struct platform_device *pdev = to_platform_device(dev);
1384 struct s5p_mfc_dev *m_dev = platform_get_drvdata(pdev);
1385
1386 if (m_dev->num_inst == 0)
1387 return 0;
1388 return s5p_mfc_wakeup(m_dev);
1389}
1390#endif
1391
Rafael J. Wysockie243c7c2014-12-04 01:10:10 +01001392#ifdef CONFIG_PM
Kamil Debskiaf935742011-06-21 10:51:26 -03001393static int s5p_mfc_runtime_suspend(struct device *dev)
1394{
1395 struct platform_device *pdev = to_platform_device(dev);
1396 struct s5p_mfc_dev *m_dev = platform_get_drvdata(pdev);
1397
1398 atomic_set(&m_dev->pm.power, 0);
1399 return 0;
1400}
1401
1402static int s5p_mfc_runtime_resume(struct device *dev)
1403{
1404 struct platform_device *pdev = to_platform_device(dev);
1405 struct s5p_mfc_dev *m_dev = platform_get_drvdata(pdev);
Kamil Debskiaf935742011-06-21 10:51:26 -03001406
Kamil Debskiaf935742011-06-21 10:51:26 -03001407 atomic_set(&m_dev->pm.power, 1);
1408 return 0;
1409}
1410#endif
1411
1412/* Power management */
1413static const struct dev_pm_ops s5p_mfc_pm_ops = {
1414 SET_SYSTEM_SLEEP_PM_OPS(s5p_mfc_suspend, s5p_mfc_resume)
1415 SET_RUNTIME_PM_OPS(s5p_mfc_runtime_suspend, s5p_mfc_runtime_resume,
1416 NULL)
1417};
1418
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001419static struct s5p_mfc_buf_size_v5 mfc_buf_size_v5 = {
Arun Kumar K8f532a72012-10-03 22:19:09 -03001420 .h264_ctx = MFC_H264_CTX_BUF_SIZE,
1421 .non_h264_ctx = MFC_CTX_BUF_SIZE,
1422 .dsc = DESC_BUF_SIZE,
1423 .shm = SHARED_BUF_SIZE,
1424};
1425
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001426static struct s5p_mfc_buf_size buf_size_v5 = {
Arun Kumar K8f532a72012-10-03 22:19:09 -03001427 .fw = MAX_FW_SIZE,
1428 .cpb = MAX_CPB_SIZE,
1429 .priv = &mfc_buf_size_v5,
1430};
1431
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001432static struct s5p_mfc_buf_align mfc_buf_align_v5 = {
Arun Kumar K8f532a72012-10-03 22:19:09 -03001433 .base = MFC_BASE_ALIGN_ORDER,
1434};
1435
1436static struct s5p_mfc_variant mfc_drvdata_v5 = {
1437 .version = MFC_VERSION,
Kamil Debski9aa5f002014-05-20 10:15:13 -03001438 .version_bit = MFC_V5_BIT,
Arun Kumar K8f532a72012-10-03 22:19:09 -03001439 .port_num = MFC_NUM_PORTS,
1440 .buf_size = &buf_size_v5,
1441 .buf_align = &mfc_buf_align_v5,
Arun Kumar K77ba6b72014-05-21 06:29:30 -03001442 .fw_name[0] = "s5p-mfc.fw",
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -03001443};
1444
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001445static struct s5p_mfc_buf_size_v6 mfc_buf_size_v6 = {
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -03001446 .dev_ctx = MFC_CTX_BUF_SIZE_V6,
1447 .h264_dec_ctx = MFC_H264_DEC_CTX_BUF_SIZE_V6,
1448 .other_dec_ctx = MFC_OTHER_DEC_CTX_BUF_SIZE_V6,
1449 .h264_enc_ctx = MFC_H264_ENC_CTX_BUF_SIZE_V6,
1450 .other_enc_ctx = MFC_OTHER_ENC_CTX_BUF_SIZE_V6,
1451};
1452
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001453static struct s5p_mfc_buf_size buf_size_v6 = {
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -03001454 .fw = MAX_FW_SIZE_V6,
1455 .cpb = MAX_CPB_SIZE_V6,
1456 .priv = &mfc_buf_size_v6,
1457};
1458
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001459static struct s5p_mfc_buf_align mfc_buf_align_v6 = {
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -03001460 .base = 0,
1461};
1462
1463static struct s5p_mfc_variant mfc_drvdata_v6 = {
1464 .version = MFC_VERSION_V6,
Kamil Debski9aa5f002014-05-20 10:15:13 -03001465 .version_bit = MFC_V6_BIT,
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -03001466 .port_num = MFC_NUM_PORTS_V6,
1467 .buf_size = &buf_size_v6,
1468 .buf_align = &mfc_buf_align_v6,
Arun Kumar K77ba6b72014-05-21 06:29:30 -03001469 .fw_name[0] = "s5p-mfc-v6.fw",
1470 /*
1471 * v6-v2 firmware contains bug fixes and interface change
1472 * for init buffer command
1473 */
1474 .fw_name[1] = "s5p-mfc-v6-v2.fw",
Arun Kumar K8f532a72012-10-03 22:19:09 -03001475};
1476
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001477static struct s5p_mfc_buf_size_v6 mfc_buf_size_v7 = {
Arun Kumar K5441e9d2013-07-09 01:24:38 -03001478 .dev_ctx = MFC_CTX_BUF_SIZE_V7,
1479 .h264_dec_ctx = MFC_H264_DEC_CTX_BUF_SIZE_V7,
1480 .other_dec_ctx = MFC_OTHER_DEC_CTX_BUF_SIZE_V7,
1481 .h264_enc_ctx = MFC_H264_ENC_CTX_BUF_SIZE_V7,
1482 .other_enc_ctx = MFC_OTHER_ENC_CTX_BUF_SIZE_V7,
1483};
1484
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001485static struct s5p_mfc_buf_size buf_size_v7 = {
Arun Kumar K5441e9d2013-07-09 01:24:38 -03001486 .fw = MAX_FW_SIZE_V7,
1487 .cpb = MAX_CPB_SIZE_V7,
1488 .priv = &mfc_buf_size_v7,
1489};
1490
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001491static struct s5p_mfc_buf_align mfc_buf_align_v7 = {
Arun Kumar K5441e9d2013-07-09 01:24:38 -03001492 .base = 0,
1493};
1494
1495static struct s5p_mfc_variant mfc_drvdata_v7 = {
1496 .version = MFC_VERSION_V7,
Kamil Debski9aa5f002014-05-20 10:15:13 -03001497 .version_bit = MFC_V7_BIT,
Arun Kumar K5441e9d2013-07-09 01:24:38 -03001498 .port_num = MFC_NUM_PORTS_V7,
1499 .buf_size = &buf_size_v7,
1500 .buf_align = &mfc_buf_align_v7,
Arun Kumar K77ba6b72014-05-21 06:29:30 -03001501 .fw_name[0] = "s5p-mfc-v7.fw",
Arun Kumar K5441e9d2013-07-09 01:24:38 -03001502};
1503
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001504static struct s5p_mfc_buf_size_v6 mfc_buf_size_v8 = {
Kiran AVNDe2b9deb2014-05-19 09:50:01 -03001505 .dev_ctx = MFC_CTX_BUF_SIZE_V8,
1506 .h264_dec_ctx = MFC_H264_DEC_CTX_BUF_SIZE_V8,
1507 .other_dec_ctx = MFC_OTHER_DEC_CTX_BUF_SIZE_V8,
Kiran AVND3e594ce72014-05-19 09:50:02 -03001508 .h264_enc_ctx = MFC_H264_ENC_CTX_BUF_SIZE_V8,
1509 .other_enc_ctx = MFC_OTHER_ENC_CTX_BUF_SIZE_V8,
Kiran AVNDe2b9deb2014-05-19 09:50:01 -03001510};
1511
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001512static struct s5p_mfc_buf_size buf_size_v8 = {
Kiran AVNDe2b9deb2014-05-19 09:50:01 -03001513 .fw = MAX_FW_SIZE_V8,
1514 .cpb = MAX_CPB_SIZE_V8,
1515 .priv = &mfc_buf_size_v8,
1516};
1517
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001518static struct s5p_mfc_buf_align mfc_buf_align_v8 = {
Kiran AVNDe2b9deb2014-05-19 09:50:01 -03001519 .base = 0,
1520};
1521
1522static struct s5p_mfc_variant mfc_drvdata_v8 = {
1523 .version = MFC_VERSION_V8,
1524 .version_bit = MFC_V8_BIT,
1525 .port_num = MFC_NUM_PORTS_V8,
1526 .buf_size = &buf_size_v8,
1527 .buf_align = &mfc_buf_align_v8,
Arun Kumar K77ba6b72014-05-21 06:29:30 -03001528 .fw_name[0] = "s5p-mfc-v8.fw",
Kiran AVNDe2b9deb2014-05-19 09:50:01 -03001529};
1530
Arun Kumar Kb27a23b2012-10-25 05:24:14 -03001531static const struct of_device_id exynos_mfc_match[] = {
1532 {
1533 .compatible = "samsung,mfc-v5",
1534 .data = &mfc_drvdata_v5,
1535 }, {
1536 .compatible = "samsung,mfc-v6",
1537 .data = &mfc_drvdata_v6,
Arun Kumar K5441e9d2013-07-09 01:24:38 -03001538 }, {
1539 .compatible = "samsung,mfc-v7",
1540 .data = &mfc_drvdata_v7,
Kiran AVNDe2b9deb2014-05-19 09:50:01 -03001541 }, {
1542 .compatible = "samsung,mfc-v8",
1543 .data = &mfc_drvdata_v8,
Arun Kumar Kb27a23b2012-10-25 05:24:14 -03001544 },
1545 {},
1546};
1547MODULE_DEVICE_TABLE(of, exynos_mfc_match);
1548
1549static void *mfc_get_drv_data(struct platform_device *pdev)
1550{
1551 struct s5p_mfc_variant *driver_data = NULL;
Marek Szyprowskied3e34e2015-12-09 12:00:15 -02001552 const struct of_device_id *match;
Arun Kumar Kb27a23b2012-10-25 05:24:14 -03001553
Marek Szyprowskied3e34e2015-12-09 12:00:15 -02001554 match = of_match_node(exynos_mfc_match, pdev->dev.of_node);
1555 if (match)
1556 driver_data = (struct s5p_mfc_variant *)match->data;
1557
Arun Kumar Kb27a23b2012-10-25 05:24:14 -03001558 return driver_data;
1559}
1560
Kamil Debski1e393e92011-08-08 13:12:51 -03001561static struct platform_driver s5p_mfc_driver = {
Arun Kumar K8f532a72012-10-03 22:19:09 -03001562 .probe = s5p_mfc_probe,
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001563 .remove = s5p_mfc_remove,
Kamil Debskiaf935742011-06-21 10:51:26 -03001564 .driver = {
1565 .name = S5P_MFC_NAME,
Arun Kumar Kb27a23b2012-10-25 05:24:14 -03001566 .pm = &s5p_mfc_pm_ops,
1567 .of_match_table = exynos_mfc_match,
Kamil Debskiaf935742011-06-21 10:51:26 -03001568 },
1569};
1570
Axel Lin1d6629b2012-01-10 03:21:49 -03001571module_platform_driver(s5p_mfc_driver);
Kamil Debskiaf935742011-06-21 10:51:26 -03001572
1573MODULE_LICENSE("GPL");
1574MODULE_AUTHOR("Kamil Debski <k.debski@samsung.com>");
1575MODULE_DESCRIPTION("Samsung S5P Multi Format Codec V4L2 driver");
1576