fimc-core.c 45 KB

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