fimc-core.c 44 KB

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