blob: cff59aa9a615f95fe918a9e564b45230df51d15c [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>
Junghak Sungc1399902015-09-22 10:30:29 -030025#include <media/videobuf2-v4l2.h>
Arun Kumar K43a1ea12012-10-03 22:19:08 -030026#include "s5p_mfc_common.h"
Kamil Debskiaf935742011-06-21 10:51:26 -030027#include "s5p_mfc_ctrl.h"
28#include "s5p_mfc_debug.h"
29#include "s5p_mfc_dec.h"
30#include "s5p_mfc_enc.h"
31#include "s5p_mfc_intr.h"
Arun Kumar K43a1ea12012-10-03 22:19:08 -030032#include "s5p_mfc_opr.h"
33#include "s5p_mfc_cmd.h"
Kamil Debskiaf935742011-06-21 10:51:26 -030034#include "s5p_mfc_pm.h"
Kamil Debskiaf935742011-06-21 10:51:26 -030035
36#define S5P_MFC_NAME "s5p-mfc"
37#define S5P_MFC_DEC_NAME "s5p-mfc-dec"
38#define S5P_MFC_ENC_NAME "s5p-mfc-enc"
39
Mauro Carvalho Chehab139adba2014-08-22 06:07:57 -050040int mfc_debug_level;
41module_param_named(debug, mfc_debug_level, int, S_IRUGO | S_IWUSR);
Kamil Debskiaf935742011-06-21 10:51:26 -030042MODULE_PARM_DESC(debug, "Debug level - higher value produces more verbose messages");
43
44/* Helper functions for interrupt processing */
Andrzej Hajda7fb89ec2012-08-14 06:13:40 -030045
Kamil Debskiaf935742011-06-21 10:51:26 -030046/* Remove from hw execution round robin */
Andrzej Hajda7fb89ec2012-08-14 06:13:40 -030047void clear_work_bit(struct s5p_mfc_ctx *ctx)
Kamil Debskiaf935742011-06-21 10:51:26 -030048{
49 struct s5p_mfc_dev *dev = ctx->dev;
50
51 spin_lock(&dev->condlock);
Andrzej Hajda7fb89ec2012-08-14 06:13:40 -030052 __clear_bit(ctx->num, &dev->ctx_work_bits);
Kamil Debskiaf935742011-06-21 10:51:26 -030053 spin_unlock(&dev->condlock);
54}
55
Andrzej Hajda7fb89ec2012-08-14 06:13:40 -030056/* Add to hw execution round robin */
57void set_work_bit(struct s5p_mfc_ctx *ctx)
58{
59 struct s5p_mfc_dev *dev = ctx->dev;
60
61 spin_lock(&dev->condlock);
62 __set_bit(ctx->num, &dev->ctx_work_bits);
63 spin_unlock(&dev->condlock);
64}
65
66/* Remove from hw execution round robin */
67void clear_work_bit_irqsave(struct s5p_mfc_ctx *ctx)
68{
69 struct s5p_mfc_dev *dev = ctx->dev;
70 unsigned long flags;
71
72 spin_lock_irqsave(&dev->condlock, flags);
73 __clear_bit(ctx->num, &dev->ctx_work_bits);
74 spin_unlock_irqrestore(&dev->condlock, flags);
75}
76
77/* Add to hw execution round robin */
78void set_work_bit_irqsave(struct s5p_mfc_ctx *ctx)
79{
80 struct s5p_mfc_dev *dev = ctx->dev;
81 unsigned long flags;
82
83 spin_lock_irqsave(&dev->condlock, flags);
84 __set_bit(ctx->num, &dev->ctx_work_bits);
85 spin_unlock_irqrestore(&dev->condlock, flags);
86}
87
Andrzej Hajda05d1d0f2015-12-02 06:22:28 -020088int s5p_mfc_get_new_ctx(struct s5p_mfc_dev *dev)
89{
90 unsigned long flags;
91 int ctx;
92
93 spin_lock_irqsave(&dev->condlock, flags);
94 ctx = dev->curr_ctx;
95 do {
96 ctx = (ctx + 1) % MFC_NUM_CONTEXTS;
97 if (ctx == dev->curr_ctx) {
98 if (!test_bit(ctx, &dev->ctx_work_bits))
99 ctx = -EAGAIN;
100 break;
101 }
102 } while (!test_bit(ctx, &dev->ctx_work_bits));
103 spin_unlock_irqrestore(&dev->condlock, flags);
104
105 return ctx;
106}
107
Kamil Debskiaf935742011-06-21 10:51:26 -0300108/* Wake up context wait_queue */
109static void wake_up_ctx(struct s5p_mfc_ctx *ctx, unsigned int reason,
110 unsigned int err)
111{
112 ctx->int_cond = 1;
113 ctx->int_type = reason;
114 ctx->int_err = err;
115 wake_up(&ctx->queue);
116}
117
118/* Wake up device wait_queue */
119static void wake_up_dev(struct s5p_mfc_dev *dev, unsigned int reason,
120 unsigned int err)
121{
122 dev->int_cond = 1;
123 dev->int_type = reason;
124 dev->int_err = err;
125 wake_up(&dev->queue);
126}
127
Andrzej Hajda62bbd722015-12-02 06:22:29 -0200128void s5p_mfc_cleanup_queue(struct list_head *lh, struct vb2_queue *vq)
129{
130 struct s5p_mfc_buf *b;
131 int i;
132
133 while (!list_empty(lh)) {
134 b = list_entry(lh->next, struct s5p_mfc_buf, list);
135 for (i = 0; i < b->b->vb2_buf.num_planes; i++)
136 vb2_set_plane_payload(&b->b->vb2_buf, i, 0);
137 vb2_buffer_done(&b->b->vb2_buf, VB2_BUF_STATE_ERROR);
138 list_del(&b->list);
139 }
140}
141
Sachin Kamata13bba42012-05-10 03:32:01 -0300142static void s5p_mfc_watchdog(unsigned long arg)
Kamil Debskiaf935742011-06-21 10:51:26 -0300143{
144 struct s5p_mfc_dev *dev = (struct s5p_mfc_dev *)arg;
145
146 if (test_bit(0, &dev->hw_lock))
147 atomic_inc(&dev->watchdog_cnt);
148 if (atomic_read(&dev->watchdog_cnt) >= MFC_WATCHDOG_CNT) {
149 /* This means that hw is busy and no interrupts were
150 * generated by hw for the Nth time of running this
151 * watchdog timer. This usually means a serious hw
152 * error. Now it is time to kill all instances and
153 * reset the MFC. */
154 mfc_err("Time out during waiting for HW\n");
155 queue_work(dev->watchdog_workqueue, &dev->watchdog_work);
156 }
157 dev->watchdog_timer.expires = jiffies +
158 msecs_to_jiffies(MFC_WATCHDOG_INTERVAL);
159 add_timer(&dev->watchdog_timer);
160}
161
162static void s5p_mfc_watchdog_worker(struct work_struct *work)
163{
164 struct s5p_mfc_dev *dev;
165 struct s5p_mfc_ctx *ctx;
166 unsigned long flags;
167 int mutex_locked;
168 int i, ret;
169
170 dev = container_of(work, struct s5p_mfc_dev, watchdog_work);
171
172 mfc_err("Driver timeout error handling\n");
173 /* Lock the mutex that protects open and release.
174 * This is necessary as they may load and unload firmware. */
175 mutex_locked = mutex_trylock(&dev->mfc_mutex);
176 if (!mutex_locked)
177 mfc_err("Error: some instance may be closing/opening\n");
178 spin_lock_irqsave(&dev->irqlock, flags);
179
180 s5p_mfc_clock_off();
181
182 for (i = 0; i < MFC_NUM_CONTEXTS; i++) {
183 ctx = dev->ctx[i];
184 if (!ctx)
185 continue;
186 ctx->state = MFCINST_ERROR;
Andrzej Hajda62bbd722015-12-02 06:22:29 -0200187 s5p_mfc_cleanup_queue(&ctx->dst_queue, &ctx->vq_dst);
188 s5p_mfc_cleanup_queue(&ctx->src_queue, &ctx->vq_src);
Kamil Debskiaf935742011-06-21 10:51:26 -0300189 clear_work_bit(ctx);
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300190 wake_up_ctx(ctx, S5P_MFC_R2H_CMD_ERR_RET, 0);
Kamil Debskiaf935742011-06-21 10:51:26 -0300191 }
192 clear_bit(0, &dev->hw_lock);
193 spin_unlock_irqrestore(&dev->irqlock, flags);
Arun Mankuzhib16e6442014-10-21 08:07:03 -0300194
195 /* De-init MFC */
196 s5p_mfc_deinit_hw(dev);
197
Kamil Debskiaf935742011-06-21 10:51:26 -0300198 /* Double check if there is at least one instance running.
199 * If no instance is in memory than no firmware should be present */
200 if (dev->num_inst > 0) {
Arun Kumar K46075002014-05-21 06:29:29 -0300201 ret = s5p_mfc_load_firmware(dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300202 if (ret) {
203 mfc_err("Failed to reload FW\n");
204 goto unlock;
205 }
206 s5p_mfc_clock_on();
207 ret = s5p_mfc_init_hw(dev);
208 if (ret)
209 mfc_err("Failed to reinit FW\n");
210 }
211unlock:
212 if (mutex_locked)
213 mutex_unlock(&dev->mfc_mutex);
214}
215
Kamil Debskiaf935742011-06-21 10:51:26 -0300216static void s5p_mfc_handle_frame_all_extracted(struct s5p_mfc_ctx *ctx)
217{
218 struct s5p_mfc_buf *dst_buf;
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300219 struct s5p_mfc_dev *dev = ctx->dev;
Kamil Debskiaf935742011-06-21 10:51:26 -0300220
221 ctx->state = MFCINST_FINISHED;
222 ctx->sequence++;
223 while (!list_empty(&ctx->dst_queue)) {
224 dst_buf = list_entry(ctx->dst_queue.next,
225 struct s5p_mfc_buf, list);
226 mfc_debug(2, "Cleaning up buffer: %d\n",
Junghak Sung2d700712015-09-22 10:30:30 -0300227 dst_buf->b->vb2_buf.index);
228 vb2_set_plane_payload(&dst_buf->b->vb2_buf, 0, 0);
229 vb2_set_plane_payload(&dst_buf->b->vb2_buf, 1, 0);
Kamil Debskiaf935742011-06-21 10:51:26 -0300230 list_del(&dst_buf->list);
Andrzej Hajda4d0b0ed2015-10-07 07:13:45 -0300231 dst_buf->flags |= MFC_BUF_FLAG_EOS;
Kamil Debskiaf935742011-06-21 10:51:26 -0300232 ctx->dst_queue_cnt--;
Junghak Sung2d700712015-09-22 10:30:30 -0300233 dst_buf->b->sequence = (ctx->sequence++);
Kamil Debskiaf935742011-06-21 10:51:26 -0300234
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300235 if (s5p_mfc_hw_call(dev->mfc_ops, get_pic_type_top, ctx) ==
236 s5p_mfc_hw_call(dev->mfc_ops, get_pic_type_bot, ctx))
Junghak Sung2d700712015-09-22 10:30:30 -0300237 dst_buf->b->field = V4L2_FIELD_NONE;
Kamil Debskiaf935742011-06-21 10:51:26 -0300238 else
Junghak Sung2d700712015-09-22 10:30:30 -0300239 dst_buf->b->field = V4L2_FIELD_INTERLACED;
240 dst_buf->b->flags |= V4L2_BUF_FLAG_LAST;
Kamil Debskiaf935742011-06-21 10:51:26 -0300241
Junghak Sung2d700712015-09-22 10:30:30 -0300242 ctx->dec_dst_flag &= ~(1 << dst_buf->b->vb2_buf.index);
243 vb2_buffer_done(&dst_buf->b->vb2_buf, VB2_BUF_STATE_DONE);
Kamil Debskiaf935742011-06-21 10:51:26 -0300244 }
245}
246
247static void s5p_mfc_handle_frame_copy_time(struct s5p_mfc_ctx *ctx)
248{
249 struct s5p_mfc_dev *dev = ctx->dev;
250 struct s5p_mfc_buf *dst_buf, *src_buf;
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300251 size_t dec_y_addr;
252 unsigned int frame_type;
253
Ilja Friedelbb21c542014-10-21 08:06:58 -0300254 /* Make sure we actually have a new frame before continuing. */
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300255 frame_type = s5p_mfc_hw_call(dev->mfc_ops, get_dec_frame_type, dev);
Ilja Friedelbb21c542014-10-21 08:06:58 -0300256 if (frame_type == S5P_FIMV_DECODE_FRAME_SKIPPED)
257 return;
258 dec_y_addr = s5p_mfc_hw_call(dev->mfc_ops, get_dec_y_adr, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300259
260 /* Copy timestamp / timecode from decoded src to dst and set
Ilja Friedelbb21c542014-10-21 08:06:58 -0300261 appropriate flags. */
Kamil Debskiaf935742011-06-21 10:51:26 -0300262 src_buf = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
263 list_for_each_entry(dst_buf, &ctx->dst_queue, list) {
Junghak Sung2d700712015-09-22 10:30:30 -0300264 if (vb2_dma_contig_plane_dma_addr(&dst_buf->b->vb2_buf, 0)
265 == dec_y_addr) {
266 dst_buf->b->timecode =
267 src_buf->b->timecode;
Junghak Sungd6dd6452015-11-03 08:16:37 -0200268 dst_buf->b->vb2_buf.timestamp =
269 src_buf->b->vb2_buf.timestamp;
Junghak Sung2d700712015-09-22 10:30:30 -0300270 dst_buf->b->flags &=
Sakari Ailus309f4d62014-02-08 14:21:35 -0300271 ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
Junghak Sung2d700712015-09-22 10:30:30 -0300272 dst_buf->b->flags |=
273 src_buf->b->flags
Sakari Ailus309f4d62014-02-08 14:21:35 -0300274 & V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
Kamil Debskiaf935742011-06-21 10:51:26 -0300275 switch (frame_type) {
276 case S5P_FIMV_DECODE_FRAME_I_FRAME:
Junghak Sung2d700712015-09-22 10:30:30 -0300277 dst_buf->b->flags |=
Kamil Debskiaf935742011-06-21 10:51:26 -0300278 V4L2_BUF_FLAG_KEYFRAME;
279 break;
280 case S5P_FIMV_DECODE_FRAME_P_FRAME:
Junghak Sung2d700712015-09-22 10:30:30 -0300281 dst_buf->b->flags |=
Kamil Debskiaf935742011-06-21 10:51:26 -0300282 V4L2_BUF_FLAG_PFRAME;
283 break;
284 case S5P_FIMV_DECODE_FRAME_B_FRAME:
Junghak Sung2d700712015-09-22 10:30:30 -0300285 dst_buf->b->flags |=
Kamil Debskiaf935742011-06-21 10:51:26 -0300286 V4L2_BUF_FLAG_BFRAME;
287 break;
Ilja Friedelbb21c542014-10-21 08:06:58 -0300288 default:
289 /* Don't know how to handle
290 S5P_FIMV_DECODE_FRAME_OTHER_FRAME. */
291 mfc_debug(2, "Unexpected frame type: %d\n",
292 frame_type);
Kamil Debskiaf935742011-06-21 10:51:26 -0300293 }
294 break;
295 }
296 }
297}
298
299static void s5p_mfc_handle_frame_new(struct s5p_mfc_ctx *ctx, unsigned int err)
300{
301 struct s5p_mfc_dev *dev = ctx->dev;
302 struct s5p_mfc_buf *dst_buf;
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300303 size_t dspl_y_addr;
304 unsigned int frame_type;
Kamil Debskiaf935742011-06-21 10:51:26 -0300305
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300306 dspl_y_addr = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_y_adr, dev);
Sjoerd Simons7c672812014-09-22 09:52:02 -0300307 if (IS_MFCV6_PLUS(dev))
308 frame_type = s5p_mfc_hw_call(dev->mfc_ops,
309 get_disp_frame_type, ctx);
310 else
311 frame_type = s5p_mfc_hw_call(dev->mfc_ops,
312 get_dec_frame_type, dev);
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300313
Kamil Debskiaf935742011-06-21 10:51:26 -0300314 /* If frame is same as previous then skip and do not dequeue */
315 if (frame_type == S5P_FIMV_DECODE_FRAME_SKIPPED) {
316 if (!ctx->after_packed_pb)
317 ctx->sequence++;
318 ctx->after_packed_pb = 0;
319 return;
320 }
321 ctx->sequence++;
322 /* The MFC returns address of the buffer, now we have to
323 * check which videobuf does it correspond to */
324 list_for_each_entry(dst_buf, &ctx->dst_queue, list) {
325 /* Check if this is the buffer we're looking for */
Junghak Sung2d700712015-09-22 10:30:30 -0300326 if (vb2_dma_contig_plane_dma_addr(&dst_buf->b->vb2_buf, 0)
327 == dspl_y_addr) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300328 list_del(&dst_buf->list);
329 ctx->dst_queue_cnt--;
Junghak Sung2d700712015-09-22 10:30:30 -0300330 dst_buf->b->sequence = ctx->sequence;
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300331 if (s5p_mfc_hw_call(dev->mfc_ops,
332 get_pic_type_top, ctx) ==
333 s5p_mfc_hw_call(dev->mfc_ops,
334 get_pic_type_bot, ctx))
Junghak Sung2d700712015-09-22 10:30:30 -0300335 dst_buf->b->field = V4L2_FIELD_NONE;
Kamil Debskiaf935742011-06-21 10:51:26 -0300336 else
Junghak Sung2d700712015-09-22 10:30:30 -0300337 dst_buf->b->field =
Kamil Debskiaf935742011-06-21 10:51:26 -0300338 V4L2_FIELD_INTERLACED;
Junghak Sung2d700712015-09-22 10:30:30 -0300339 vb2_set_plane_payload(&dst_buf->b->vb2_buf, 0,
340 ctx->luma_size);
341 vb2_set_plane_payload(&dst_buf->b->vb2_buf, 1,
342 ctx->chroma_size);
343 clear_bit(dst_buf->b->vb2_buf.index,
Kamil Debskiaf935742011-06-21 10:51:26 -0300344 &ctx->dec_dst_flag);
345
Junghak Sung2d700712015-09-22 10:30:30 -0300346 vb2_buffer_done(&dst_buf->b->vb2_buf, err ?
347 VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
Kamil Debskiaf935742011-06-21 10:51:26 -0300348
Kamil Debskiaf935742011-06-21 10:51:26 -0300349 break;
350 }
351 }
352}
353
354/* Handle frame decoding interrupt */
355static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
356 unsigned int reason, unsigned int err)
357{
358 struct s5p_mfc_dev *dev = ctx->dev;
359 unsigned int dst_frame_status;
Pawel Osciaka0517f52014-05-19 09:32:57 -0300360 unsigned int dec_frame_status;
Kamil Debskiaf935742011-06-21 10:51:26 -0300361 struct s5p_mfc_buf *src_buf;
362 unsigned long flags;
363 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;
Kamil Debskie2c3be22014-09-11 10:27:20 -0300378 s5p_mfc_hw_call_void(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();
Kamil Debskie2c3be22014-09-11 10:27:20 -0300382 s5p_mfc_hw_call_void(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
388 spin_lock_irqsave(&dev->irqlock, flags);
389 /* All frames remaining in the buffer have been extracted */
390 if (dst_frame_status == S5P_FIMV_DEC_STATUS_DECODING_EMPTY) {
391 if (ctx->state == MFCINST_RES_CHANGE_FLUSH) {
Pawel Osciak0520e4c2014-05-14 03:59:43 -0300392 static const struct v4l2_event ev_src_ch = {
393 .type = V4L2_EVENT_SOURCE_CHANGE,
394 .u.src_change.changes =
395 V4L2_EVENT_SRC_CH_RESOLUTION,
396 };
397
Kamil Debskiaf935742011-06-21 10:51:26 -0300398 s5p_mfc_handle_frame_all_extracted(ctx);
399 ctx->state = MFCINST_RES_CHANGE_END;
Pawel Osciak0520e4c2014-05-14 03:59:43 -0300400 v4l2_event_queue_fh(&ctx->fh, &ev_src_ch);
401
Kamil Debskiaf935742011-06-21 10:51:26 -0300402 goto leave_handle_frame;
403 } else {
404 s5p_mfc_handle_frame_all_extracted(ctx);
405 }
406 }
407
Pawel Osciaka0517f52014-05-19 09:32:57 -0300408 if (dec_frame_status == S5P_FIMV_DEC_STATUS_DECODING_DISPLAY)
Kamil Debskiaf935742011-06-21 10:51:26 -0300409 s5p_mfc_handle_frame_copy_time(ctx);
410
411 /* A frame has been decoded and is in the buffer */
412 if (dst_frame_status == S5P_FIMV_DEC_STATUS_DISPLAY_ONLY ||
413 dst_frame_status == S5P_FIMV_DEC_STATUS_DECODING_DISPLAY) {
414 s5p_mfc_handle_frame_new(ctx, err);
415 } else {
416 mfc_debug(2, "No frame decode\n");
417 }
418 /* Mark source buffer as complete */
419 if (dst_frame_status != S5P_FIMV_DEC_STATUS_DISPLAY_ONLY
420 && !list_empty(&ctx->src_queue)) {
421 src_buf = list_entry(ctx->src_queue.next, struct s5p_mfc_buf,
422 list);
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300423 ctx->consumed_stream += s5p_mfc_hw_call(dev->mfc_ops,
424 get_consumed_stream, dev);
425 if (ctx->codec_mode != S5P_MFC_CODEC_H264_DEC &&
Pawel Osciakf49f3ed2014-05-19 09:33:02 -0300426 ctx->codec_mode != S5P_MFC_CODEC_VP8_DEC &&
Arun Kumar Kd2a0db12012-11-14 09:26:45 -0300427 ctx->consumed_stream + STUFF_BYTE <
Junghak Sung2d700712015-09-22 10:30:30 -0300428 src_buf->b->vb2_buf.planes[0].bytesused) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300429 /* Run MFC again on the same buffer */
430 mfc_debug(2, "Running again the same buffer\n");
431 ctx->after_packed_pb = 1;
432 } else {
Kamil Debskiaf935742011-06-21 10:51:26 -0300433 mfc_debug(2, "MFC needs next buffer\n");
434 ctx->consumed_stream = 0;
Kamil Debskia34026e2013-01-11 12:29:33 -0300435 if (src_buf->flags & MFC_BUF_FLAG_EOS)
436 ctx->state = MFCINST_FINISHING;
Kamil Debskiaf935742011-06-21 10:51:26 -0300437 list_del(&src_buf->list);
438 ctx->src_queue_cnt--;
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300439 if (s5p_mfc_hw_call(dev->mfc_ops, err_dec, err) > 0)
Junghak Sung2d700712015-09-22 10:30:30 -0300440 vb2_buffer_done(&src_buf->b->vb2_buf,
441 VB2_BUF_STATE_ERROR);
Kamil Debskiaf935742011-06-21 10:51:26 -0300442 else
Junghak Sung2d700712015-09-22 10:30:30 -0300443 vb2_buffer_done(&src_buf->b->vb2_buf,
444 VB2_BUF_STATE_DONE);
Kamil Debskiaf935742011-06-21 10:51:26 -0300445 }
446 }
447leave_handle_frame:
448 spin_unlock_irqrestore(&dev->irqlock, flags);
449 if ((ctx->src_queue_cnt == 0 && ctx->state != MFCINST_FINISHING)
Arun Kumar Ke9d98dd2013-04-24 09:41:53 -0300450 || ctx->dst_queue_cnt < ctx->pb_count)
Kamil Debskiaf935742011-06-21 10:51:26 -0300451 clear_work_bit(ctx);
Kamil Debskie2c3be22014-09-11 10:27:20 -0300452 s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300453 wake_up_ctx(ctx, reason, err);
Pawel Osciak9a7bc6b2014-10-21 08:07:01 -0300454 WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
Kamil Debskiaf935742011-06-21 10:51:26 -0300455 s5p_mfc_clock_off();
Prathyush K76a4ddb2013-10-04 01:47:19 -0300456 /* if suspending, wake up device and do not try_run again*/
457 if (test_bit(0, &dev->enter_suspend))
458 wake_up_dev(dev, reason, err);
459 else
Kamil Debskie2c3be22014-09-11 10:27:20 -0300460 s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300461}
462
463/* Error handling for interrupt */
Kamil Debski7296e252012-12-21 05:32:59 -0300464static void s5p_mfc_handle_error(struct s5p_mfc_dev *dev,
465 struct s5p_mfc_ctx *ctx, unsigned int reason, unsigned int err)
Kamil Debskiaf935742011-06-21 10:51:26 -0300466{
Kamil Debskiaf935742011-06-21 10:51:26 -0300467 unsigned long flags;
468
Kamil Debskiaf935742011-06-21 10:51:26 -0300469 mfc_err("Interrupt Error: %08x\n", err);
Kamil Debskiaf935742011-06-21 10:51:26 -0300470
Kamil Debski7296e252012-12-21 05:32:59 -0300471 if (ctx != NULL) {
472 /* Error recovery is dependent on the state of context */
473 switch (ctx->state) {
474 case MFCINST_RES_CHANGE_INIT:
475 case MFCINST_RES_CHANGE_FLUSH:
476 case MFCINST_RES_CHANGE_END:
477 case MFCINST_FINISHING:
478 case MFCINST_FINISHED:
479 case MFCINST_RUNNING:
Jonathan McCrohan39c1cb22013-10-20 21:34:01 -0300480 /* It is highly probable that an error occurred
Kamil Debski7296e252012-12-21 05:32:59 -0300481 * while decoding a frame */
482 clear_work_bit(ctx);
483 ctx->state = MFCINST_ERROR;
484 /* Mark all dst buffers as having an error */
485 spin_lock_irqsave(&dev->irqlock, flags);
Andrzej Hajda62bbd722015-12-02 06:22:29 -0200486 s5p_mfc_cleanup_queue(&ctx->dst_queue, &ctx->vq_dst);
Kamil Debski7296e252012-12-21 05:32:59 -0300487 /* Mark all src buffers as having an error */
Andrzej Hajda62bbd722015-12-02 06:22:29 -0200488 s5p_mfc_cleanup_queue(&ctx->src_queue, &ctx->vq_src);
Kamil Debski7296e252012-12-21 05:32:59 -0300489 spin_unlock_irqrestore(&dev->irqlock, flags);
490 wake_up_ctx(ctx, reason, err);
491 break;
492 default:
493 clear_work_bit(ctx);
494 ctx->state = MFCINST_ERROR;
495 wake_up_ctx(ctx, reason, err);
496 break;
497 }
Kamil Debskiaf935742011-06-21 10:51:26 -0300498 }
Pawel Osciak9a7bc6b2014-10-21 08:07:01 -0300499 WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
Kamil Debskie2c3be22014-09-11 10:27:20 -0300500 s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev);
Kamil Debski7296e252012-12-21 05:32:59 -0300501 s5p_mfc_clock_off();
502 wake_up_dev(dev, reason, err);
Kamil Debskiaf935742011-06-21 10:51:26 -0300503 return;
504}
505
506/* Header parsing interrupt handling */
507static void s5p_mfc_handle_seq_done(struct s5p_mfc_ctx *ctx,
508 unsigned int reason, unsigned int err)
509{
510 struct s5p_mfc_dev *dev;
Kamil Debskiaf935742011-06-21 10:51:26 -0300511
Sachin Kamat12597622012-05-10 03:32:00 -0300512 if (ctx == NULL)
Kamil Debskiaf935742011-06-21 10:51:26 -0300513 return;
514 dev = ctx->dev;
515 if (ctx->c_ops->post_seq_start) {
516 if (ctx->c_ops->post_seq_start(ctx))
517 mfc_err("post_seq_start() failed\n");
518 } else {
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300519 ctx->img_width = s5p_mfc_hw_call(dev->mfc_ops, get_img_width,
520 dev);
521 ctx->img_height = s5p_mfc_hw_call(dev->mfc_ops, get_img_height,
522 dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300523
Kamil Debskie2c3be22014-09-11 10:27:20 -0300524 s5p_mfc_hw_call_void(dev->mfc_ops, dec_calc_dpb_size, ctx);
Arun Kumar K8f532a72012-10-03 22:19:09 -0300525
Arun Kumar Ke9d98dd2013-04-24 09:41:53 -0300526 ctx->pb_count = s5p_mfc_hw_call(dev->mfc_ops, get_dpb_count,
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300527 dev);
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -0300528 ctx->mv_count = s5p_mfc_hw_call(dev->mfc_ops, get_mv_count,
529 dev);
Julia Lawallbb869362012-01-12 17:49:30 -0300530 if (ctx->img_width == 0 || ctx->img_height == 0)
Kamil Debskiaf935742011-06-21 10:51:26 -0300531 ctx->state = MFCINST_ERROR;
532 else
533 ctx->state = MFCINST_HEAD_PARSED;
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -0300534
535 if ((ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
536 ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) &&
537 !list_empty(&ctx->src_queue)) {
538 struct s5p_mfc_buf *src_buf;
539 src_buf = list_entry(ctx->src_queue.next,
540 struct s5p_mfc_buf, list);
541 if (s5p_mfc_hw_call(dev->mfc_ops, get_consumed_stream,
542 dev) <
Junghak Sung2d700712015-09-22 10:30:30 -0300543 src_buf->b->vb2_buf.planes[0].bytesused)
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -0300544 ctx->head_processed = 0;
545 else
546 ctx->head_processed = 1;
547 } else {
548 ctx->head_processed = 1;
549 }
Kamil Debskiaf935742011-06-21 10:51:26 -0300550 }
Kamil Debskie2c3be22014-09-11 10:27:20 -0300551 s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300552 clear_work_bit(ctx);
Pawel Osciak9a7bc6b2014-10-21 08:07:01 -0300553 WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
Kamil Debskiaf935742011-06-21 10:51:26 -0300554 s5p_mfc_clock_off();
Kamil Debskie2c3be22014-09-11 10:27:20 -0300555 s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300556 wake_up_ctx(ctx, reason, err);
557}
558
559/* Header parsing interrupt handling */
560static void s5p_mfc_handle_init_buffers(struct s5p_mfc_ctx *ctx,
561 unsigned int reason, unsigned int err)
562{
563 struct s5p_mfc_buf *src_buf;
564 struct s5p_mfc_dev *dev;
565 unsigned long flags;
566
Sachin Kamat12597622012-05-10 03:32:00 -0300567 if (ctx == NULL)
Kamil Debskiaf935742011-06-21 10:51:26 -0300568 return;
569 dev = ctx->dev;
Kamil Debskie2c3be22014-09-11 10:27:20 -0300570 s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300571 ctx->int_type = reason;
572 ctx->int_err = err;
573 ctx->int_cond = 1;
Andrzej Hajda7fb89ec2012-08-14 06:13:40 -0300574 clear_work_bit(ctx);
Kamil Debskiaf935742011-06-21 10:51:26 -0300575 if (err == 0) {
576 ctx->state = MFCINST_RUNNING;
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -0300577 if (!ctx->dpb_flush_flag && ctx->head_processed) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300578 spin_lock_irqsave(&dev->irqlock, flags);
579 if (!list_empty(&ctx->src_queue)) {
580 src_buf = list_entry(ctx->src_queue.next,
581 struct s5p_mfc_buf, list);
582 list_del(&src_buf->list);
583 ctx->src_queue_cnt--;
Junghak Sung2d700712015-09-22 10:30:30 -0300584 vb2_buffer_done(&src_buf->b->vb2_buf,
Kamil Debskiaf935742011-06-21 10:51:26 -0300585 VB2_BUF_STATE_DONE);
586 }
587 spin_unlock_irqrestore(&dev->irqlock, flags);
588 } else {
589 ctx->dpb_flush_flag = 0;
590 }
Pawel Osciak9a7bc6b2014-10-21 08:07:01 -0300591 WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
Kamil Debskiaf935742011-06-21 10:51:26 -0300592
593 s5p_mfc_clock_off();
594
595 wake_up(&ctx->queue);
Kamil Debskie2c3be22014-09-11 10:27:20 -0300596 s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300597 } else {
Pawel Osciak9a7bc6b2014-10-21 08:07:01 -0300598 WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
Kamil Debskiaf935742011-06-21 10:51:26 -0300599
600 s5p_mfc_clock_off();
601
602 wake_up(&ctx->queue);
603 }
604}
605
Andrzej Hajda96c57772015-10-07 07:15:31 -0300606static void s5p_mfc_handle_stream_complete(struct s5p_mfc_ctx *ctx)
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300607{
608 struct s5p_mfc_dev *dev = ctx->dev;
609 struct s5p_mfc_buf *mb_entry;
610
Andrzej Hajda4130eab2013-05-28 03:26:16 -0300611 mfc_debug(2, "Stream completed\n");
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300612
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300613 ctx->state = MFCINST_FINISHED;
614
615 spin_lock(&dev->irqlock);
616 if (!list_empty(&ctx->dst_queue)) {
617 mb_entry = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf,
618 list);
619 list_del(&mb_entry->list);
620 ctx->dst_queue_cnt--;
Junghak Sung2d700712015-09-22 10:30:30 -0300621 vb2_set_plane_payload(&mb_entry->b->vb2_buf, 0, 0);
622 vb2_buffer_done(&mb_entry->b->vb2_buf, VB2_BUF_STATE_DONE);
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300623 }
624 spin_unlock(&dev->irqlock);
625
626 clear_work_bit(ctx);
627
Sachin Kamate8256442013-01-22 01:00:06 -0300628 WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300629
630 s5p_mfc_clock_off();
631 wake_up(&ctx->queue);
Kamil Debskie2c3be22014-09-11 10:27:20 -0300632 s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300633}
634
Kamil Debskiaf935742011-06-21 10:51:26 -0300635/* Interrupt processing */
636static irqreturn_t s5p_mfc_irq(int irq, void *priv)
637{
638 struct s5p_mfc_dev *dev = priv;
639 struct s5p_mfc_ctx *ctx;
640 unsigned int reason;
641 unsigned int err;
642
643 mfc_debug_enter();
644 /* Reset the timeout watchdog */
645 atomic_set(&dev->watchdog_cnt, 0);
646 ctx = dev->ctx[dev->curr_ctx];
647 /* Get the reason of interrupt and the error code */
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300648 reason = s5p_mfc_hw_call(dev->mfc_ops, get_int_reason, dev);
649 err = s5p_mfc_hw_call(dev->mfc_ops, get_int_err, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300650 mfc_debug(1, "Int reason: %d (err: %08x)\n", reason, err);
651 switch (reason) {
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300652 case S5P_MFC_R2H_CMD_ERR_RET:
Jonathan McCrohan39c1cb22013-10-20 21:34:01 -0300653 /* An error has occurred */
Kamil Debskiaf935742011-06-21 10:51:26 -0300654 if (ctx->state == MFCINST_RUNNING &&
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300655 s5p_mfc_hw_call(dev->mfc_ops, err_dec, err) >=
656 dev->warn_start)
Kamil Debskiaf935742011-06-21 10:51:26 -0300657 s5p_mfc_handle_frame(ctx, reason, err);
658 else
Kamil Debski7296e252012-12-21 05:32:59 -0300659 s5p_mfc_handle_error(dev, ctx, reason, err);
Kamil Debskiaf935742011-06-21 10:51:26 -0300660 clear_bit(0, &dev->enter_suspend);
661 break;
662
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300663 case S5P_MFC_R2H_CMD_SLICE_DONE_RET:
664 case S5P_MFC_R2H_CMD_FIELD_DONE_RET:
665 case S5P_MFC_R2H_CMD_FRAME_DONE_RET:
Kamil Debskiaf935742011-06-21 10:51:26 -0300666 if (ctx->c_ops->post_frame_start) {
667 if (ctx->c_ops->post_frame_start(ctx))
668 mfc_err("post_frame_start() failed\n");
Andrzej Hajda96c57772015-10-07 07:15:31 -0300669
670 if (ctx->state == MFCINST_FINISHING &&
671 list_empty(&ctx->ref_queue)) {
672 s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev);
673 s5p_mfc_handle_stream_complete(ctx);
674 break;
675 }
Kamil Debskie2c3be22014-09-11 10:27:20 -0300676 s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300677 wake_up_ctx(ctx, reason, err);
Pawel Osciak9a7bc6b2014-10-21 08:07:01 -0300678 WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
Kamil Debskiaf935742011-06-21 10:51:26 -0300679 s5p_mfc_clock_off();
Kamil Debskie2c3be22014-09-11 10:27:20 -0300680 s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300681 } else {
682 s5p_mfc_handle_frame(ctx, reason, err);
683 }
684 break;
685
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300686 case S5P_MFC_R2H_CMD_SEQ_DONE_RET:
Kamil Debskiaf935742011-06-21 10:51:26 -0300687 s5p_mfc_handle_seq_done(ctx, reason, err);
688 break;
689
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300690 case S5P_MFC_R2H_CMD_OPEN_INSTANCE_RET:
691 ctx->inst_no = s5p_mfc_hw_call(dev->mfc_ops, get_inst_no, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300692 ctx->state = MFCINST_GOT_INST;
693 clear_work_bit(ctx);
694 wake_up(&ctx->queue);
695 goto irq_cleanup_hw;
696
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300697 case S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET:
Kamil Debskiaf935742011-06-21 10:51:26 -0300698 clear_work_bit(ctx);
Pawel Osciak9d87e832014-05-19 09:33:00 -0300699 ctx->inst_no = MFC_NO_INSTANCE_SET;
Kamil Debskiaf935742011-06-21 10:51:26 -0300700 ctx->state = MFCINST_FREE;
701 wake_up(&ctx->queue);
702 goto irq_cleanup_hw;
703
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300704 case S5P_MFC_R2H_CMD_SYS_INIT_RET:
705 case S5P_MFC_R2H_CMD_FW_STATUS_RET:
706 case S5P_MFC_R2H_CMD_SLEEP_RET:
707 case S5P_MFC_R2H_CMD_WAKEUP_RET:
Kamil Debskiaf935742011-06-21 10:51:26 -0300708 if (ctx)
709 clear_work_bit(ctx);
Kamil Debskie2c3be22014-09-11 10:27:20 -0300710 s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300711 wake_up_dev(dev, reason, err);
712 clear_bit(0, &dev->hw_lock);
713 clear_bit(0, &dev->enter_suspend);
714 break;
715
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300716 case S5P_MFC_R2H_CMD_INIT_BUFFERS_RET:
Kamil Debskiaf935742011-06-21 10:51:26 -0300717 s5p_mfc_handle_init_buffers(ctx, reason, err);
718 break;
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300719
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300720 case S5P_MFC_R2H_CMD_COMPLETE_SEQ_RET:
Andrzej Hajda96c57772015-10-07 07:15:31 -0300721 s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev);
722 ctx->int_type = reason;
723 ctx->int_err = err;
724 s5p_mfc_handle_stream_complete(ctx);
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300725 break;
726
Arun Kumar K8f23cc02012-11-22 06:15:55 -0300727 case S5P_MFC_R2H_CMD_DPB_FLUSH_RET:
728 clear_work_bit(ctx);
729 ctx->state = MFCINST_RUNNING;
730 wake_up(&ctx->queue);
731 goto irq_cleanup_hw;
732
Kamil Debskiaf935742011-06-21 10:51:26 -0300733 default:
734 mfc_debug(2, "Unknown int reason\n");
Kamil Debskie2c3be22014-09-11 10:27:20 -0300735 s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300736 }
737 mfc_debug_leave();
738 return IRQ_HANDLED;
739irq_cleanup_hw:
Kamil Debskie2c3be22014-09-11 10:27:20 -0300740 s5p_mfc_hw_call_void(dev->mfc_ops, clear_int_flags, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300741 ctx->int_type = reason;
742 ctx->int_err = err;
743 ctx->int_cond = 1;
744 if (test_and_clear_bit(0, &dev->hw_lock) == 0)
745 mfc_err("Failed to unlock hw\n");
746
747 s5p_mfc_clock_off();
748
Kamil Debskie2c3be22014-09-11 10:27:20 -0300749 s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300750 mfc_debug(2, "Exit via irq_cleanup_hw\n");
751 return IRQ_HANDLED;
752}
753
754/* Open an MFC node */
755static int s5p_mfc_open(struct file *file)
756{
Marek Szyprowskib80cb8d2013-12-03 10:12:51 -0300757 struct video_device *vdev = video_devdata(file);
Kamil Debskiaf935742011-06-21 10:51:26 -0300758 struct s5p_mfc_dev *dev = video_drvdata(file);
759 struct s5p_mfc_ctx *ctx = NULL;
760 struct vb2_queue *q;
Kamil Debskiaf935742011-06-21 10:51:26 -0300761 int ret = 0;
762
763 mfc_debug_enter();
Hans Verkuilbc738302012-06-24 07:13:33 -0300764 if (mutex_lock_interruptible(&dev->mfc_mutex))
765 return -ERESTARTSYS;
Kamil Debskiaf935742011-06-21 10:51:26 -0300766 dev->num_inst++; /* It is guarded by mfc_mutex in vfd */
767 /* Allocate memory for context */
Sachin Kamatbae061b2012-08-17 03:22:55 -0300768 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
Kamil Debskiaf935742011-06-21 10:51:26 -0300769 if (!ctx) {
770 mfc_err("Not enough memory\n");
771 ret = -ENOMEM;
772 goto err_alloc;
773 }
Zhaowei Yuan55647a92014-07-23 01:06:12 -0300774 v4l2_fh_init(&ctx->fh, vdev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300775 file->private_data = &ctx->fh;
776 v4l2_fh_add(&ctx->fh);
777 ctx->dev = dev;
778 INIT_LIST_HEAD(&ctx->src_queue);
779 INIT_LIST_HEAD(&ctx->dst_queue);
780 ctx->src_queue_cnt = 0;
781 ctx->dst_queue_cnt = 0;
782 /* Get context number */
783 ctx->num = 0;
784 while (dev->ctx[ctx->num]) {
785 ctx->num++;
786 if (ctx->num >= MFC_NUM_CONTEXTS) {
787 mfc_err("Too many open contexts\n");
788 ret = -EBUSY;
789 goto err_no_ctx;
790 }
791 }
792 /* Mark context as idle */
Andrzej Hajda7fb89ec2012-08-14 06:13:40 -0300793 clear_work_bit_irqsave(ctx);
Kamil Debskiaf935742011-06-21 10:51:26 -0300794 dev->ctx[ctx->num] = ctx;
Marek Szyprowskib80cb8d2013-12-03 10:12:51 -0300795 if (vdev == dev->vfd_dec) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300796 ctx->type = MFCINST_DECODER;
797 ctx->c_ops = get_dec_codec_ops();
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300798 s5p_mfc_dec_init(ctx);
Kamil Debskiaf935742011-06-21 10:51:26 -0300799 /* Setup ctrl handler */
800 ret = s5p_mfc_dec_ctrls_setup(ctx);
801 if (ret) {
802 mfc_err("Failed to setup mfc controls\n");
803 goto err_ctrls_setup;
804 }
Marek Szyprowskib80cb8d2013-12-03 10:12:51 -0300805 } else if (vdev == dev->vfd_enc) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300806 ctx->type = MFCINST_ENCODER;
807 ctx->c_ops = get_enc_codec_ops();
808 /* only for encoder */
809 INIT_LIST_HEAD(&ctx->ref_queue);
810 ctx->ref_queue_cnt = 0;
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300811 s5p_mfc_enc_init(ctx);
Kamil Debskiaf935742011-06-21 10:51:26 -0300812 /* Setup ctrl handler */
813 ret = s5p_mfc_enc_ctrls_setup(ctx);
814 if (ret) {
815 mfc_err("Failed to setup mfc controls\n");
816 goto err_ctrls_setup;
817 }
818 } else {
819 ret = -ENOENT;
820 goto err_bad_node;
821 }
822 ctx->fh.ctrl_handler = &ctx->ctrl_handler;
Pawel Osciak9d87e832014-05-19 09:33:00 -0300823 ctx->inst_no = MFC_NO_INSTANCE_SET;
Kamil Debskiaf935742011-06-21 10:51:26 -0300824 /* Load firmware if this is the first instance */
825 if (dev->num_inst == 1) {
826 dev->watchdog_timer.expires = jiffies +
827 msecs_to_jiffies(MFC_WATCHDOG_INTERVAL);
828 add_timer(&dev->watchdog_timer);
829 ret = s5p_mfc_power_on();
830 if (ret < 0) {
831 mfc_err("power on failed\n");
832 goto err_pwr_enable;
833 }
834 s5p_mfc_clock_on();
Kamil Debski2e731e42013-01-03 11:02:07 -0300835 ret = s5p_mfc_load_firmware(dev);
836 if (ret) {
837 s5p_mfc_clock_off();
838 goto err_load_fw;
839 }
Kamil Debskiaf935742011-06-21 10:51:26 -0300840 /* Init the FW */
841 ret = s5p_mfc_init_hw(dev);
Kamil Debski2e731e42013-01-03 11:02:07 -0300842 s5p_mfc_clock_off();
Kamil Debskiaf935742011-06-21 10:51:26 -0300843 if (ret)
844 goto err_init_hw;
Kamil Debskiaf935742011-06-21 10:51:26 -0300845 }
846 /* Init videobuf2 queue for CAPTURE */
847 q = &ctx->vq_dst;
848 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
849 q->drv_priv = &ctx->fh;
Prabhakar Lad654a7312014-11-26 19:42:32 -0300850 q->lock = &dev->mfc_mutex;
Marek Szyprowskib80cb8d2013-12-03 10:12:51 -0300851 if (vdev == dev->vfd_dec) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300852 q->io_modes = VB2_MMAP;
853 q->ops = get_dec_queue_ops();
Marek Szyprowskib80cb8d2013-12-03 10:12:51 -0300854 } else if (vdev == dev->vfd_enc) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300855 q->io_modes = VB2_MMAP | VB2_USERPTR;
856 q->ops = get_enc_queue_ops();
857 } else {
858 ret = -ENOENT;
859 goto err_queue_init;
860 }
Rasmus Villemoes749ae712014-10-21 11:55:35 -0300861 q->mem_ops = &vb2_dma_contig_memops;
Sakari Ailusade48682014-02-25 19:12:19 -0300862 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
Kamil Debskiaf935742011-06-21 10:51:26 -0300863 ret = vb2_queue_init(q);
864 if (ret) {
865 mfc_err("Failed to initialize videobuf2 queue(capture)\n");
866 goto err_queue_init;
867 }
868 /* Init videobuf2 queue for OUTPUT */
869 q = &ctx->vq_src;
870 q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
871 q->io_modes = VB2_MMAP;
872 q->drv_priv = &ctx->fh;
Kamil Debski41f03a02015-03-03 11:32:58 -0300873 q->lock = &dev->mfc_mutex;
Marek Szyprowskib80cb8d2013-12-03 10:12:51 -0300874 if (vdev == dev->vfd_dec) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300875 q->io_modes = VB2_MMAP;
876 q->ops = get_dec_queue_ops();
Marek Szyprowskib80cb8d2013-12-03 10:12:51 -0300877 } else if (vdev == dev->vfd_enc) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300878 q->io_modes = VB2_MMAP | VB2_USERPTR;
879 q->ops = get_enc_queue_ops();
880 } else {
881 ret = -ENOENT;
882 goto err_queue_init;
883 }
Kamil Debskie6c9dec2015-02-23 09:26:19 -0300884 /* One way to indicate end-of-stream for MFC is to set the
885 * bytesused == 0. However by default videobuf2 handles bytesused
886 * equal to 0 as a special case and changes its value to the size
887 * of the buffer. Set the allow_zero_bytesused flag so that videobuf2
888 * will keep the value of bytesused intact.
889 */
890 q->allow_zero_bytesused = 1;
Rasmus Villemoes749ae712014-10-21 11:55:35 -0300891 q->mem_ops = &vb2_dma_contig_memops;
Sakari Ailusade48682014-02-25 19:12:19 -0300892 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
Kamil Debskiaf935742011-06-21 10:51:26 -0300893 ret = vb2_queue_init(q);
894 if (ret) {
895 mfc_err("Failed to initialize videobuf2 queue(output)\n");
896 goto err_queue_init;
897 }
898 init_waitqueue_head(&ctx->queue);
Hans Verkuilbc738302012-06-24 07:13:33 -0300899 mutex_unlock(&dev->mfc_mutex);
Kamil Debskiaf935742011-06-21 10:51:26 -0300900 mfc_debug_leave();
901 return ret;
Jonathan McCrohan39c1cb22013-10-20 21:34:01 -0300902 /* Deinit when failure occurred */
Kamil Debskiaf935742011-06-21 10:51:26 -0300903err_queue_init:
Kamil Debski2e731e42013-01-03 11:02:07 -0300904 if (dev->num_inst == 1)
905 s5p_mfc_deinit_hw(dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300906err_init_hw:
Kamil Debski2e731e42013-01-03 11:02:07 -0300907err_load_fw:
Kamil Debskiaf935742011-06-21 10:51:26 -0300908err_pwr_enable:
909 if (dev->num_inst == 1) {
910 if (s5p_mfc_power_off() < 0)
911 mfc_err("power off failed\n");
Kamil Debski1b73ba02012-11-22 10:00:28 -0300912 del_timer_sync(&dev->watchdog_timer);
Kamil Debskiaf935742011-06-21 10:51:26 -0300913 }
914err_ctrls_setup:
915 s5p_mfc_dec_ctrls_delete(ctx);
916err_bad_node:
Kamil Debski1b73ba02012-11-22 10:00:28 -0300917 dev->ctx[ctx->num] = NULL;
Kamil Debskiaf935742011-06-21 10:51:26 -0300918err_no_ctx:
919 v4l2_fh_del(&ctx->fh);
920 v4l2_fh_exit(&ctx->fh);
921 kfree(ctx);
922err_alloc:
923 dev->num_inst--;
Hans Verkuilbc738302012-06-24 07:13:33 -0300924 mutex_unlock(&dev->mfc_mutex);
Kamil Debskiaf935742011-06-21 10:51:26 -0300925 mfc_debug_leave();
926 return ret;
927}
928
929/* Release MFC context */
930static int s5p_mfc_release(struct file *file)
931{
932 struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data);
933 struct s5p_mfc_dev *dev = ctx->dev;
Kamil Debskiaf935742011-06-21 10:51:26 -0300934
935 mfc_debug_enter();
Hans Verkuilbc738302012-06-24 07:13:33 -0300936 mutex_lock(&dev->mfc_mutex);
Kamil Debskiaf935742011-06-21 10:51:26 -0300937 s5p_mfc_clock_on();
938 vb2_queue_release(&ctx->vq_src);
939 vb2_queue_release(&ctx->vq_dst);
940 /* Mark context as idle */
Andrzej Hajda7fb89ec2012-08-14 06:13:40 -0300941 clear_work_bit_irqsave(ctx);
Pawel Osciak9d87e832014-05-19 09:33:00 -0300942 /* If instance was initialised and not yet freed,
Jonathan McCrohan39c1cb22013-10-20 21:34:01 -0300943 * return instance and free resources */
Pawel Osciak9d87e832014-05-19 09:33:00 -0300944 if (ctx->state != MFCINST_FREE && ctx->state != MFCINST_INIT) {
Kamil Debskiaf935742011-06-21 10:51:26 -0300945 mfc_debug(2, "Has to free instance\n");
Pawel Osciak818cd912014-05-19 09:32:59 -0300946 s5p_mfc_close_mfc_inst(dev, ctx);
Kamil Debskiaf935742011-06-21 10:51:26 -0300947 }
948 /* hardware locking scheme */
949 if (dev->curr_ctx == ctx->num)
950 clear_bit(0, &dev->hw_lock);
951 dev->num_inst--;
952 if (dev->num_inst == 0) {
Kamil Debski2e731e42013-01-03 11:02:07 -0300953 mfc_debug(2, "Last instance\n");
Arun Kumar K43a1ea12012-10-03 22:19:08 -0300954 s5p_mfc_deinit_hw(dev);
Kamil Debskiaf935742011-06-21 10:51:26 -0300955 del_timer_sync(&dev->watchdog_timer);
956 if (s5p_mfc_power_off() < 0)
957 mfc_err("Power off failed\n");
958 }
959 mfc_debug(2, "Shutting down clock\n");
960 s5p_mfc_clock_off();
Sachin Kamat12597622012-05-10 03:32:00 -0300961 dev->ctx[ctx->num] = NULL;
Kamil Debskiaf935742011-06-21 10:51:26 -0300962 s5p_mfc_dec_ctrls_delete(ctx);
963 v4l2_fh_del(&ctx->fh);
964 v4l2_fh_exit(&ctx->fh);
965 kfree(ctx);
966 mfc_debug_leave();
Hans Verkuilbc738302012-06-24 07:13:33 -0300967 mutex_unlock(&dev->mfc_mutex);
Kamil Debskiaf935742011-06-21 10:51:26 -0300968 return 0;
969}
970
971/* Poll */
972static unsigned int s5p_mfc_poll(struct file *file,
973 struct poll_table_struct *wait)
974{
975 struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data);
976 struct s5p_mfc_dev *dev = ctx->dev;
977 struct vb2_queue *src_q, *dst_q;
978 struct vb2_buffer *src_vb = NULL, *dst_vb = NULL;
979 unsigned int rc = 0;
980 unsigned long flags;
981
Hans Verkuilbc738302012-06-24 07:13:33 -0300982 mutex_lock(&dev->mfc_mutex);
Kamil Debskiaf935742011-06-21 10:51:26 -0300983 src_q = &ctx->vq_src;
984 dst_q = &ctx->vq_dst;
985 /*
986 * There has to be at least one buffer queued on each queued_list, which
987 * means either in driver already or waiting for driver to claim it
988 * and start processing.
989 */
990 if ((!src_q->streaming || list_empty(&src_q->queued_list))
991 && (!dst_q->streaming || list_empty(&dst_q->queued_list))) {
992 rc = POLLERR;
993 goto end;
994 }
995 mutex_unlock(&dev->mfc_mutex);
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -0300996 poll_wait(file, &ctx->fh.wait, wait);
Kamil Debskiaf935742011-06-21 10:51:26 -0300997 poll_wait(file, &src_q->done_wq, wait);
998 poll_wait(file, &dst_q->done_wq, wait);
999 mutex_lock(&dev->mfc_mutex);
Andrzej Hajdaf9f715a2012-08-21 08:05:32 -03001000 if (v4l2_event_pending(&ctx->fh))
1001 rc |= POLLPRI;
Kamil Debskiaf935742011-06-21 10:51:26 -03001002 spin_lock_irqsave(&src_q->done_lock, flags);
1003 if (!list_empty(&src_q->done_list))
1004 src_vb = list_first_entry(&src_q->done_list, struct vb2_buffer,
1005 done_entry);
1006 if (src_vb && (src_vb->state == VB2_BUF_STATE_DONE
1007 || src_vb->state == VB2_BUF_STATE_ERROR))
1008 rc |= POLLOUT | POLLWRNORM;
1009 spin_unlock_irqrestore(&src_q->done_lock, flags);
1010 spin_lock_irqsave(&dst_q->done_lock, flags);
1011 if (!list_empty(&dst_q->done_list))
1012 dst_vb = list_first_entry(&dst_q->done_list, struct vb2_buffer,
1013 done_entry);
1014 if (dst_vb && (dst_vb->state == VB2_BUF_STATE_DONE
1015 || dst_vb->state == VB2_BUF_STATE_ERROR))
1016 rc |= POLLIN | POLLRDNORM;
1017 spin_unlock_irqrestore(&dst_q->done_lock, flags);
1018end:
Hans Verkuilbc738302012-06-24 07:13:33 -03001019 mutex_unlock(&dev->mfc_mutex);
Kamil Debskiaf935742011-06-21 10:51:26 -03001020 return rc;
1021}
1022
1023/* Mmap */
1024static int s5p_mfc_mmap(struct file *file, struct vm_area_struct *vma)
1025{
1026 struct s5p_mfc_ctx *ctx = fh_to_ctx(file->private_data);
Hans Verkuilbc738302012-06-24 07:13:33 -03001027 struct s5p_mfc_dev *dev = ctx->dev;
Kamil Debskiaf935742011-06-21 10:51:26 -03001028 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
1029 int ret;
Hans Verkuilbc738302012-06-24 07:13:33 -03001030
1031 if (mutex_lock_interruptible(&dev->mfc_mutex))
1032 return -ERESTARTSYS;
Kamil Debskiaf935742011-06-21 10:51:26 -03001033 if (offset < DST_QUEUE_OFF_BASE) {
1034 mfc_debug(2, "mmaping source\n");
1035 ret = vb2_mmap(&ctx->vq_src, vma);
1036 } else { /* capture */
1037 mfc_debug(2, "mmaping destination\n");
1038 vma->vm_pgoff -= (DST_QUEUE_OFF_BASE >> PAGE_SHIFT);
1039 ret = vb2_mmap(&ctx->vq_dst, vma);
1040 }
Hans Verkuilbc738302012-06-24 07:13:33 -03001041 mutex_unlock(&dev->mfc_mutex);
Kamil Debskiaf935742011-06-21 10:51:26 -03001042 return ret;
1043}
1044
1045/* v4l2 ops */
1046static const struct v4l2_file_operations s5p_mfc_fops = {
1047 .owner = THIS_MODULE,
1048 .open = s5p_mfc_open,
1049 .release = s5p_mfc_release,
1050 .poll = s5p_mfc_poll,
1051 .unlocked_ioctl = video_ioctl2,
1052 .mmap = s5p_mfc_mmap,
1053};
1054
1055static int match_child(struct device *dev, void *data)
1056{
1057 if (!dev_name(dev))
1058 return 0;
1059 return !strcmp(dev_name(dev), (char *)data);
1060}
1061
Arun Kumar Kb27a23b2012-10-25 05:24:14 -03001062static void *mfc_get_drv_data(struct platform_device *pdev);
1063
Arun Kumar K6e83e6e2013-01-18 15:42:34 -03001064static int s5p_mfc_alloc_memdevs(struct s5p_mfc_dev *dev)
1065{
Sylwester Nawrocki65fccab2013-04-10 07:17:52 -03001066 unsigned int mem_info[2] = { };
Arun Kumar K6e83e6e2013-01-18 15:42:34 -03001067
1068 dev->mem_dev_l = devm_kzalloc(&dev->plat_dev->dev,
1069 sizeof(struct device), GFP_KERNEL);
1070 if (!dev->mem_dev_l) {
1071 mfc_err("Not enough memory\n");
1072 return -ENOMEM;
1073 }
1074 device_initialize(dev->mem_dev_l);
1075 of_property_read_u32_array(dev->plat_dev->dev.of_node,
1076 "samsung,mfc-l", mem_info, 2);
1077 if (dma_declare_coherent_memory(dev->mem_dev_l, mem_info[0],
1078 mem_info[0], mem_info[1],
1079 DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE) == 0) {
1080 mfc_err("Failed to declare coherent memory for\n"
1081 "MFC device\n");
1082 return -ENOMEM;
1083 }
1084
1085 dev->mem_dev_r = devm_kzalloc(&dev->plat_dev->dev,
1086 sizeof(struct device), GFP_KERNEL);
1087 if (!dev->mem_dev_r) {
1088 mfc_err("Not enough memory\n");
1089 return -ENOMEM;
1090 }
1091 device_initialize(dev->mem_dev_r);
1092 of_property_read_u32_array(dev->plat_dev->dev.of_node,
1093 "samsung,mfc-r", mem_info, 2);
1094 if (dma_declare_coherent_memory(dev->mem_dev_r, mem_info[0],
1095 mem_info[0], mem_info[1],
1096 DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE) == 0) {
1097 pr_err("Failed to declare coherent memory for\n"
1098 "MFC device\n");
1099 return -ENOMEM;
1100 }
1101 return 0;
1102}
1103
Kamil Debskiaf935742011-06-21 10:51:26 -03001104/* MFC probe function */
Kamil Debski1e393e92011-08-08 13:12:51 -03001105static int s5p_mfc_probe(struct platform_device *pdev)
Kamil Debskiaf935742011-06-21 10:51:26 -03001106{
1107 struct s5p_mfc_dev *dev;
1108 struct video_device *vfd;
1109 struct resource *res;
1110 int ret;
1111
1112 pr_debug("%s++\n", __func__);
Sachin Kamatbae061b2012-08-17 03:22:55 -03001113 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
Kamil Debskiaf935742011-06-21 10:51:26 -03001114 if (!dev) {
1115 dev_err(&pdev->dev, "Not enough memory for MFC device\n");
1116 return -ENOMEM;
1117 }
1118
1119 spin_lock_init(&dev->irqlock);
1120 spin_lock_init(&dev->condlock);
1121 dev->plat_dev = pdev;
1122 if (!dev->plat_dev) {
1123 dev_err(&pdev->dev, "No platform data specified\n");
Sachin Kamatd310f472012-05-14 08:22:27 -03001124 return -ENODEV;
Kamil Debskiaf935742011-06-21 10:51:26 -03001125 }
1126
Arun Kumar Kb27a23b2012-10-25 05:24:14 -03001127 dev->variant = mfc_get_drv_data(pdev);
Arun Kumar K8f532a72012-10-03 22:19:09 -03001128
Kamil Debskiaf935742011-06-21 10:51:26 -03001129 ret = s5p_mfc_init_pm(dev);
1130 if (ret < 0) {
1131 dev_err(&pdev->dev, "failed to get mfc clock source\n");
Sachin Kamatd310f472012-05-14 08:22:27 -03001132 return ret;
Kamil Debskiaf935742011-06-21 10:51:26 -03001133 }
1134
1135 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Kamil Debskiaf935742011-06-21 10:51:26 -03001136
Thierry Redingf23999e2013-01-21 06:09:07 -03001137 dev->regs_base = devm_ioremap_resource(&pdev->dev, res);
1138 if (IS_ERR(dev->regs_base))
1139 return PTR_ERR(dev->regs_base);
Kamil Debskiaf935742011-06-21 10:51:26 -03001140
1141 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1142 if (res == NULL) {
1143 dev_err(&pdev->dev, "failed to get irq resource\n");
1144 ret = -ENOENT;
Sachin Kamatd310f472012-05-14 08:22:27 -03001145 goto err_res;
Kamil Debskiaf935742011-06-21 10:51:26 -03001146 }
1147 dev->irq = res->start;
Sachin Kamatd310f472012-05-14 08:22:27 -03001148 ret = devm_request_irq(&pdev->dev, dev->irq, s5p_mfc_irq,
Michael Opdenacker1957f0d2013-10-13 02:58:39 -03001149 0, pdev->name, dev);
Kamil Debskiaf935742011-06-21 10:51:26 -03001150 if (ret) {
1151 dev_err(&pdev->dev, "Failed to install irq (%d)\n", ret);
Sachin Kamatd310f472012-05-14 08:22:27 -03001152 goto err_res;
Kamil Debskiaf935742011-06-21 10:51:26 -03001153 }
1154
Arun Kumar Kb27a23b2012-10-25 05:24:14 -03001155 if (pdev->dev.of_node) {
Wei Yongjund68b44e2013-04-17 23:18:19 -03001156 ret = s5p_mfc_alloc_memdevs(dev);
1157 if (ret < 0)
Arun Kumar Kb27a23b2012-10-25 05:24:14 -03001158 goto err_res;
Arun Kumar Kb27a23b2012-10-25 05:24:14 -03001159 } else {
1160 dev->mem_dev_l = device_find_child(&dev->plat_dev->dev,
1161 "s5p-mfc-l", match_child);
1162 if (!dev->mem_dev_l) {
1163 mfc_err("Mem child (L) device get failed\n");
1164 ret = -ENODEV;
1165 goto err_res;
1166 }
1167 dev->mem_dev_r = device_find_child(&dev->plat_dev->dev,
1168 "s5p-mfc-r", match_child);
1169 if (!dev->mem_dev_r) {
1170 mfc_err("Mem child (R) device get failed\n");
1171 ret = -ENODEV;
1172 goto err_res;
1173 }
Kamil Debskiaf935742011-06-21 10:51:26 -03001174 }
1175
1176 dev->alloc_ctx[0] = vb2_dma_contig_init_ctx(dev->mem_dev_l);
Kamil Debskief89fff2013-01-03 07:06:03 -03001177 if (IS_ERR(dev->alloc_ctx[0])) {
Kamil Debskiaf935742011-06-21 10:51:26 -03001178 ret = PTR_ERR(dev->alloc_ctx[0]);
Sachin Kamatd310f472012-05-14 08:22:27 -03001179 goto err_res;
Kamil Debskiaf935742011-06-21 10:51:26 -03001180 }
1181 dev->alloc_ctx[1] = vb2_dma_contig_init_ctx(dev->mem_dev_r);
Kamil Debskief89fff2013-01-03 07:06:03 -03001182 if (IS_ERR(dev->alloc_ctx[1])) {
Kamil Debskiaf935742011-06-21 10:51:26 -03001183 ret = PTR_ERR(dev->alloc_ctx[1]);
1184 goto err_mem_init_ctx_1;
1185 }
1186
1187 mutex_init(&dev->mfc_mutex);
1188
Kamil Debski2e731e42013-01-03 11:02:07 -03001189 ret = s5p_mfc_alloc_firmware(dev);
1190 if (ret)
1191 goto err_alloc_fw;
1192
Kamil Debskiaf935742011-06-21 10:51:26 -03001193 ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
1194 if (ret)
1195 goto err_v4l2_dev_reg;
1196 init_waitqueue_head(&dev->queue);
1197
1198 /* decoder */
1199 vfd = video_device_alloc();
1200 if (!vfd) {
1201 v4l2_err(&dev->v4l2_dev, "Failed to allocate video device\n");
1202 ret = -ENOMEM;
1203 goto err_dec_alloc;
1204 }
Joonyoung Shimd0ce8982014-02-20 23:22:12 -03001205 vfd->fops = &s5p_mfc_fops;
Kamil Debskiaf935742011-06-21 10:51:26 -03001206 vfd->ioctl_ops = get_dec_v4l2_ioctl_ops();
Joonyoung Shimd0ce8982014-02-20 23:22:12 -03001207 vfd->release = video_device_release;
Kamil Debskiaf935742011-06-21 10:51:26 -03001208 vfd->lock = &dev->mfc_mutex;
1209 vfd->v4l2_dev = &dev->v4l2_dev;
Hans Verkuil954f3402012-09-05 06:05:50 -03001210 vfd->vfl_dir = VFL_DIR_M2M;
Kamil Debskiaf935742011-06-21 10:51:26 -03001211 snprintf(vfd->name, sizeof(vfd->name), "%s", S5P_MFC_DEC_NAME);
1212 dev->vfd_dec = vfd;
1213 ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
1214 if (ret) {
1215 v4l2_err(&dev->v4l2_dev, "Failed to register video device\n");
1216 video_device_release(vfd);
1217 goto err_dec_reg;
1218 }
1219 v4l2_info(&dev->v4l2_dev,
1220 "decoder registered as /dev/video%d\n", vfd->num);
1221 video_set_drvdata(vfd, dev);
1222
1223 /* encoder */
1224 vfd = video_device_alloc();
1225 if (!vfd) {
1226 v4l2_err(&dev->v4l2_dev, "Failed to allocate video device\n");
1227 ret = -ENOMEM;
1228 goto err_enc_alloc;
1229 }
Joonyoung Shimd0ce8982014-02-20 23:22:12 -03001230 vfd->fops = &s5p_mfc_fops;
Kamil Debskiaf935742011-06-21 10:51:26 -03001231 vfd->ioctl_ops = get_enc_v4l2_ioctl_ops();
Joonyoung Shimd0ce8982014-02-20 23:22:12 -03001232 vfd->release = video_device_release;
Kamil Debskiaf935742011-06-21 10:51:26 -03001233 vfd->lock = &dev->mfc_mutex;
1234 vfd->v4l2_dev = &dev->v4l2_dev;
Arun Kumar Kcdcf45e2012-10-04 16:14:56 -03001235 vfd->vfl_dir = VFL_DIR_M2M;
Kamil Debskiaf935742011-06-21 10:51:26 -03001236 snprintf(vfd->name, sizeof(vfd->name), "%s", S5P_MFC_ENC_NAME);
1237 dev->vfd_enc = vfd;
1238 ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
1239 if (ret) {
1240 v4l2_err(&dev->v4l2_dev, "Failed to register video device\n");
1241 video_device_release(vfd);
1242 goto err_enc_reg;
1243 }
1244 v4l2_info(&dev->v4l2_dev,
1245 "encoder registered as /dev/video%d\n", vfd->num);
1246 video_set_drvdata(vfd, dev);
1247 platform_set_drvdata(pdev, dev);
1248
1249 dev->hw_lock = 0;
1250 dev->watchdog_workqueue = create_singlethread_workqueue(S5P_MFC_NAME);
1251 INIT_WORK(&dev->watchdog_work, s5p_mfc_watchdog_worker);
1252 atomic_set(&dev->watchdog_cnt, 0);
1253 init_timer(&dev->watchdog_timer);
1254 dev->watchdog_timer.data = (unsigned long)dev;
1255 dev->watchdog_timer.function = s5p_mfc_watchdog;
1256
Arun Kumar 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
Kamil Debskiaf935742011-06-21 10:51:26 -03001262 pr_debug("%s--\n", __func__);
1263 return 0;
1264
1265/* Deinit MFC if probe had failed */
1266err_enc_reg:
1267 video_device_release(dev->vfd_enc);
1268err_enc_alloc:
1269 video_unregister_device(dev->vfd_dec);
1270err_dec_reg:
1271 video_device_release(dev->vfd_dec);
1272err_dec_alloc:
1273 v4l2_device_unregister(&dev->v4l2_dev);
1274err_v4l2_dev_reg:
Kamil Debski2e731e42013-01-03 11:02:07 -03001275 s5p_mfc_release_firmware(dev);
1276err_alloc_fw:
Kamil Debskiaf935742011-06-21 10:51:26 -03001277 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[1]);
1278err_mem_init_ctx_1:
1279 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[0]);
Kamil Debskiaf935742011-06-21 10:51:26 -03001280err_res:
1281 s5p_mfc_final_pm(dev);
Sachin Kamatd310f472012-05-14 08:22:27 -03001282
Kamil Debskiaf935742011-06-21 10:51:26 -03001283 pr_debug("%s-- with error\n", __func__);
1284 return ret;
1285
1286}
1287
1288/* Remove the driver */
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001289static int s5p_mfc_remove(struct platform_device *pdev)
Kamil Debskiaf935742011-06-21 10:51:26 -03001290{
1291 struct s5p_mfc_dev *dev = platform_get_drvdata(pdev);
1292
1293 v4l2_info(&dev->v4l2_dev, "Removing %s\n", pdev->name);
1294
1295 del_timer_sync(&dev->watchdog_timer);
1296 flush_workqueue(dev->watchdog_workqueue);
1297 destroy_workqueue(dev->watchdog_workqueue);
1298
1299 video_unregister_device(dev->vfd_enc);
1300 video_unregister_device(dev->vfd_dec);
1301 v4l2_device_unregister(&dev->v4l2_dev);
Kamil Debski2e731e42013-01-03 11:02:07 -03001302 s5p_mfc_release_firmware(dev);
Kamil Debskiaf935742011-06-21 10:51:26 -03001303 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[0]);
1304 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[1]);
Arun Kumar K6e83e6e2013-01-18 15:42:34 -03001305 if (pdev->dev.of_node) {
1306 put_device(dev->mem_dev_l);
1307 put_device(dev->mem_dev_r);
1308 }
Kamil Debskiaf935742011-06-21 10:51:26 -03001309
Kamil Debskiaf935742011-06-21 10:51:26 -03001310 s5p_mfc_final_pm(dev);
Kamil Debskiaf935742011-06-21 10:51:26 -03001311 return 0;
1312}
1313
1314#ifdef CONFIG_PM_SLEEP
1315
1316static int s5p_mfc_suspend(struct device *dev)
1317{
1318 struct platform_device *pdev = to_platform_device(dev);
1319 struct s5p_mfc_dev *m_dev = platform_get_drvdata(pdev);
1320 int ret;
1321
1322 if (m_dev->num_inst == 0)
1323 return 0;
Sachin Kamat81c9bcf2012-09-28 04:01:35 -03001324
Kamil Debskiaf935742011-06-21 10:51:26 -03001325 if (test_and_set_bit(0, &m_dev->enter_suspend) != 0) {
1326 mfc_err("Error: going to suspend for a second time\n");
1327 return -EIO;
1328 }
1329
1330 /* Check if we're processing then wait if it necessary. */
1331 while (test_and_set_bit(0, &m_dev->hw_lock) != 0) {
1332 /* Try and lock the HW */
1333 /* Wait on the interrupt waitqueue */
1334 ret = wait_event_interruptible_timeout(m_dev->queue,
Prathyush K76a4ddb2013-10-04 01:47:19 -03001335 m_dev->int_cond, msecs_to_jiffies(MFC_INT_TIMEOUT));
Kamil Debskiaf935742011-06-21 10:51:26 -03001336 if (ret == 0) {
1337 mfc_err("Waiting for hardware to finish timed out\n");
Prathyush K64370992014-10-21 08:06:57 -03001338 clear_bit(0, &m_dev->enter_suspend);
Kamil Debskiaf935742011-06-21 10:51:26 -03001339 return -EIO;
1340 }
1341 }
Sachin Kamat81c9bcf2012-09-28 04:01:35 -03001342
Prathyush K64370992014-10-21 08:06:57 -03001343 ret = s5p_mfc_sleep(m_dev);
1344 if (ret) {
1345 clear_bit(0, &m_dev->enter_suspend);
1346 clear_bit(0, &m_dev->hw_lock);
1347 }
1348 return ret;
Kamil Debskiaf935742011-06-21 10:51:26 -03001349}
1350
1351static int s5p_mfc_resume(struct device *dev)
1352{
1353 struct platform_device *pdev = to_platform_device(dev);
1354 struct s5p_mfc_dev *m_dev = platform_get_drvdata(pdev);
1355
1356 if (m_dev->num_inst == 0)
1357 return 0;
1358 return s5p_mfc_wakeup(m_dev);
1359}
1360#endif
1361
Rafael J. Wysockie243c7c2014-12-04 01:10:10 +01001362#ifdef CONFIG_PM
Kamil Debskiaf935742011-06-21 10:51:26 -03001363static int s5p_mfc_runtime_suspend(struct device *dev)
1364{
1365 struct platform_device *pdev = to_platform_device(dev);
1366 struct s5p_mfc_dev *m_dev = platform_get_drvdata(pdev);
1367
1368 atomic_set(&m_dev->pm.power, 0);
1369 return 0;
1370}
1371
1372static int s5p_mfc_runtime_resume(struct device *dev)
1373{
1374 struct platform_device *pdev = to_platform_device(dev);
1375 struct s5p_mfc_dev *m_dev = platform_get_drvdata(pdev);
Kamil Debskiaf935742011-06-21 10:51:26 -03001376
Kamil Debskiaf935742011-06-21 10:51:26 -03001377 atomic_set(&m_dev->pm.power, 1);
1378 return 0;
1379}
1380#endif
1381
1382/* Power management */
1383static const struct dev_pm_ops s5p_mfc_pm_ops = {
1384 SET_SYSTEM_SLEEP_PM_OPS(s5p_mfc_suspend, s5p_mfc_resume)
1385 SET_RUNTIME_PM_OPS(s5p_mfc_runtime_suspend, s5p_mfc_runtime_resume,
1386 NULL)
1387};
1388
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001389static struct s5p_mfc_buf_size_v5 mfc_buf_size_v5 = {
Arun Kumar K8f532a72012-10-03 22:19:09 -03001390 .h264_ctx = MFC_H264_CTX_BUF_SIZE,
1391 .non_h264_ctx = MFC_CTX_BUF_SIZE,
1392 .dsc = DESC_BUF_SIZE,
1393 .shm = SHARED_BUF_SIZE,
1394};
1395
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001396static struct s5p_mfc_buf_size buf_size_v5 = {
Arun Kumar K8f532a72012-10-03 22:19:09 -03001397 .fw = MAX_FW_SIZE,
1398 .cpb = MAX_CPB_SIZE,
1399 .priv = &mfc_buf_size_v5,
1400};
1401
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001402static struct s5p_mfc_buf_align mfc_buf_align_v5 = {
Arun Kumar K8f532a72012-10-03 22:19:09 -03001403 .base = MFC_BASE_ALIGN_ORDER,
1404};
1405
1406static struct s5p_mfc_variant mfc_drvdata_v5 = {
1407 .version = MFC_VERSION,
Kamil Debski9aa5f002014-05-20 10:15:13 -03001408 .version_bit = MFC_V5_BIT,
Arun Kumar K8f532a72012-10-03 22:19:09 -03001409 .port_num = MFC_NUM_PORTS,
1410 .buf_size = &buf_size_v5,
1411 .buf_align = &mfc_buf_align_v5,
Arun Kumar K77ba6b72014-05-21 06:29:30 -03001412 .fw_name[0] = "s5p-mfc.fw",
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -03001413};
1414
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001415static struct s5p_mfc_buf_size_v6 mfc_buf_size_v6 = {
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -03001416 .dev_ctx = MFC_CTX_BUF_SIZE_V6,
1417 .h264_dec_ctx = MFC_H264_DEC_CTX_BUF_SIZE_V6,
1418 .other_dec_ctx = MFC_OTHER_DEC_CTX_BUF_SIZE_V6,
1419 .h264_enc_ctx = MFC_H264_ENC_CTX_BUF_SIZE_V6,
1420 .other_enc_ctx = MFC_OTHER_ENC_CTX_BUF_SIZE_V6,
1421};
1422
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001423static struct s5p_mfc_buf_size buf_size_v6 = {
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -03001424 .fw = MAX_FW_SIZE_V6,
1425 .cpb = MAX_CPB_SIZE_V6,
1426 .priv = &mfc_buf_size_v6,
1427};
1428
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001429static struct s5p_mfc_buf_align mfc_buf_align_v6 = {
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -03001430 .base = 0,
1431};
1432
1433static struct s5p_mfc_variant mfc_drvdata_v6 = {
1434 .version = MFC_VERSION_V6,
Kamil Debski9aa5f002014-05-20 10:15:13 -03001435 .version_bit = MFC_V6_BIT,
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -03001436 .port_num = MFC_NUM_PORTS_V6,
1437 .buf_size = &buf_size_v6,
1438 .buf_align = &mfc_buf_align_v6,
Arun Kumar K77ba6b72014-05-21 06:29:30 -03001439 .fw_name[0] = "s5p-mfc-v6.fw",
1440 /*
1441 * v6-v2 firmware contains bug fixes and interface change
1442 * for init buffer command
1443 */
1444 .fw_name[1] = "s5p-mfc-v6-v2.fw",
Arun Kumar K8f532a72012-10-03 22:19:09 -03001445};
1446
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001447static struct s5p_mfc_buf_size_v6 mfc_buf_size_v7 = {
Arun Kumar K5441e9d2013-07-09 01:24:38 -03001448 .dev_ctx = MFC_CTX_BUF_SIZE_V7,
1449 .h264_dec_ctx = MFC_H264_DEC_CTX_BUF_SIZE_V7,
1450 .other_dec_ctx = MFC_OTHER_DEC_CTX_BUF_SIZE_V7,
1451 .h264_enc_ctx = MFC_H264_ENC_CTX_BUF_SIZE_V7,
1452 .other_enc_ctx = MFC_OTHER_ENC_CTX_BUF_SIZE_V7,
1453};
1454
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001455static struct s5p_mfc_buf_size buf_size_v7 = {
Arun Kumar K5441e9d2013-07-09 01:24:38 -03001456 .fw = MAX_FW_SIZE_V7,
1457 .cpb = MAX_CPB_SIZE_V7,
1458 .priv = &mfc_buf_size_v7,
1459};
1460
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001461static struct s5p_mfc_buf_align mfc_buf_align_v7 = {
Arun Kumar K5441e9d2013-07-09 01:24:38 -03001462 .base = 0,
1463};
1464
1465static struct s5p_mfc_variant mfc_drvdata_v7 = {
1466 .version = MFC_VERSION_V7,
Kamil Debski9aa5f002014-05-20 10:15:13 -03001467 .version_bit = MFC_V7_BIT,
Arun Kumar K5441e9d2013-07-09 01:24:38 -03001468 .port_num = MFC_NUM_PORTS_V7,
1469 .buf_size = &buf_size_v7,
1470 .buf_align = &mfc_buf_align_v7,
Arun Kumar K77ba6b72014-05-21 06:29:30 -03001471 .fw_name[0] = "s5p-mfc-v7.fw",
Arun Kumar K5441e9d2013-07-09 01:24:38 -03001472};
1473
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001474static struct s5p_mfc_buf_size_v6 mfc_buf_size_v8 = {
Kiran AVNDe2b9deb2014-05-19 09:50:01 -03001475 .dev_ctx = MFC_CTX_BUF_SIZE_V8,
1476 .h264_dec_ctx = MFC_H264_DEC_CTX_BUF_SIZE_V8,
1477 .other_dec_ctx = MFC_OTHER_DEC_CTX_BUF_SIZE_V8,
Kiran AVND3e594ce72014-05-19 09:50:02 -03001478 .h264_enc_ctx = MFC_H264_ENC_CTX_BUF_SIZE_V8,
1479 .other_enc_ctx = MFC_OTHER_ENC_CTX_BUF_SIZE_V8,
Kiran AVNDe2b9deb2014-05-19 09:50:01 -03001480};
1481
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001482static struct s5p_mfc_buf_size buf_size_v8 = {
Kiran AVNDe2b9deb2014-05-19 09:50:01 -03001483 .fw = MAX_FW_SIZE_V8,
1484 .cpb = MAX_CPB_SIZE_V8,
1485 .priv = &mfc_buf_size_v8,
1486};
1487
Mauro Carvalho Chehabca5ea0c2014-09-24 09:08:10 -03001488static struct s5p_mfc_buf_align mfc_buf_align_v8 = {
Kiran AVNDe2b9deb2014-05-19 09:50:01 -03001489 .base = 0,
1490};
1491
1492static struct s5p_mfc_variant mfc_drvdata_v8 = {
1493 .version = MFC_VERSION_V8,
1494 .version_bit = MFC_V8_BIT,
1495 .port_num = MFC_NUM_PORTS_V8,
1496 .buf_size = &buf_size_v8,
1497 .buf_align = &mfc_buf_align_v8,
Arun Kumar K77ba6b72014-05-21 06:29:30 -03001498 .fw_name[0] = "s5p-mfc-v8.fw",
Kiran AVNDe2b9deb2014-05-19 09:50:01 -03001499};
1500
Krzysztof Kozlowski6425f642015-05-01 12:51:03 -03001501static const struct platform_device_id mfc_driver_ids[] = {
Arun Kumar K8f532a72012-10-03 22:19:09 -03001502 {
1503 .name = "s5p-mfc",
1504 .driver_data = (unsigned long)&mfc_drvdata_v5,
Jeongtae Parkf96f3cf2012-10-03 22:19:11 -03001505 }, {
1506 .name = "s5p-mfc-v5",
1507 .driver_data = (unsigned long)&mfc_drvdata_v5,
1508 }, {
1509 .name = "s5p-mfc-v6",
1510 .driver_data = (unsigned long)&mfc_drvdata_v6,
Arun Kumar K5441e9d2013-07-09 01:24:38 -03001511 }, {
1512 .name = "s5p-mfc-v7",
1513 .driver_data = (unsigned long)&mfc_drvdata_v7,
Kiran AVNDe2b9deb2014-05-19 09:50:01 -03001514 }, {
1515 .name = "s5p-mfc-v8",
1516 .driver_data = (unsigned long)&mfc_drvdata_v8,
Arun Kumar K8f532a72012-10-03 22:19:09 -03001517 },
1518 {},
1519};
1520MODULE_DEVICE_TABLE(platform, mfc_driver_ids);
1521
Arun Kumar Kb27a23b2012-10-25 05:24:14 -03001522static const struct of_device_id exynos_mfc_match[] = {
1523 {
1524 .compatible = "samsung,mfc-v5",
1525 .data = &mfc_drvdata_v5,
1526 }, {
1527 .compatible = "samsung,mfc-v6",
1528 .data = &mfc_drvdata_v6,
Arun Kumar K5441e9d2013-07-09 01:24:38 -03001529 }, {
1530 .compatible = "samsung,mfc-v7",
1531 .data = &mfc_drvdata_v7,
Kiran AVNDe2b9deb2014-05-19 09:50:01 -03001532 }, {
1533 .compatible = "samsung,mfc-v8",
1534 .data = &mfc_drvdata_v8,
Arun Kumar Kb27a23b2012-10-25 05:24:14 -03001535 },
1536 {},
1537};
1538MODULE_DEVICE_TABLE(of, exynos_mfc_match);
1539
1540static void *mfc_get_drv_data(struct platform_device *pdev)
1541{
1542 struct s5p_mfc_variant *driver_data = NULL;
1543
1544 if (pdev->dev.of_node) {
1545 const struct of_device_id *match;
Sachin Kamata40a1382013-05-23 00:51:19 -03001546 match = of_match_node(exynos_mfc_match,
Arun Kumar Kb27a23b2012-10-25 05:24:14 -03001547 pdev->dev.of_node);
1548 if (match)
1549 driver_data = (struct s5p_mfc_variant *)match->data;
1550 } else {
1551 driver_data = (struct s5p_mfc_variant *)
1552 platform_get_device_id(pdev)->driver_data;
1553 }
1554 return driver_data;
1555}
1556
Kamil Debski1e393e92011-08-08 13:12:51 -03001557static struct platform_driver s5p_mfc_driver = {
Arun Kumar K8f532a72012-10-03 22:19:09 -03001558 .probe = s5p_mfc_probe,
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001559 .remove = s5p_mfc_remove,
Arun Kumar K8f532a72012-10-03 22:19:09 -03001560 .id_table = mfc_driver_ids,
Kamil Debskiaf935742011-06-21 10:51:26 -03001561 .driver = {
1562 .name = S5P_MFC_NAME,
Arun Kumar Kb27a23b2012-10-25 05:24:14 -03001563 .pm = &s5p_mfc_pm_ops,
1564 .of_match_table = exynos_mfc_match,
Kamil Debskiaf935742011-06-21 10:51:26 -03001565 },
1566};
1567
Axel Lin1d6629b2012-01-10 03:21:49 -03001568module_platform_driver(s5p_mfc_driver);
Kamil Debskiaf935742011-06-21 10:51:26 -03001569
1570MODULE_LICENSE("GPL");
1571MODULE_AUTHOR("Kamil Debski <k.debski@samsung.com>");
1572MODULE_DESCRIPTION("Samsung S5P Multi Format Codec V4L2 driver");
1573