fimc-core.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842
  1. /*
  2. * S5P camera interface (video postprocessor) driver
  3. *
  4. * Copyright (c) 2010 Samsung Electronics Co., Ltd
  5. *
  6. * Sylwester Nawrocki, <s.nawrocki@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published
  10. * by the Free Software Foundation, either version 2 of the License,
  11. * or (at your option) any later version.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/version.h>
  16. #include <linux/types.h>
  17. #include <linux/errno.h>
  18. #include <linux/bug.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/device.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/list.h>
  23. #include <linux/io.h>
  24. #include <linux/slab.h>
  25. #include <linux/clk.h>
  26. #include <media/v4l2-ioctl.h>
  27. #include <media/videobuf2-core.h>
  28. #include <media/videobuf2-dma-contig.h>
  29. #include "fimc-core.h"
  30. static char *fimc_clock_name[NUM_FIMC_CLOCKS] = { "sclk_fimc", "fimc" };
  31. static struct fimc_fmt fimc_formats[] = {
  32. {
  33. .name = "RGB565",
  34. .fourcc = V4L2_PIX_FMT_RGB565X,
  35. .depth = { 16 },
  36. .color = S5P_FIMC_RGB565,
  37. .memplanes = 1,
  38. .colplanes = 1,
  39. .mbus_code = V4L2_MBUS_FMT_RGB565_2X8_BE,
  40. .flags = FMT_FLAGS_M2M,
  41. }, {
  42. .name = "BGR666",
  43. .fourcc = V4L2_PIX_FMT_BGR666,
  44. .depth = { 32 },
  45. .color = S5P_FIMC_RGB666,
  46. .memplanes = 1,
  47. .colplanes = 1,
  48. .flags = FMT_FLAGS_M2M,
  49. }, {
  50. .name = "XRGB-8-8-8-8, 32 bpp",
  51. .fourcc = V4L2_PIX_FMT_RGB32,
  52. .depth = { 32 },
  53. .color = S5P_FIMC_RGB888,
  54. .memplanes = 1,
  55. .colplanes = 1,
  56. .flags = FMT_FLAGS_M2M,
  57. }, {
  58. .name = "YUV 4:2:2 packed, YCbYCr",
  59. .fourcc = V4L2_PIX_FMT_YUYV,
  60. .depth = { 16 },
  61. .color = S5P_FIMC_YCBYCR422,
  62. .memplanes = 1,
  63. .colplanes = 1,
  64. .mbus_code = V4L2_MBUS_FMT_YUYV8_2X8,
  65. .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM,
  66. }, {
  67. .name = "YUV 4:2:2 packed, CbYCrY",
  68. .fourcc = V4L2_PIX_FMT_UYVY,
  69. .depth = { 16 },
  70. .color = S5P_FIMC_CBYCRY422,
  71. .memplanes = 1,
  72. .colplanes = 1,
  73. .mbus_code = V4L2_MBUS_FMT_UYVY8_2X8,
  74. .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM,
  75. }, {
  76. .name = "YUV 4:2:2 packed, CrYCbY",
  77. .fourcc = V4L2_PIX_FMT_VYUY,
  78. .depth = { 16 },
  79. .color = S5P_FIMC_CRYCBY422,
  80. .memplanes = 1,
  81. .colplanes = 1,
  82. .mbus_code = V4L2_MBUS_FMT_VYUY8_2X8,
  83. .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM,
  84. }, {
  85. .name = "YUV 4:2:2 packed, YCrYCb",
  86. .fourcc = V4L2_PIX_FMT_YVYU,
  87. .depth = { 16 },
  88. .color = S5P_FIMC_YCRYCB422,
  89. .memplanes = 1,
  90. .colplanes = 1,
  91. .mbus_code = V4L2_MBUS_FMT_YVYU8_2X8,
  92. .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM,
  93. }, {
  94. .name = "YUV 4:2:2 planar, Y/Cb/Cr",
  95. .fourcc = V4L2_PIX_FMT_YUV422P,
  96. .depth = { 12 },
  97. .color = S5P_FIMC_YCBYCR422,
  98. .memplanes = 1,
  99. .colplanes = 3,
  100. .flags = FMT_FLAGS_M2M,
  101. }, {
  102. .name = "YUV 4:2:2 planar, Y/CbCr",
  103. .fourcc = V4L2_PIX_FMT_NV16,
  104. .depth = { 16 },
  105. .color = S5P_FIMC_YCBYCR422,
  106. .memplanes = 1,
  107. .colplanes = 2,
  108. .flags = FMT_FLAGS_M2M,
  109. }, {
  110. .name = "YUV 4:2:2 planar, Y/CrCb",
  111. .fourcc = V4L2_PIX_FMT_NV61,
  112. .depth = { 16 },
  113. .color = S5P_FIMC_YCRYCB422,
  114. .memplanes = 1,
  115. .colplanes = 2,
  116. .flags = FMT_FLAGS_M2M,
  117. }, {
  118. .name = "YUV 4:2:0 planar, YCbCr",
  119. .fourcc = V4L2_PIX_FMT_YUV420,
  120. .depth = { 12 },
  121. .color = S5P_FIMC_YCBCR420,
  122. .memplanes = 1,
  123. .colplanes = 3,
  124. .flags = FMT_FLAGS_M2M,
  125. }, {
  126. .name = "YUV 4:2:0 planar, Y/CbCr",
  127. .fourcc = V4L2_PIX_FMT_NV12,
  128. .depth = { 12 },
  129. .color = S5P_FIMC_YCBCR420,
  130. .memplanes = 1,
  131. .colplanes = 2,
  132. .flags = FMT_FLAGS_M2M,
  133. }, {
  134. .name = "YUV 4:2:0 non-contiguous 2-planar, Y/CbCr",
  135. .fourcc = V4L2_PIX_FMT_NV12M,
  136. .color = S5P_FIMC_YCBCR420,
  137. .depth = { 8, 4 },
  138. .memplanes = 2,
  139. .colplanes = 2,
  140. .flags = FMT_FLAGS_M2M,
  141. }, {
  142. .name = "YUV 4:2:0 non-contiguous 3-planar, Y/Cb/Cr",
  143. .fourcc = V4L2_PIX_FMT_YUV420M,
  144. .color = S5P_FIMC_YCBCR420,
  145. .depth = { 8, 2, 2 },
  146. .memplanes = 3,
  147. .colplanes = 3,
  148. .flags = FMT_FLAGS_M2M,
  149. }, {
  150. .name = "YUV 4:2:0 non-contiguous 2-planar, Y/CbCr, tiled",
  151. .fourcc = V4L2_PIX_FMT_NV12MT,
  152. .color = S5P_FIMC_YCBCR420,
  153. .depth = { 8, 4 },
  154. .memplanes = 2,
  155. .colplanes = 2,
  156. .flags = FMT_FLAGS_M2M,
  157. },
  158. };
  159. static struct v4l2_queryctrl fimc_ctrls[] = {
  160. {
  161. .id = V4L2_CID_HFLIP,
  162. .type = V4L2_CTRL_TYPE_BOOLEAN,
  163. .name = "Horizontal flip",
  164. .minimum = 0,
  165. .maximum = 1,
  166. .default_value = 0,
  167. }, {
  168. .id = V4L2_CID_VFLIP,
  169. .type = V4L2_CTRL_TYPE_BOOLEAN,
  170. .name = "Vertical flip",
  171. .minimum = 0,
  172. .maximum = 1,
  173. .default_value = 0,
  174. }, {
  175. .id = V4L2_CID_ROTATE,
  176. .type = V4L2_CTRL_TYPE_INTEGER,
  177. .name = "Rotation (CCW)",
  178. .minimum = 0,
  179. .maximum = 270,
  180. .step = 90,
  181. .default_value = 0,
  182. },
  183. };
  184. static struct v4l2_queryctrl *get_ctrl(int id)
  185. {
  186. int i;
  187. for (i = 0; i < ARRAY_SIZE(fimc_ctrls); ++i)
  188. if (id == fimc_ctrls[i].id)
  189. return &fimc_ctrls[i];
  190. return NULL;
  191. }
  192. int fimc_check_scaler_ratio(struct v4l2_rect *r, struct fimc_frame *f)
  193. {
  194. if (r->width > f->width) {
  195. if (f->width > (r->width * SCALER_MAX_HRATIO))
  196. return -EINVAL;
  197. } else {
  198. if ((f->width * SCALER_MAX_HRATIO) < r->width)
  199. return -EINVAL;
  200. }
  201. if (r->height > f->height) {
  202. if (f->height > (r->height * SCALER_MAX_VRATIO))
  203. return -EINVAL;
  204. } else {
  205. if ((f->height * SCALER_MAX_VRATIO) < r->height)
  206. return -EINVAL;
  207. }
  208. return 0;
  209. }
  210. static int fimc_get_scaler_factor(u32 src, u32 tar, u32 *ratio, u32 *shift)
  211. {
  212. u32 sh = 6;
  213. if (src >= 64 * tar)
  214. return -EINVAL;
  215. while (sh--) {
  216. u32 tmp = 1 << sh;
  217. if (src >= tar * tmp) {
  218. *shift = sh, *ratio = tmp;
  219. return 0;
  220. }
  221. }
  222. *shift = 0, *ratio = 1;
  223. dbg("s: %d, t: %d, shift: %d, ratio: %d",
  224. src, tar, *shift, *ratio);
  225. return 0;
  226. }
  227. int fimc_set_scaler_info(struct fimc_ctx *ctx)
  228. {
  229. struct fimc_scaler *sc = &ctx->scaler;
  230. struct fimc_frame *s_frame = &ctx->s_frame;
  231. struct fimc_frame *d_frame = &ctx->d_frame;
  232. int tx, ty, sx, sy;
  233. int ret;
  234. if (ctx->rotation == 90 || ctx->rotation == 270) {
  235. ty = d_frame->width;
  236. tx = d_frame->height;
  237. } else {
  238. tx = d_frame->width;
  239. ty = d_frame->height;
  240. }
  241. if (tx <= 0 || ty <= 0) {
  242. v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
  243. "invalid target size: %d x %d", tx, ty);
  244. return -EINVAL;
  245. }
  246. sx = s_frame->width;
  247. sy = s_frame->height;
  248. if (sx <= 0 || sy <= 0) {
  249. err("invalid source size: %d x %d", sx, sy);
  250. return -EINVAL;
  251. }
  252. sc->real_width = sx;
  253. sc->real_height = sy;
  254. dbg("sx= %d, sy= %d, tx= %d, ty= %d", sx, sy, tx, ty);
  255. ret = fimc_get_scaler_factor(sx, tx, &sc->pre_hratio, &sc->hfactor);
  256. if (ret)
  257. return ret;
  258. ret = fimc_get_scaler_factor(sy, ty, &sc->pre_vratio, &sc->vfactor);
  259. if (ret)
  260. return ret;
  261. sc->pre_dst_width = sx / sc->pre_hratio;
  262. sc->pre_dst_height = sy / sc->pre_vratio;
  263. sc->main_hratio = (sx << 8) / (tx << sc->hfactor);
  264. sc->main_vratio = (sy << 8) / (ty << sc->vfactor);
  265. sc->scaleup_h = (tx >= sx) ? 1 : 0;
  266. sc->scaleup_v = (ty >= sy) ? 1 : 0;
  267. /* check to see if input and output size/format differ */
  268. if (s_frame->fmt->color == d_frame->fmt->color
  269. && s_frame->width == d_frame->width
  270. && s_frame->height == d_frame->height)
  271. sc->copy_mode = 1;
  272. else
  273. sc->copy_mode = 0;
  274. return 0;
  275. }
  276. static void fimc_capture_handler(struct fimc_dev *fimc)
  277. {
  278. struct fimc_vid_cap *cap = &fimc->vid_cap;
  279. struct fimc_vid_buffer *v_buf = NULL;
  280. if (!list_empty(&cap->active_buf_q)) {
  281. v_buf = active_queue_pop(cap);
  282. vb2_buffer_done(&v_buf->vb, VB2_BUF_STATE_DONE);
  283. }
  284. if (test_and_clear_bit(ST_CAPT_SHUT, &fimc->state)) {
  285. wake_up(&fimc->irq_queue);
  286. return;
  287. }
  288. if (!list_empty(&cap->pending_buf_q)) {
  289. v_buf = pending_queue_pop(cap);
  290. fimc_hw_set_output_addr(fimc, &v_buf->paddr, cap->buf_index);
  291. v_buf->index = cap->buf_index;
  292. dbg("hw ptr: %d, sw ptr: %d",
  293. fimc_hw_get_frame_index(fimc), cap->buf_index);
  294. /* Move the buffer to the capture active queue */
  295. active_queue_add(cap, v_buf);
  296. dbg("next frame: %d, done frame: %d",
  297. fimc_hw_get_frame_index(fimc), v_buf->index);
  298. if (++cap->buf_index >= FIMC_MAX_OUT_BUFS)
  299. cap->buf_index = 0;
  300. } else if (test_and_clear_bit(ST_CAPT_STREAM, &fimc->state) &&
  301. cap->active_buf_cnt <= 1) {
  302. fimc_deactivate_capture(fimc);
  303. }
  304. dbg("frame: %d, active_buf_cnt= %d",
  305. fimc_hw_get_frame_index(fimc), cap->active_buf_cnt);
  306. }
  307. static irqreturn_t fimc_isr(int irq, void *priv)
  308. {
  309. struct fimc_dev *fimc = priv;
  310. BUG_ON(!fimc);
  311. fimc_hw_clear_irq(fimc);
  312. spin_lock(&fimc->slock);
  313. if (test_and_clear_bit(ST_M2M_PEND, &fimc->state)) {
  314. struct vb2_buffer *src_vb, *dst_vb;
  315. struct fimc_ctx *ctx = v4l2_m2m_get_curr_priv(fimc->m2m.m2m_dev);
  316. if (!ctx || !ctx->m2m_ctx)
  317. goto isr_unlock;
  318. src_vb = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
  319. dst_vb = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
  320. if (src_vb && dst_vb) {
  321. v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_DONE);
  322. v4l2_m2m_buf_done(dst_vb, VB2_BUF_STATE_DONE);
  323. v4l2_m2m_job_finish(fimc->m2m.m2m_dev, ctx->m2m_ctx);
  324. }
  325. goto isr_unlock;
  326. }
  327. if (test_bit(ST_CAPT_RUN, &fimc->state))
  328. fimc_capture_handler(fimc);
  329. if (test_and_clear_bit(ST_CAPT_PEND, &fimc->state)) {
  330. set_bit(ST_CAPT_RUN, &fimc->state);
  331. wake_up(&fimc->irq_queue);
  332. }
  333. isr_unlock:
  334. spin_unlock(&fimc->slock);
  335. return IRQ_HANDLED;
  336. }
  337. /* The color format (colplanes, memplanes) must be already configured. */
  338. int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
  339. struct fimc_frame *frame, struct fimc_addr *paddr)
  340. {
  341. int ret = 0;
  342. u32 pix_size;
  343. if (vb == NULL || frame == NULL)
  344. return -EINVAL;
  345. pix_size = frame->width * frame->height;
  346. dbg("memplanes= %d, colplanes= %d, pix_size= %d",
  347. frame->fmt->memplanes, frame->fmt->colplanes, pix_size);
  348. paddr->y = vb2_dma_contig_plane_paddr(vb, 0);
  349. if (frame->fmt->memplanes == 1) {
  350. switch (frame->fmt->colplanes) {
  351. case 1:
  352. paddr->cb = 0;
  353. paddr->cr = 0;
  354. break;
  355. case 2:
  356. /* decompose Y into Y/Cb */
  357. paddr->cb = (u32)(paddr->y + pix_size);
  358. paddr->cr = 0;
  359. break;
  360. case 3:
  361. paddr->cb = (u32)(paddr->y + pix_size);
  362. /* decompose Y into Y/Cb/Cr */
  363. if (S5P_FIMC_YCBCR420 == frame->fmt->color)
  364. paddr->cr = (u32)(paddr->cb
  365. + (pix_size >> 2));
  366. else /* 422 */
  367. paddr->cr = (u32)(paddr->cb
  368. + (pix_size >> 1));
  369. break;
  370. default:
  371. return -EINVAL;
  372. }
  373. } else {
  374. if (frame->fmt->memplanes >= 2)
  375. paddr->cb = vb2_dma_contig_plane_paddr(vb, 1);
  376. if (frame->fmt->memplanes == 3)
  377. paddr->cr = vb2_dma_contig_plane_paddr(vb, 2);
  378. }
  379. dbg("PHYS_ADDR: y= 0x%X cb= 0x%X cr= 0x%X ret= %d",
  380. paddr->y, paddr->cb, paddr->cr, ret);
  381. return ret;
  382. }
  383. /* Set order for 1 and 2 plane YCBCR 4:2:2 formats. */
  384. static void fimc_set_yuv_order(struct fimc_ctx *ctx)
  385. {
  386. /* The one only mode supported in SoC. */
  387. ctx->in_order_2p = S5P_FIMC_LSB_CRCB;
  388. ctx->out_order_2p = S5P_FIMC_LSB_CRCB;
  389. /* Set order for 1 plane input formats. */
  390. switch (ctx->s_frame.fmt->color) {
  391. case S5P_FIMC_YCRYCB422:
  392. ctx->in_order_1p = S5P_FIMC_IN_YCRYCB;
  393. break;
  394. case S5P_FIMC_CBYCRY422:
  395. ctx->in_order_1p = S5P_FIMC_IN_CBYCRY;
  396. break;
  397. case S5P_FIMC_CRYCBY422:
  398. ctx->in_order_1p = S5P_FIMC_IN_CRYCBY;
  399. break;
  400. case S5P_FIMC_YCBYCR422:
  401. default:
  402. ctx->in_order_1p = S5P_FIMC_IN_YCBYCR;
  403. break;
  404. }
  405. dbg("ctx->in_order_1p= %d", ctx->in_order_1p);
  406. switch (ctx->d_frame.fmt->color) {
  407. case S5P_FIMC_YCRYCB422:
  408. ctx->out_order_1p = S5P_FIMC_OUT_YCRYCB;
  409. break;
  410. case S5P_FIMC_CBYCRY422:
  411. ctx->out_order_1p = S5P_FIMC_OUT_CBYCRY;
  412. break;
  413. case S5P_FIMC_CRYCBY422:
  414. ctx->out_order_1p = S5P_FIMC_OUT_CRYCBY;
  415. break;
  416. case S5P_FIMC_YCBYCR422:
  417. default:
  418. ctx->out_order_1p = S5P_FIMC_OUT_YCBYCR;
  419. break;
  420. }
  421. dbg("ctx->out_order_1p= %d", ctx->out_order_1p);
  422. }
  423. static void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f)
  424. {
  425. struct samsung_fimc_variant *variant = ctx->fimc_dev->variant;
  426. u32 i, depth = 0;
  427. for (i = 0; i < f->fmt->colplanes; i++)
  428. depth += f->fmt->depth[i];
  429. f->dma_offset.y_h = f->offs_h;
  430. if (!variant->pix_hoff)
  431. f->dma_offset.y_h *= (depth >> 3);
  432. f->dma_offset.y_v = f->offs_v;
  433. f->dma_offset.cb_h = f->offs_h;
  434. f->dma_offset.cb_v = f->offs_v;
  435. f->dma_offset.cr_h = f->offs_h;
  436. f->dma_offset.cr_v = f->offs_v;
  437. if (!variant->pix_hoff) {
  438. if (f->fmt->colplanes == 3) {
  439. f->dma_offset.cb_h >>= 1;
  440. f->dma_offset.cr_h >>= 1;
  441. }
  442. if (f->fmt->color == S5P_FIMC_YCBCR420) {
  443. f->dma_offset.cb_v >>= 1;
  444. f->dma_offset.cr_v >>= 1;
  445. }
  446. }
  447. dbg("in_offset: color= %d, y_h= %d, y_v= %d",
  448. f->fmt->color, f->dma_offset.y_h, f->dma_offset.y_v);
  449. }
  450. /**
  451. * fimc_prepare_config - check dimensions, operation and color mode
  452. * and pre-calculate offset and the scaling coefficients.
  453. *
  454. * @ctx: hardware context information
  455. * @flags: flags indicating which parameters to check/update
  456. *
  457. * Return: 0 if dimensions are valid or non zero otherwise.
  458. */
  459. int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags)
  460. {
  461. struct fimc_frame *s_frame, *d_frame;
  462. struct vb2_buffer *vb = NULL;
  463. int ret = 0;
  464. s_frame = &ctx->s_frame;
  465. d_frame = &ctx->d_frame;
  466. if (flags & FIMC_PARAMS) {
  467. /* Prepare the DMA offset ratios for scaler. */
  468. fimc_prepare_dma_offset(ctx, &ctx->s_frame);
  469. fimc_prepare_dma_offset(ctx, &ctx->d_frame);
  470. if (s_frame->height > (SCALER_MAX_VRATIO * d_frame->height) ||
  471. s_frame->width > (SCALER_MAX_HRATIO * d_frame->width)) {
  472. err("out of scaler range");
  473. return -EINVAL;
  474. }
  475. fimc_set_yuv_order(ctx);
  476. }
  477. /* Input DMA mode is not allowed when the scaler is disabled. */
  478. ctx->scaler.enabled = 1;
  479. if (flags & FIMC_SRC_ADDR) {
  480. vb = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
  481. ret = fimc_prepare_addr(ctx, vb, s_frame, &s_frame->paddr);
  482. if (ret)
  483. return ret;
  484. }
  485. if (flags & FIMC_DST_ADDR) {
  486. vb = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
  487. ret = fimc_prepare_addr(ctx, vb, d_frame, &d_frame->paddr);
  488. }
  489. return ret;
  490. }
  491. static void fimc_dma_run(void *priv)
  492. {
  493. struct fimc_ctx *ctx = priv;
  494. struct fimc_dev *fimc;
  495. unsigned long flags;
  496. u32 ret;
  497. if (WARN(!ctx, "null hardware context\n"))
  498. return;
  499. fimc = ctx->fimc_dev;
  500. spin_lock_irqsave(&ctx->slock, flags);
  501. set_bit(ST_M2M_PEND, &fimc->state);
  502. ctx->state |= (FIMC_SRC_ADDR | FIMC_DST_ADDR);
  503. ret = fimc_prepare_config(ctx, ctx->state);
  504. if (ret) {
  505. err("Wrong parameters");
  506. goto dma_unlock;
  507. }
  508. /* Reconfigure hardware if the context has changed. */
  509. if (fimc->m2m.ctx != ctx) {
  510. ctx->state |= FIMC_PARAMS;
  511. fimc->m2m.ctx = ctx;
  512. }
  513. fimc_hw_set_input_addr(fimc, &ctx->s_frame.paddr);
  514. if (ctx->state & FIMC_PARAMS) {
  515. fimc_hw_set_input_path(ctx);
  516. fimc_hw_set_in_dma(ctx);
  517. if (fimc_set_scaler_info(ctx)) {
  518. err("Scaler setup error");
  519. goto dma_unlock;
  520. }
  521. fimc_hw_set_scaler(ctx);
  522. fimc_hw_set_target_format(ctx);
  523. fimc_hw_set_rotation(ctx);
  524. fimc_hw_set_effect(ctx);
  525. }
  526. fimc_hw_set_output_path(ctx);
  527. if (ctx->state & (FIMC_DST_ADDR | FIMC_PARAMS))
  528. fimc_hw_set_output_addr(fimc, &ctx->d_frame.paddr, -1);
  529. if (ctx->state & FIMC_PARAMS)
  530. fimc_hw_set_out_dma(ctx);
  531. fimc_activate_capture(ctx);
  532. ctx->state &= (FIMC_CTX_M2M | FIMC_CTX_CAP |
  533. FIMC_SRC_FMT | FIMC_DST_FMT);
  534. fimc_hw_activate_input_dma(fimc, true);
  535. dma_unlock:
  536. spin_unlock_irqrestore(&ctx->slock, flags);
  537. }
  538. static void fimc_job_abort(void *priv)
  539. {
  540. /* Nothing done in job_abort. */
  541. }
  542. static int fimc_queue_setup(struct vb2_queue *vq, unsigned int *num_buffers,
  543. unsigned int *num_planes, unsigned long sizes[],
  544. void *allocators[])
  545. {
  546. struct fimc_ctx *ctx = vb2_get_drv_priv(vq);
  547. struct fimc_frame *f;
  548. int i;
  549. f = ctx_get_frame(ctx, vq->type);
  550. if (IS_ERR(f))
  551. return PTR_ERR(f);
  552. /*
  553. * Return number of non-contigous planes (plane buffers)
  554. * depending on the configured color format.
  555. */
  556. if (f->fmt)
  557. *num_planes = f->fmt->memplanes;
  558. for (i = 0; i < f->fmt->memplanes; i++) {
  559. sizes[i] = (f->width * f->height * f->fmt->depth[i]) >> 3;
  560. allocators[i] = ctx->fimc_dev->alloc_ctx;
  561. }
  562. if (*num_buffers == 0)
  563. *num_buffers = 1;
  564. return 0;
  565. }
  566. static int fimc_buf_prepare(struct vb2_buffer *vb)
  567. {
  568. struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
  569. struct fimc_frame *frame;
  570. int i;
  571. frame = ctx_get_frame(ctx, vb->vb2_queue->type);
  572. if (IS_ERR(frame))
  573. return PTR_ERR(frame);
  574. for (i = 0; i < frame->fmt->memplanes; i++)
  575. vb2_set_plane_payload(vb, i, frame->payload[i]);
  576. return 0;
  577. }
  578. static void fimc_buf_queue(struct vb2_buffer *vb)
  579. {
  580. struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
  581. dbg("ctx: %p, ctx->state: 0x%x", ctx, ctx->state);
  582. if (ctx->m2m_ctx)
  583. v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
  584. }
  585. static void fimc_lock(struct vb2_queue *vq)
  586. {
  587. struct fimc_ctx *ctx = vb2_get_drv_priv(vq);
  588. mutex_lock(&ctx->fimc_dev->lock);
  589. }
  590. static void fimc_unlock(struct vb2_queue *vq)
  591. {
  592. struct fimc_ctx *ctx = vb2_get_drv_priv(vq);
  593. mutex_unlock(&ctx->fimc_dev->lock);
  594. }
  595. struct vb2_ops fimc_qops = {
  596. .queue_setup = fimc_queue_setup,
  597. .buf_prepare = fimc_buf_prepare,
  598. .buf_queue = fimc_buf_queue,
  599. .wait_prepare = fimc_unlock,
  600. .wait_finish = fimc_lock,
  601. };
  602. static int fimc_m2m_querycap(struct file *file, void *priv,
  603. struct v4l2_capability *cap)
  604. {
  605. struct fimc_ctx *ctx = file->private_data;
  606. struct fimc_dev *fimc = ctx->fimc_dev;
  607. strncpy(cap->driver, fimc->pdev->name, sizeof(cap->driver) - 1);
  608. strncpy(cap->card, fimc->pdev->name, sizeof(cap->card) - 1);
  609. cap->bus_info[0] = 0;
  610. cap->version = KERNEL_VERSION(1, 0, 0);
  611. cap->capabilities = V4L2_CAP_STREAMING |
  612. V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT |
  613. V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_OUTPUT_MPLANE;
  614. return 0;
  615. }
  616. int fimc_vidioc_enum_fmt_mplane(struct file *file, void *priv,
  617. struct v4l2_fmtdesc *f)
  618. {
  619. struct fimc_fmt *fmt;
  620. if (f->index >= ARRAY_SIZE(fimc_formats))
  621. return -EINVAL;
  622. fmt = &fimc_formats[f->index];
  623. strncpy(f->description, fmt->name, sizeof(f->description) - 1);
  624. f->pixelformat = fmt->fourcc;
  625. return 0;
  626. }
  627. int fimc_vidioc_g_fmt_mplane(struct file *file, void *priv,
  628. struct v4l2_format *f)
  629. {
  630. struct fimc_ctx *ctx = priv;
  631. struct fimc_frame *frame;
  632. frame = ctx_get_frame(ctx, f->type);
  633. if (IS_ERR(frame))
  634. return PTR_ERR(frame);
  635. f->fmt.pix.width = frame->width;
  636. f->fmt.pix.height = frame->height;
  637. f->fmt.pix.field = V4L2_FIELD_NONE;
  638. f->fmt.pix.pixelformat = frame->fmt->fourcc;
  639. return 0;
  640. }
  641. struct fimc_fmt *find_format(struct v4l2_format *f, unsigned int mask)
  642. {
  643. struct fimc_fmt *fmt;
  644. unsigned int i;
  645. for (i = 0; i < ARRAY_SIZE(fimc_formats); ++i) {
  646. fmt = &fimc_formats[i];
  647. if (fmt->fourcc == f->fmt.pix.pixelformat &&
  648. (fmt->flags & mask))
  649. break;
  650. }
  651. return (i == ARRAY_SIZE(fimc_formats)) ? NULL : fmt;
  652. }
  653. struct fimc_fmt *find_mbus_format(struct v4l2_mbus_framefmt *f,
  654. unsigned int mask)
  655. {
  656. struct fimc_fmt *fmt;
  657. unsigned int i;
  658. for (i = 0; i < ARRAY_SIZE(fimc_formats); ++i) {
  659. fmt = &fimc_formats[i];
  660. if (fmt->mbus_code == f->code && (fmt->flags & mask))
  661. break;
  662. }
  663. return (i == ARRAY_SIZE(fimc_formats)) ? NULL : fmt;
  664. }
  665. int fimc_vidioc_try_fmt_mplane(struct file *file, void *priv,
  666. struct v4l2_format *f)
  667. {
  668. struct fimc_ctx *ctx = priv;
  669. struct fimc_dev *fimc = ctx->fimc_dev;
  670. struct samsung_fimc_variant *variant = fimc->variant;
  671. struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
  672. struct fimc_fmt *fmt;
  673. u32 max_width, mod_x, mod_y, mask;
  674. int i, is_output = 0;
  675. if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  676. if (ctx->state & FIMC_CTX_CAP)
  677. return -EINVAL;
  678. is_output = 1;
  679. } else if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  680. return -EINVAL;
  681. }
  682. dbg("w: %d, h: %d", pix->width, pix->height);
  683. mask = is_output ? FMT_FLAGS_M2M : FMT_FLAGS_M2M | FMT_FLAGS_CAM;
  684. fmt = find_format(f, mask);
  685. if (!fmt) {
  686. v4l2_err(&fimc->m2m.v4l2_dev, "Fourcc format (0x%X) invalid.\n",
  687. pix->pixelformat);
  688. return -EINVAL;
  689. }
  690. if (pix->field == V4L2_FIELD_ANY)
  691. pix->field = V4L2_FIELD_NONE;
  692. else if (V4L2_FIELD_NONE != pix->field)
  693. return -EINVAL;
  694. if (is_output) {
  695. max_width = variant->pix_limit->scaler_dis_w;
  696. mod_x = ffs(variant->min_inp_pixsize) - 1;
  697. } else {
  698. max_width = variant->pix_limit->out_rot_dis_w;
  699. mod_x = ffs(variant->min_out_pixsize) - 1;
  700. }
  701. if (tiled_fmt(fmt)) {
  702. mod_x = 6; /* 64 x 32 pixels tile */
  703. mod_y = 5;
  704. } else {
  705. if (fimc->id == 1 && variant->pix_hoff)
  706. mod_y = fimc_fmt_is_rgb(fmt->color) ? 0 : 1;
  707. else
  708. mod_y = mod_x;
  709. }
  710. dbg("mod_x: %d, mod_y: %d, max_w: %d", mod_x, mod_y, max_width);
  711. v4l_bound_align_image(&pix->width, 16, max_width, mod_x,
  712. &pix->height, 8, variant->pix_limit->scaler_dis_w, mod_y, 0);
  713. pix->num_planes = fmt->memplanes;
  714. for (i = 0; i < pix->num_planes; ++i) {
  715. int bpl = pix->plane_fmt[i].bytesperline;
  716. dbg("[%d] bpl: %d, depth: %d, w: %d, h: %d",
  717. i, bpl, fmt->depth[i], pix->width, pix->height);
  718. if (!bpl || (bpl * 8 / fmt->depth[i]) > pix->width)
  719. bpl = (pix->width * fmt->depth[0]) >> 3;
  720. if (!pix->plane_fmt[i].sizeimage)
  721. pix->plane_fmt[i].sizeimage = pix->height * bpl;
  722. pix->plane_fmt[i].bytesperline = bpl;
  723. dbg("[%d]: bpl: %d, sizeimage: %d",
  724. i, pix->plane_fmt[i].bytesperline,
  725. pix->plane_fmt[i].sizeimage);
  726. }
  727. return 0;
  728. }
  729. static int fimc_m2m_s_fmt_mplane(struct file *file, void *priv,
  730. struct v4l2_format *f)
  731. {
  732. struct fimc_ctx *ctx = priv;
  733. struct fimc_dev *fimc = ctx->fimc_dev;
  734. struct vb2_queue *vq;
  735. struct fimc_frame *frame;
  736. struct v4l2_pix_format_mplane *pix;
  737. unsigned long flags;
  738. int i, ret = 0;
  739. u32 tmp;
  740. ret = fimc_vidioc_try_fmt_mplane(file, priv, f);
  741. if (ret)
  742. return ret;
  743. vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
  744. if (vb2_is_streaming(vq)) {
  745. v4l2_err(&fimc->m2m.v4l2_dev, "queue (%d) busy\n", f->type);
  746. return -EBUSY;
  747. }
  748. if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  749. frame = &ctx->s_frame;
  750. } else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
  751. frame = &ctx->d_frame;
  752. } else {
  753. v4l2_err(&fimc->m2m.v4l2_dev,
  754. "Wrong buffer/video queue type (%d)\n", f->type);
  755. return -EINVAL;
  756. }
  757. pix = &f->fmt.pix_mp;
  758. frame->fmt = find_format(f, FMT_FLAGS_M2M);
  759. if (!frame->fmt)
  760. return -EINVAL;
  761. for (i = 0; i < frame->fmt->colplanes; i++)
  762. frame->payload[i] = pix->plane_fmt[i].bytesperline * pix->height;
  763. frame->f_width = pix->plane_fmt[0].bytesperline * 8 /
  764. frame->fmt->depth[0];
  765. frame->f_height = pix->height;
  766. frame->width = pix->width;
  767. frame->height = pix->height;
  768. frame->o_width = pix->width;
  769. frame->o_height = pix->height;
  770. frame->offs_h = 0;
  771. frame->offs_v = 0;
  772. spin_lock_irqsave(&ctx->slock, flags);
  773. tmp = (frame == &ctx->d_frame) ? FIMC_DST_FMT : FIMC_SRC_FMT;
  774. ctx->state |= FIMC_PARAMS | tmp;
  775. spin_unlock_irqrestore(&ctx->slock, flags);
  776. dbg("f_w: %d, f_h: %d", frame->f_width, frame->f_height);
  777. return 0;
  778. }
  779. static int fimc_m2m_reqbufs(struct file *file, void *priv,
  780. struct v4l2_requestbuffers *reqbufs)
  781. {
  782. struct fimc_ctx *ctx = priv;
  783. return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
  784. }
  785. static int fimc_m2m_querybuf(struct file *file, void *priv,
  786. struct v4l2_buffer *buf)
  787. {
  788. struct fimc_ctx *ctx = priv;
  789. return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
  790. }
  791. static int fimc_m2m_qbuf(struct file *file, void *priv,
  792. struct v4l2_buffer *buf)
  793. {
  794. struct fimc_ctx *ctx = priv;
  795. return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
  796. }
  797. static int fimc_m2m_dqbuf(struct file *file, void *priv,
  798. struct v4l2_buffer *buf)
  799. {
  800. struct fimc_ctx *ctx = priv;
  801. return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf);
  802. }
  803. static int fimc_m2m_streamon(struct file *file, void *priv,
  804. enum v4l2_buf_type type)
  805. {
  806. struct fimc_ctx *ctx = priv;
  807. /* The source and target color format need to be set */
  808. if (V4L2_TYPE_IS_OUTPUT(type)) {
  809. if (~ctx->state & FIMC_SRC_FMT)
  810. return -EINVAL;
  811. } else if (~ctx->state & FIMC_DST_FMT) {
  812. return -EINVAL;
  813. }
  814. return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
  815. }
  816. static int fimc_m2m_streamoff(struct file *file, void *priv,
  817. enum v4l2_buf_type type)
  818. {
  819. struct fimc_ctx *ctx = priv;
  820. return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type);
  821. }
  822. int fimc_vidioc_queryctrl(struct file *file, void *priv,
  823. struct v4l2_queryctrl *qc)
  824. {
  825. struct fimc_ctx *ctx = priv;
  826. struct v4l2_queryctrl *c;
  827. int ret = -EINVAL;
  828. c = get_ctrl(qc->id);
  829. if (c) {
  830. *qc = *c;
  831. return 0;
  832. }
  833. if (ctx->state & FIMC_CTX_CAP) {
  834. return v4l2_subdev_call(ctx->fimc_dev->vid_cap.sd,
  835. core, queryctrl, qc);
  836. }
  837. return ret;
  838. }
  839. int fimc_vidioc_g_ctrl(struct file *file, void *priv,
  840. struct v4l2_control *ctrl)
  841. {
  842. struct fimc_ctx *ctx = priv;
  843. struct fimc_dev *fimc = ctx->fimc_dev;
  844. switch (ctrl->id) {
  845. case V4L2_CID_HFLIP:
  846. ctrl->value = (FLIP_X_AXIS & ctx->flip) ? 1 : 0;
  847. break;
  848. case V4L2_CID_VFLIP:
  849. ctrl->value = (FLIP_Y_AXIS & ctx->flip) ? 1 : 0;
  850. break;
  851. case V4L2_CID_ROTATE:
  852. ctrl->value = ctx->rotation;
  853. break;
  854. default:
  855. if (ctx->state & FIMC_CTX_CAP) {
  856. return v4l2_subdev_call(fimc->vid_cap.sd, core,
  857. g_ctrl, ctrl);
  858. } else {
  859. v4l2_err(&fimc->m2m.v4l2_dev,
  860. "Invalid control\n");
  861. return -EINVAL;
  862. }
  863. }
  864. dbg("ctrl->value= %d", ctrl->value);
  865. return 0;
  866. }
  867. int check_ctrl_val(struct fimc_ctx *ctx, struct v4l2_control *ctrl)
  868. {
  869. struct v4l2_queryctrl *c;
  870. c = get_ctrl(ctrl->id);
  871. if (!c)
  872. return -EINVAL;
  873. if (ctrl->value < c->minimum || ctrl->value > c->maximum
  874. || (c->step != 0 && ctrl->value % c->step != 0)) {
  875. v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
  876. "Invalid control value\n");
  877. return -ERANGE;
  878. }
  879. return 0;
  880. }
  881. int fimc_s_ctrl(struct fimc_ctx *ctx, struct v4l2_control *ctrl)
  882. {
  883. struct samsung_fimc_variant *variant = ctx->fimc_dev->variant;
  884. struct fimc_dev *fimc = ctx->fimc_dev;
  885. unsigned long flags;
  886. if (ctx->rotation != 0 &&
  887. (ctrl->id == V4L2_CID_HFLIP || ctrl->id == V4L2_CID_VFLIP)) {
  888. v4l2_err(&fimc->m2m.v4l2_dev,
  889. "Simultaneous flip and rotation is not supported\n");
  890. return -EINVAL;
  891. }
  892. spin_lock_irqsave(&ctx->slock, flags);
  893. switch (ctrl->id) {
  894. case V4L2_CID_HFLIP:
  895. if (ctrl->value)
  896. ctx->flip |= FLIP_X_AXIS;
  897. else
  898. ctx->flip &= ~FLIP_X_AXIS;
  899. break;
  900. case V4L2_CID_VFLIP:
  901. if (ctrl->value)
  902. ctx->flip |= FLIP_Y_AXIS;
  903. else
  904. ctx->flip &= ~FLIP_Y_AXIS;
  905. break;
  906. case V4L2_CID_ROTATE:
  907. /* Check for the output rotator availability */
  908. if ((ctrl->value == 90 || ctrl->value == 270) &&
  909. (ctx->in_path == FIMC_DMA && !variant->has_out_rot)) {
  910. spin_unlock_irqrestore(&ctx->slock, flags);
  911. return -EINVAL;
  912. } else {
  913. ctx->rotation = ctrl->value;
  914. }
  915. break;
  916. default:
  917. spin_unlock_irqrestore(&ctx->slock, flags);
  918. v4l2_err(&fimc->m2m.v4l2_dev, "Invalid control\n");
  919. return -EINVAL;
  920. }
  921. ctx->state |= FIMC_PARAMS;
  922. spin_unlock_irqrestore(&ctx->slock, flags);
  923. return 0;
  924. }
  925. static int fimc_m2m_s_ctrl(struct file *file, void *priv,
  926. struct v4l2_control *ctrl)
  927. {
  928. struct fimc_ctx *ctx = priv;
  929. int ret = 0;
  930. ret = check_ctrl_val(ctx, ctrl);
  931. if (ret)
  932. return ret;
  933. ret = fimc_s_ctrl(ctx, ctrl);
  934. return 0;
  935. }
  936. static int fimc_m2m_cropcap(struct file *file, void *fh,
  937. struct v4l2_cropcap *cr)
  938. {
  939. struct fimc_frame *frame;
  940. struct fimc_ctx *ctx = fh;
  941. frame = ctx_get_frame(ctx, cr->type);
  942. if (IS_ERR(frame))
  943. return PTR_ERR(frame);
  944. cr->bounds.left = 0;
  945. cr->bounds.top = 0;
  946. cr->bounds.width = frame->f_width;
  947. cr->bounds.height = frame->f_height;
  948. cr->defrect = cr->bounds;
  949. return 0;
  950. }
  951. static int fimc_m2m_g_crop(struct file *file, void *fh, struct v4l2_crop *cr)
  952. {
  953. struct fimc_frame *frame;
  954. struct fimc_ctx *ctx = file->private_data;
  955. frame = ctx_get_frame(ctx, cr->type);
  956. if (IS_ERR(frame))
  957. return PTR_ERR(frame);
  958. cr->c.left = frame->offs_h;
  959. cr->c.top = frame->offs_v;
  960. cr->c.width = frame->width;
  961. cr->c.height = frame->height;
  962. return 0;
  963. }
  964. int fimc_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr)
  965. {
  966. struct fimc_dev *fimc = ctx->fimc_dev;
  967. struct fimc_frame *f;
  968. u32 min_size, halign, depth = 0;
  969. int i;
  970. if (cr->c.top < 0 || cr->c.left < 0) {
  971. v4l2_err(&fimc->m2m.v4l2_dev,
  972. "doesn't support negative values for top & left\n");
  973. return -EINVAL;
  974. }
  975. if (cr->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
  976. f = (ctx->state & FIMC_CTX_CAP) ? &ctx->s_frame : &ctx->d_frame;
  977. else if (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE &&
  978. ctx->state & FIMC_CTX_M2M)
  979. f = &ctx->s_frame;
  980. else
  981. return -EINVAL;
  982. min_size = (f == &ctx->s_frame) ?
  983. fimc->variant->min_inp_pixsize : fimc->variant->min_out_pixsize;
  984. if (ctx->state & FIMC_CTX_M2M) {
  985. if (fimc->id == 1 && fimc->variant->pix_hoff)
  986. halign = fimc_fmt_is_rgb(f->fmt->color) ? 0 : 1;
  987. else
  988. halign = ffs(min_size) - 1;
  989. /* there are more strict aligment requirements at camera interface */
  990. } else {
  991. min_size = 16;
  992. halign = 4;
  993. }
  994. for (i = 0; i < f->fmt->colplanes; i++)
  995. depth += f->fmt->depth[i];
  996. v4l_bound_align_image(&cr->c.width, min_size, f->o_width,
  997. ffs(min_size) - 1,
  998. &cr->c.height, min_size, f->o_height,
  999. halign, 64/(ALIGN(depth, 8)));
  1000. /* adjust left/top if cropping rectangle is out of bounds */
  1001. if (cr->c.left + cr->c.width > f->o_width)
  1002. cr->c.left = f->o_width - cr->c.width;
  1003. if (cr->c.top + cr->c.height > f->o_height)
  1004. cr->c.top = f->o_height - cr->c.height;
  1005. cr->c.left = round_down(cr->c.left, min_size);
  1006. cr->c.top = round_down(cr->c.top,
  1007. ctx->state & FIMC_CTX_M2M ? 8 : 16);
  1008. dbg("l:%d, t:%d, w:%d, h:%d, f_w: %d, f_h: %d",
  1009. cr->c.left, cr->c.top, cr->c.width, cr->c.height,
  1010. f->f_width, f->f_height);
  1011. return 0;
  1012. }
  1013. static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
  1014. {
  1015. struct fimc_ctx *ctx = file->private_data;
  1016. struct fimc_dev *fimc = ctx->fimc_dev;
  1017. unsigned long flags;
  1018. struct fimc_frame *f;
  1019. int ret;
  1020. ret = fimc_try_crop(ctx, cr);
  1021. if (ret)
  1022. return ret;
  1023. f = (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) ?
  1024. &ctx->s_frame : &ctx->d_frame;
  1025. spin_lock_irqsave(&ctx->slock, flags);
  1026. if (~ctx->state & (FIMC_SRC_FMT | FIMC_DST_FMT)) {
  1027. /* Check to see if scaling ratio is within supported range */
  1028. if (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
  1029. ret = fimc_check_scaler_ratio(&cr->c, &ctx->d_frame);
  1030. else
  1031. ret = fimc_check_scaler_ratio(&cr->c, &ctx->s_frame);
  1032. if (ret) {
  1033. v4l2_err(&fimc->m2m.v4l2_dev, "Out of scaler range");
  1034. spin_unlock_irqrestore(&ctx->slock, flags);
  1035. return -EINVAL;
  1036. }
  1037. }
  1038. ctx->state |= FIMC_PARAMS;
  1039. f->offs_h = cr->c.left;
  1040. f->offs_v = cr->c.top;
  1041. f->width = cr->c.width;
  1042. f->height = cr->c.height;
  1043. spin_unlock_irqrestore(&ctx->slock, flags);
  1044. return 0;
  1045. }
  1046. static const struct v4l2_ioctl_ops fimc_m2m_ioctl_ops = {
  1047. .vidioc_querycap = fimc_m2m_querycap,
  1048. .vidioc_enum_fmt_vid_cap_mplane = fimc_vidioc_enum_fmt_mplane,
  1049. .vidioc_enum_fmt_vid_out_mplane = fimc_vidioc_enum_fmt_mplane,
  1050. .vidioc_g_fmt_vid_cap_mplane = fimc_vidioc_g_fmt_mplane,
  1051. .vidioc_g_fmt_vid_out_mplane = fimc_vidioc_g_fmt_mplane,
  1052. .vidioc_try_fmt_vid_cap_mplane = fimc_vidioc_try_fmt_mplane,
  1053. .vidioc_try_fmt_vid_out_mplane = fimc_vidioc_try_fmt_mplane,
  1054. .vidioc_s_fmt_vid_cap_mplane = fimc_m2m_s_fmt_mplane,
  1055. .vidioc_s_fmt_vid_out_mplane = fimc_m2m_s_fmt_mplane,
  1056. .vidioc_reqbufs = fimc_m2m_reqbufs,
  1057. .vidioc_querybuf = fimc_m2m_querybuf,
  1058. .vidioc_qbuf = fimc_m2m_qbuf,
  1059. .vidioc_dqbuf = fimc_m2m_dqbuf,
  1060. .vidioc_streamon = fimc_m2m_streamon,
  1061. .vidioc_streamoff = fimc_m2m_streamoff,
  1062. .vidioc_queryctrl = fimc_vidioc_queryctrl,
  1063. .vidioc_g_ctrl = fimc_vidioc_g_ctrl,
  1064. .vidioc_s_ctrl = fimc_m2m_s_ctrl,
  1065. .vidioc_g_crop = fimc_m2m_g_crop,
  1066. .vidioc_s_crop = fimc_m2m_s_crop,
  1067. .vidioc_cropcap = fimc_m2m_cropcap
  1068. };
  1069. static int queue_init(void *priv, struct vb2_queue *src_vq,
  1070. struct vb2_queue *dst_vq)
  1071. {
  1072. struct fimc_ctx *ctx = priv;
  1073. int ret;
  1074. memset(src_vq, 0, sizeof(*src_vq));
  1075. src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
  1076. src_vq->io_modes = VB2_MMAP | VB2_USERPTR;
  1077. src_vq->drv_priv = ctx;
  1078. src_vq->ops = &fimc_qops;
  1079. src_vq->mem_ops = &vb2_dma_contig_memops;
  1080. src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
  1081. ret = vb2_queue_init(src_vq);
  1082. if (ret)
  1083. return ret;
  1084. memset(dst_vq, 0, sizeof(*dst_vq));
  1085. dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
  1086. dst_vq->io_modes = VB2_MMAP | VB2_USERPTR;
  1087. dst_vq->drv_priv = ctx;
  1088. dst_vq->ops = &fimc_qops;
  1089. dst_vq->mem_ops = &vb2_dma_contig_memops;
  1090. dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
  1091. return vb2_queue_init(dst_vq);
  1092. }
  1093. static int fimc_m2m_open(struct file *file)
  1094. {
  1095. struct fimc_dev *fimc = video_drvdata(file);
  1096. struct fimc_ctx *ctx = NULL;
  1097. dbg("pid: %d, state: 0x%lx, refcnt: %d",
  1098. task_pid_nr(current), fimc->state, fimc->vid_cap.refcnt);
  1099. /*
  1100. * Return if the corresponding video capture node
  1101. * is already opened.
  1102. */
  1103. if (fimc->vid_cap.refcnt > 0)
  1104. return -EBUSY;
  1105. fimc->m2m.refcnt++;
  1106. set_bit(ST_OUTDMA_RUN, &fimc->state);
  1107. ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
  1108. if (!ctx)
  1109. return -ENOMEM;
  1110. file->private_data = ctx;
  1111. ctx->fimc_dev = fimc;
  1112. /* Default color format */
  1113. ctx->s_frame.fmt = &fimc_formats[0];
  1114. ctx->d_frame.fmt = &fimc_formats[0];
  1115. /* Setup the device context for mem2mem mode. */
  1116. ctx->state = FIMC_CTX_M2M;
  1117. ctx->flags = 0;
  1118. ctx->in_path = FIMC_DMA;
  1119. ctx->out_path = FIMC_DMA;
  1120. spin_lock_init(&ctx->slock);
  1121. ctx->m2m_ctx = v4l2_m2m_ctx_init(fimc->m2m.m2m_dev, ctx, queue_init);
  1122. if (IS_ERR(ctx->m2m_ctx)) {
  1123. int err = PTR_ERR(ctx->m2m_ctx);
  1124. kfree(ctx);
  1125. return err;
  1126. }
  1127. return 0;
  1128. }
  1129. static int fimc_m2m_release(struct file *file)
  1130. {
  1131. struct fimc_ctx *ctx = file->private_data;
  1132. struct fimc_dev *fimc = ctx->fimc_dev;
  1133. dbg("pid: %d, state: 0x%lx, refcnt= %d",
  1134. task_pid_nr(current), fimc->state, fimc->m2m.refcnt);
  1135. v4l2_m2m_ctx_release(ctx->m2m_ctx);
  1136. kfree(ctx);
  1137. if (--fimc->m2m.refcnt <= 0)
  1138. clear_bit(ST_OUTDMA_RUN, &fimc->state);
  1139. return 0;
  1140. }
  1141. static unsigned int fimc_m2m_poll(struct file *file,
  1142. struct poll_table_struct *wait)
  1143. {
  1144. struct fimc_ctx *ctx = file->private_data;
  1145. return v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
  1146. }
  1147. static int fimc_m2m_mmap(struct file *file, struct vm_area_struct *vma)
  1148. {
  1149. struct fimc_ctx *ctx = file->private_data;
  1150. return v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);
  1151. }
  1152. static const struct v4l2_file_operations fimc_m2m_fops = {
  1153. .owner = THIS_MODULE,
  1154. .open = fimc_m2m_open,
  1155. .release = fimc_m2m_release,
  1156. .poll = fimc_m2m_poll,
  1157. .unlocked_ioctl = video_ioctl2,
  1158. .mmap = fimc_m2m_mmap,
  1159. };
  1160. static struct v4l2_m2m_ops m2m_ops = {
  1161. .device_run = fimc_dma_run,
  1162. .job_abort = fimc_job_abort,
  1163. };
  1164. static int fimc_register_m2m_device(struct fimc_dev *fimc)
  1165. {
  1166. struct video_device *vfd;
  1167. struct platform_device *pdev;
  1168. struct v4l2_device *v4l2_dev;
  1169. int ret = 0;
  1170. if (!fimc)
  1171. return -ENODEV;
  1172. pdev = fimc->pdev;
  1173. v4l2_dev = &fimc->m2m.v4l2_dev;
  1174. /* set name if it is empty */
  1175. if (!v4l2_dev->name[0])
  1176. snprintf(v4l2_dev->name, sizeof(v4l2_dev->name),
  1177. "%s.m2m", dev_name(&pdev->dev));
  1178. ret = v4l2_device_register(&pdev->dev, v4l2_dev);
  1179. if (ret)
  1180. goto err_m2m_r1;
  1181. vfd = video_device_alloc();
  1182. if (!vfd) {
  1183. v4l2_err(v4l2_dev, "Failed to allocate video device\n");
  1184. goto err_m2m_r1;
  1185. }
  1186. vfd->fops = &fimc_m2m_fops;
  1187. vfd->ioctl_ops = &fimc_m2m_ioctl_ops;
  1188. vfd->minor = -1;
  1189. vfd->release = video_device_release;
  1190. vfd->lock = &fimc->lock;
  1191. snprintf(vfd->name, sizeof(vfd->name), "%s:m2m", dev_name(&pdev->dev));
  1192. video_set_drvdata(vfd, fimc);
  1193. platform_set_drvdata(pdev, fimc);
  1194. fimc->m2m.vfd = vfd;
  1195. fimc->m2m.m2m_dev = v4l2_m2m_init(&m2m_ops);
  1196. if (IS_ERR(fimc->m2m.m2m_dev)) {
  1197. v4l2_err(v4l2_dev, "failed to initialize v4l2-m2m device\n");
  1198. ret = PTR_ERR(fimc->m2m.m2m_dev);
  1199. goto err_m2m_r2;
  1200. }
  1201. ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
  1202. if (ret) {
  1203. v4l2_err(v4l2_dev,
  1204. "%s(): failed to register video device\n", __func__);
  1205. goto err_m2m_r3;
  1206. }
  1207. v4l2_info(v4l2_dev,
  1208. "FIMC m2m driver registered as /dev/video%d\n", vfd->num);
  1209. return 0;
  1210. err_m2m_r3:
  1211. v4l2_m2m_release(fimc->m2m.m2m_dev);
  1212. err_m2m_r2:
  1213. video_device_release(fimc->m2m.vfd);
  1214. err_m2m_r1:
  1215. v4l2_device_unregister(v4l2_dev);
  1216. return ret;
  1217. }
  1218. static void fimc_unregister_m2m_device(struct fimc_dev *fimc)
  1219. {
  1220. if (fimc) {
  1221. v4l2_m2m_release(fimc->m2m.m2m_dev);
  1222. video_unregister_device(fimc->m2m.vfd);
  1223. v4l2_device_unregister(&fimc->m2m.v4l2_dev);
  1224. }
  1225. }
  1226. static void fimc_clk_release(struct fimc_dev *fimc)
  1227. {
  1228. int i;
  1229. for (i = 0; i < NUM_FIMC_CLOCKS; i++) {
  1230. if (fimc->clock[i]) {
  1231. clk_disable(fimc->clock[i]);
  1232. clk_put(fimc->clock[i]);
  1233. }
  1234. }
  1235. }
  1236. static int fimc_clk_get(struct fimc_dev *fimc)
  1237. {
  1238. int i;
  1239. for (i = 0; i < NUM_FIMC_CLOCKS; i++) {
  1240. fimc->clock[i] = clk_get(&fimc->pdev->dev, fimc_clock_name[i]);
  1241. if (IS_ERR(fimc->clock[i])) {
  1242. dev_err(&fimc->pdev->dev,
  1243. "failed to get fimc clock: %s\n",
  1244. fimc_clock_name[i]);
  1245. return -ENXIO;
  1246. }
  1247. clk_enable(fimc->clock[i]);
  1248. }
  1249. return 0;
  1250. }
  1251. static int fimc_probe(struct platform_device *pdev)
  1252. {
  1253. struct fimc_dev *fimc;
  1254. struct resource *res;
  1255. struct samsung_fimc_driverdata *drv_data;
  1256. int ret = 0;
  1257. dev_dbg(&pdev->dev, "%s():\n", __func__);
  1258. drv_data = (struct samsung_fimc_driverdata *)
  1259. platform_get_device_id(pdev)->driver_data;
  1260. if (pdev->id >= drv_data->num_entities) {
  1261. dev_err(&pdev->dev, "Invalid platform device id: %d\n",
  1262. pdev->id);
  1263. return -EINVAL;
  1264. }
  1265. fimc = kzalloc(sizeof(struct fimc_dev), GFP_KERNEL);
  1266. if (!fimc)
  1267. return -ENOMEM;
  1268. fimc->id = pdev->id;
  1269. fimc->variant = drv_data->variant[fimc->id];
  1270. fimc->pdev = pdev;
  1271. fimc->pdata = pdev->dev.platform_data;
  1272. fimc->state = ST_IDLE;
  1273. init_waitqueue_head(&fimc->irq_queue);
  1274. spin_lock_init(&fimc->slock);
  1275. mutex_init(&fimc->lock);
  1276. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1277. if (!res) {
  1278. dev_err(&pdev->dev, "failed to find the registers\n");
  1279. ret = -ENOENT;
  1280. goto err_info;
  1281. }
  1282. fimc->regs_res = request_mem_region(res->start, resource_size(res),
  1283. dev_name(&pdev->dev));
  1284. if (!fimc->regs_res) {
  1285. dev_err(&pdev->dev, "failed to obtain register region\n");
  1286. ret = -ENOENT;
  1287. goto err_info;
  1288. }
  1289. fimc->regs = ioremap(res->start, resource_size(res));
  1290. if (!fimc->regs) {
  1291. dev_err(&pdev->dev, "failed to map registers\n");
  1292. ret = -ENXIO;
  1293. goto err_req_region;
  1294. }
  1295. ret = fimc_clk_get(fimc);
  1296. if (ret)
  1297. goto err_regs_unmap;
  1298. clk_set_rate(fimc->clock[0], drv_data->lclk_frequency);
  1299. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1300. if (!res) {
  1301. dev_err(&pdev->dev, "failed to get IRQ resource\n");
  1302. ret = -ENXIO;
  1303. goto err_clk;
  1304. }
  1305. fimc->irq = res->start;
  1306. fimc_hw_reset(fimc);
  1307. ret = request_irq(fimc->irq, fimc_isr, 0, pdev->name, fimc);
  1308. if (ret) {
  1309. dev_err(&pdev->dev, "failed to install irq (%d)\n", ret);
  1310. goto err_clk;
  1311. }
  1312. /* Initialize contiguous memory allocator */
  1313. fimc->alloc_ctx = vb2_dma_contig_init_ctx(&fimc->pdev->dev);
  1314. if (IS_ERR(fimc->alloc_ctx)) {
  1315. ret = PTR_ERR(fimc->alloc_ctx);
  1316. goto err_irq;
  1317. }
  1318. ret = fimc_register_m2m_device(fimc);
  1319. if (ret)
  1320. goto err_irq;
  1321. /* At least one camera sensor is required to register capture node */
  1322. if (fimc->pdata) {
  1323. int i;
  1324. for (i = 0; i < FIMC_MAX_CAMIF_CLIENTS; ++i)
  1325. if (fimc->pdata->isp_info[i])
  1326. break;
  1327. if (i < FIMC_MAX_CAMIF_CLIENTS) {
  1328. ret = fimc_register_capture_device(fimc);
  1329. if (ret)
  1330. goto err_m2m;
  1331. }
  1332. }
  1333. /*
  1334. * Exclude the additional output DMA address registers by masking
  1335. * them out on HW revisions that provide extended capabilites.
  1336. */
  1337. if (fimc->variant->out_buf_count > 4)
  1338. fimc_hw_set_dma_seq(fimc, 0xF);
  1339. dev_dbg(&pdev->dev, "%s(): fimc-%d registered successfully\n",
  1340. __func__, fimc->id);
  1341. return 0;
  1342. err_m2m:
  1343. fimc_unregister_m2m_device(fimc);
  1344. err_irq:
  1345. free_irq(fimc->irq, fimc);
  1346. err_clk:
  1347. fimc_clk_release(fimc);
  1348. err_regs_unmap:
  1349. iounmap(fimc->regs);
  1350. err_req_region:
  1351. release_resource(fimc->regs_res);
  1352. kfree(fimc->regs_res);
  1353. err_info:
  1354. kfree(fimc);
  1355. return ret;
  1356. }
  1357. static int __devexit fimc_remove(struct platform_device *pdev)
  1358. {
  1359. struct fimc_dev *fimc =
  1360. (struct fimc_dev *)platform_get_drvdata(pdev);
  1361. free_irq(fimc->irq, fimc);
  1362. fimc_hw_reset(fimc);
  1363. fimc_unregister_m2m_device(fimc);
  1364. fimc_unregister_capture_device(fimc);
  1365. fimc_clk_release(fimc);
  1366. vb2_dma_contig_cleanup_ctx(fimc->alloc_ctx);
  1367. iounmap(fimc->regs);
  1368. release_resource(fimc->regs_res);
  1369. kfree(fimc->regs_res);
  1370. kfree(fimc);
  1371. dev_info(&pdev->dev, "%s driver unloaded\n", pdev->name);
  1372. return 0;
  1373. }
  1374. /* Image pixel limits, similar across several FIMC HW revisions. */
  1375. static struct fimc_pix_limit s5p_pix_limit[3] = {
  1376. [0] = {
  1377. .scaler_en_w = 3264,
  1378. .scaler_dis_w = 8192,
  1379. .in_rot_en_h = 1920,
  1380. .in_rot_dis_w = 8192,
  1381. .out_rot_en_w = 1920,
  1382. .out_rot_dis_w = 4224,
  1383. },
  1384. [1] = {
  1385. .scaler_en_w = 4224,
  1386. .scaler_dis_w = 8192,
  1387. .in_rot_en_h = 1920,
  1388. .in_rot_dis_w = 8192,
  1389. .out_rot_en_w = 1920,
  1390. .out_rot_dis_w = 4224,
  1391. },
  1392. [2] = {
  1393. .scaler_en_w = 1920,
  1394. .scaler_dis_w = 8192,
  1395. .in_rot_en_h = 1280,
  1396. .in_rot_dis_w = 8192,
  1397. .out_rot_en_w = 1280,
  1398. .out_rot_dis_w = 1920,
  1399. },
  1400. };
  1401. static struct samsung_fimc_variant fimc0_variant_s5p = {
  1402. .has_inp_rot = 1,
  1403. .has_out_rot = 1,
  1404. .min_inp_pixsize = 16,
  1405. .min_out_pixsize = 16,
  1406. .hor_offs_align = 8,
  1407. .out_buf_count = 4,
  1408. .pix_limit = &s5p_pix_limit[0],
  1409. };
  1410. static struct samsung_fimc_variant fimc2_variant_s5p = {
  1411. .min_inp_pixsize = 16,
  1412. .min_out_pixsize = 16,
  1413. .hor_offs_align = 8,
  1414. .out_buf_count = 4,
  1415. .pix_limit = &s5p_pix_limit[1],
  1416. };
  1417. static struct samsung_fimc_variant fimc0_variant_s5pv210 = {
  1418. .pix_hoff = 1,
  1419. .has_inp_rot = 1,
  1420. .has_out_rot = 1,
  1421. .min_inp_pixsize = 16,
  1422. .min_out_pixsize = 16,
  1423. .hor_offs_align = 8,
  1424. .out_buf_count = 4,
  1425. .pix_limit = &s5p_pix_limit[1],
  1426. };
  1427. static struct samsung_fimc_variant fimc1_variant_s5pv210 = {
  1428. .pix_hoff = 1,
  1429. .has_inp_rot = 1,
  1430. .has_out_rot = 1,
  1431. .min_inp_pixsize = 16,
  1432. .min_out_pixsize = 16,
  1433. .hor_offs_align = 1,
  1434. .out_buf_count = 4,
  1435. .pix_limit = &s5p_pix_limit[2],
  1436. };
  1437. static struct samsung_fimc_variant fimc2_variant_s5pv210 = {
  1438. .pix_hoff = 1,
  1439. .min_inp_pixsize = 16,
  1440. .min_out_pixsize = 16,
  1441. .hor_offs_align = 8,
  1442. .out_buf_count = 4,
  1443. .pix_limit = &s5p_pix_limit[2],
  1444. };
  1445. static struct samsung_fimc_variant fimc0_variant_s5pv310 = {
  1446. .pix_hoff = 1,
  1447. .has_inp_rot = 1,
  1448. .has_out_rot = 1,
  1449. .has_cistatus2 = 1,
  1450. .min_inp_pixsize = 16,
  1451. .min_out_pixsize = 16,
  1452. .hor_offs_align = 1,
  1453. .out_buf_count = 32,
  1454. .pix_limit = &s5p_pix_limit[1],
  1455. };
  1456. static struct samsung_fimc_variant fimc2_variant_s5pv310 = {
  1457. .pix_hoff = 1,
  1458. .has_cistatus2 = 1,
  1459. .min_inp_pixsize = 16,
  1460. .min_out_pixsize = 16,
  1461. .hor_offs_align = 1,
  1462. .out_buf_count = 32,
  1463. .pix_limit = &s5p_pix_limit[2],
  1464. };
  1465. /* S5PC100 */
  1466. static struct samsung_fimc_driverdata fimc_drvdata_s5p = {
  1467. .variant = {
  1468. [0] = &fimc0_variant_s5p,
  1469. [1] = &fimc0_variant_s5p,
  1470. [2] = &fimc2_variant_s5p,
  1471. },
  1472. .num_entities = 3,
  1473. .lclk_frequency = 133000000UL,
  1474. };
  1475. /* S5PV210, S5PC110 */
  1476. static struct samsung_fimc_driverdata fimc_drvdata_s5pv210 = {
  1477. .variant = {
  1478. [0] = &fimc0_variant_s5pv210,
  1479. [1] = &fimc1_variant_s5pv210,
  1480. [2] = &fimc2_variant_s5pv210,
  1481. },
  1482. .num_entities = 3,
  1483. .lclk_frequency = 166000000UL,
  1484. };
  1485. /* S5PV310, S5PC210 */
  1486. static struct samsung_fimc_driverdata fimc_drvdata_s5pv310 = {
  1487. .variant = {
  1488. [0] = &fimc0_variant_s5pv310,
  1489. [1] = &fimc0_variant_s5pv310,
  1490. [2] = &fimc0_variant_s5pv310,
  1491. [3] = &fimc2_variant_s5pv310,
  1492. },
  1493. .num_entities = 4,
  1494. .lclk_frequency = 166000000UL,
  1495. };
  1496. static struct platform_device_id fimc_driver_ids[] = {
  1497. {
  1498. .name = "s5p-fimc",
  1499. .driver_data = (unsigned long)&fimc_drvdata_s5p,
  1500. }, {
  1501. .name = "s5pv210-fimc",
  1502. .driver_data = (unsigned long)&fimc_drvdata_s5pv210,
  1503. }, {
  1504. .name = "s5pv310-fimc",
  1505. .driver_data = (unsigned long)&fimc_drvdata_s5pv310,
  1506. },
  1507. {},
  1508. };
  1509. MODULE_DEVICE_TABLE(platform, fimc_driver_ids);
  1510. static struct platform_driver fimc_driver = {
  1511. .probe = fimc_probe,
  1512. .remove = __devexit_p(fimc_remove),
  1513. .id_table = fimc_driver_ids,
  1514. .driver = {
  1515. .name = MODULE_NAME,
  1516. .owner = THIS_MODULE,
  1517. }
  1518. };
  1519. static int __init fimc_init(void)
  1520. {
  1521. int ret = platform_driver_register(&fimc_driver);
  1522. if (ret)
  1523. err("platform_driver_register failed: %d\n", ret);
  1524. return ret;
  1525. }
  1526. static void __exit fimc_exit(void)
  1527. {
  1528. platform_driver_unregister(&fimc_driver);
  1529. }
  1530. module_init(fimc_init);
  1531. module_exit(fimc_exit);
  1532. MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
  1533. MODULE_DESCRIPTION("S5P FIMC camera host interface/video postprocessor driver");
  1534. MODULE_LICENSE("GPL");