s5p_mfc.c 43 KB

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