fimc-core.c 43 KB

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