s5p_mfc.c 42 KB

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