fimc-core.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  1. /*
  2. * Samsung S5P/EXYNOS4 SoC series FIMC (CAMIF) driver
  3. *
  4. * Copyright (C) 2010-2012 Samsung Electronics Co., Ltd.
  5. * Sylwester Nawrocki <s.nawrocki@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published
  9. * by the Free Software Foundation, either version 2 of the License,
  10. * or (at your option) any later version.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/types.h>
  15. #include <linux/errno.h>
  16. #include <linux/bug.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/device.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/pm_runtime.h>
  21. #include <linux/list.h>
  22. #include <linux/io.h>
  23. #include <linux/slab.h>
  24. #include <linux/clk.h>
  25. #include <media/v4l2-ioctl.h>
  26. #include <media/videobuf2-core.h>
  27. #include <media/videobuf2-dma-contig.h>
  28. #include "fimc-core.h"
  29. #include "fimc-reg.h"
  30. #include "fimc-mdevice.h"
  31. static char *fimc_clocks[MAX_FIMC_CLOCKS] = {
  32. "sclk_fimc", "fimc"
  33. };
  34. static struct fimc_fmt fimc_formats[] = {
  35. {
  36. .name = "RGB565",
  37. .fourcc = V4L2_PIX_FMT_RGB565,
  38. .depth = { 16 },
  39. .color = FIMC_FMT_RGB565,
  40. .memplanes = 1,
  41. .colplanes = 1,
  42. .flags = FMT_FLAGS_M2M,
  43. }, {
  44. .name = "BGR666",
  45. .fourcc = V4L2_PIX_FMT_BGR666,
  46. .depth = { 32 },
  47. .color = FIMC_FMT_RGB666,
  48. .memplanes = 1,
  49. .colplanes = 1,
  50. .flags = FMT_FLAGS_M2M,
  51. }, {
  52. .name = "ARGB8888, 32 bpp",
  53. .fourcc = V4L2_PIX_FMT_RGB32,
  54. .depth = { 32 },
  55. .color = FIMC_FMT_RGB888,
  56. .memplanes = 1,
  57. .colplanes = 1,
  58. .flags = FMT_FLAGS_M2M | FMT_HAS_ALPHA,
  59. }, {
  60. .name = "ARGB1555",
  61. .fourcc = V4L2_PIX_FMT_RGB555,
  62. .depth = { 16 },
  63. .color = FIMC_FMT_RGB555,
  64. .memplanes = 1,
  65. .colplanes = 1,
  66. .flags = FMT_FLAGS_M2M_OUT | FMT_HAS_ALPHA,
  67. }, {
  68. .name = "ARGB4444",
  69. .fourcc = V4L2_PIX_FMT_RGB444,
  70. .depth = { 16 },
  71. .color = FIMC_FMT_RGB444,
  72. .memplanes = 1,
  73. .colplanes = 1,
  74. .flags = FMT_FLAGS_M2M_OUT | FMT_HAS_ALPHA,
  75. }, {
  76. .name = "YUV 4:2:2 packed, YCbYCr",
  77. .fourcc = V4L2_PIX_FMT_YUYV,
  78. .depth = { 16 },
  79. .color = FIMC_FMT_YCBYCR422,
  80. .memplanes = 1,
  81. .colplanes = 1,
  82. .mbus_code = V4L2_MBUS_FMT_YUYV8_2X8,
  83. .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM,
  84. }, {
  85. .name = "YUV 4:2:2 packed, CbYCrY",
  86. .fourcc = V4L2_PIX_FMT_UYVY,
  87. .depth = { 16 },
  88. .color = FIMC_FMT_CBYCRY422,
  89. .memplanes = 1,
  90. .colplanes = 1,
  91. .mbus_code = V4L2_MBUS_FMT_UYVY8_2X8,
  92. .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM,
  93. }, {
  94. .name = "YUV 4:2:2 packed, CrYCbY",
  95. .fourcc = V4L2_PIX_FMT_VYUY,
  96. .depth = { 16 },
  97. .color = FIMC_FMT_CRYCBY422,
  98. .memplanes = 1,
  99. .colplanes = 1,
  100. .mbus_code = V4L2_MBUS_FMT_VYUY8_2X8,
  101. .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM,
  102. }, {
  103. .name = "YUV 4:2:2 packed, YCrYCb",
  104. .fourcc = V4L2_PIX_FMT_YVYU,
  105. .depth = { 16 },
  106. .color = FIMC_FMT_YCRYCB422,
  107. .memplanes = 1,
  108. .colplanes = 1,
  109. .mbus_code = V4L2_MBUS_FMT_YVYU8_2X8,
  110. .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM,
  111. }, {
  112. .name = "YUV 4:2:2 planar, Y/Cb/Cr",
  113. .fourcc = V4L2_PIX_FMT_YUV422P,
  114. .depth = { 12 },
  115. .color = FIMC_FMT_YCBYCR422,
  116. .memplanes = 1,
  117. .colplanes = 3,
  118. .flags = FMT_FLAGS_M2M,
  119. }, {
  120. .name = "YUV 4:2:2 planar, Y/CbCr",
  121. .fourcc = V4L2_PIX_FMT_NV16,
  122. .depth = { 16 },
  123. .color = FIMC_FMT_YCBYCR422,
  124. .memplanes = 1,
  125. .colplanes = 2,
  126. .flags = FMT_FLAGS_M2M,
  127. }, {
  128. .name = "YUV 4:2:2 planar, Y/CrCb",
  129. .fourcc = V4L2_PIX_FMT_NV61,
  130. .depth = { 16 },
  131. .color = FIMC_FMT_YCRYCB422,
  132. .memplanes = 1,
  133. .colplanes = 2,
  134. .flags = FMT_FLAGS_M2M,
  135. }, {
  136. .name = "YUV 4:2:0 planar, YCbCr",
  137. .fourcc = V4L2_PIX_FMT_YUV420,
  138. .depth = { 12 },
  139. .color = FIMC_FMT_YCBCR420,
  140. .memplanes = 1,
  141. .colplanes = 3,
  142. .flags = FMT_FLAGS_M2M,
  143. }, {
  144. .name = "YUV 4:2:0 planar, Y/CbCr",
  145. .fourcc = V4L2_PIX_FMT_NV12,
  146. .depth = { 12 },
  147. .color = FIMC_FMT_YCBCR420,
  148. .memplanes = 1,
  149. .colplanes = 2,
  150. .flags = FMT_FLAGS_M2M,
  151. }, {
  152. .name = "YUV 4:2:0 non-contig. 2p, Y/CbCr",
  153. .fourcc = V4L2_PIX_FMT_NV12M,
  154. .color = FIMC_FMT_YCBCR420,
  155. .depth = { 8, 4 },
  156. .memplanes = 2,
  157. .colplanes = 2,
  158. .flags = FMT_FLAGS_M2M,
  159. }, {
  160. .name = "YUV 4:2:0 non-contig. 3p, Y/Cb/Cr",
  161. .fourcc = V4L2_PIX_FMT_YUV420M,
  162. .color = FIMC_FMT_YCBCR420,
  163. .depth = { 8, 2, 2 },
  164. .memplanes = 3,
  165. .colplanes = 3,
  166. .flags = FMT_FLAGS_M2M,
  167. }, {
  168. .name = "YUV 4:2:0 non-contig. 2p, tiled",
  169. .fourcc = V4L2_PIX_FMT_NV12MT,
  170. .color = FIMC_FMT_YCBCR420,
  171. .depth = { 8, 4 },
  172. .memplanes = 2,
  173. .colplanes = 2,
  174. .flags = FMT_FLAGS_M2M,
  175. }, {
  176. .name = "JPEG encoded data",
  177. .fourcc = V4L2_PIX_FMT_JPEG,
  178. .color = FIMC_FMT_JPEG,
  179. .depth = { 8 },
  180. .memplanes = 1,
  181. .colplanes = 1,
  182. .mbus_code = V4L2_MBUS_FMT_JPEG_1X8,
  183. .flags = FMT_FLAGS_CAM,
  184. },
  185. };
  186. struct fimc_fmt *fimc_get_format(unsigned int index)
  187. {
  188. if (index >= ARRAY_SIZE(fimc_formats))
  189. return NULL;
  190. return &fimc_formats[index];
  191. }
  192. int fimc_check_scaler_ratio(struct fimc_ctx *ctx, int sw, int sh,
  193. int dw, int dh, int rotation)
  194. {
  195. if (rotation == 90 || rotation == 270)
  196. swap(dw, dh);
  197. if (!ctx->scaler.enabled)
  198. return (sw == dw && sh == dh) ? 0 : -EINVAL;
  199. if ((sw >= SCALER_MAX_HRATIO * dw) || (sh >= SCALER_MAX_VRATIO * dh))
  200. return -EINVAL;
  201. return 0;
  202. }
  203. static int fimc_get_scaler_factor(u32 src, u32 tar, u32 *ratio, u32 *shift)
  204. {
  205. u32 sh = 6;
  206. if (src >= 64 * tar)
  207. return -EINVAL;
  208. while (sh--) {
  209. u32 tmp = 1 << sh;
  210. if (src >= tar * tmp) {
  211. *shift = sh, *ratio = tmp;
  212. return 0;
  213. }
  214. }
  215. *shift = 0, *ratio = 1;
  216. return 0;
  217. }
  218. int fimc_set_scaler_info(struct fimc_ctx *ctx)
  219. {
  220. struct fimc_variant *variant = ctx->fimc_dev->variant;
  221. struct device *dev = &ctx->fimc_dev->pdev->dev;
  222. struct fimc_scaler *sc = &ctx->scaler;
  223. struct fimc_frame *s_frame = &ctx->s_frame;
  224. struct fimc_frame *d_frame = &ctx->d_frame;
  225. int tx, ty, sx, sy;
  226. int ret;
  227. if (ctx->rotation == 90 || ctx->rotation == 270) {
  228. ty = d_frame->width;
  229. tx = d_frame->height;
  230. } else {
  231. tx = d_frame->width;
  232. ty = d_frame->height;
  233. }
  234. if (tx <= 0 || ty <= 0) {
  235. dev_err(dev, "Invalid target size: %dx%d", tx, ty);
  236. return -EINVAL;
  237. }
  238. sx = s_frame->width;
  239. sy = s_frame->height;
  240. if (sx <= 0 || sy <= 0) {
  241. dev_err(dev, "Invalid source size: %dx%d", sx, sy);
  242. return -EINVAL;
  243. }
  244. sc->real_width = sx;
  245. sc->real_height = sy;
  246. ret = fimc_get_scaler_factor(sx, tx, &sc->pre_hratio, &sc->hfactor);
  247. if (ret)
  248. return ret;
  249. ret = fimc_get_scaler_factor(sy, ty, &sc->pre_vratio, &sc->vfactor);
  250. if (ret)
  251. return ret;
  252. sc->pre_dst_width = sx / sc->pre_hratio;
  253. sc->pre_dst_height = sy / sc->pre_vratio;
  254. if (variant->has_mainscaler_ext) {
  255. sc->main_hratio = (sx << 14) / (tx << sc->hfactor);
  256. sc->main_vratio = (sy << 14) / (ty << sc->vfactor);
  257. } else {
  258. sc->main_hratio = (sx << 8) / (tx << sc->hfactor);
  259. sc->main_vratio = (sy << 8) / (ty << sc->vfactor);
  260. }
  261. sc->scaleup_h = (tx >= sx) ? 1 : 0;
  262. sc->scaleup_v = (ty >= sy) ? 1 : 0;
  263. /* check to see if input and output size/format differ */
  264. if (s_frame->fmt->color == d_frame->fmt->color
  265. && s_frame->width == d_frame->width
  266. && s_frame->height == d_frame->height)
  267. sc->copy_mode = 1;
  268. else
  269. sc->copy_mode = 0;
  270. return 0;
  271. }
  272. static irqreturn_t fimc_irq_handler(int irq, void *priv)
  273. {
  274. struct fimc_dev *fimc = priv;
  275. struct fimc_ctx *ctx;
  276. fimc_hw_clear_irq(fimc);
  277. spin_lock(&fimc->slock);
  278. if (test_and_clear_bit(ST_M2M_PEND, &fimc->state)) {
  279. if (test_and_clear_bit(ST_M2M_SUSPENDING, &fimc->state)) {
  280. set_bit(ST_M2M_SUSPENDED, &fimc->state);
  281. wake_up(&fimc->irq_queue);
  282. goto out;
  283. }
  284. ctx = v4l2_m2m_get_curr_priv(fimc->m2m.m2m_dev);
  285. if (ctx != NULL) {
  286. spin_unlock(&fimc->slock);
  287. fimc_m2m_job_finish(ctx, VB2_BUF_STATE_DONE);
  288. if (ctx->state & FIMC_CTX_SHUT) {
  289. ctx->state &= ~FIMC_CTX_SHUT;
  290. wake_up(&fimc->irq_queue);
  291. }
  292. return IRQ_HANDLED;
  293. }
  294. } else if (test_bit(ST_CAPT_PEND, &fimc->state)) {
  295. int last_buf = test_bit(ST_CAPT_JPEG, &fimc->state) &&
  296. fimc->vid_cap.reqbufs_count == 1;
  297. fimc_capture_irq_handler(fimc, !last_buf);
  298. }
  299. out:
  300. spin_unlock(&fimc->slock);
  301. return IRQ_HANDLED;
  302. }
  303. /* The color format (colplanes, memplanes) must be already configured. */
  304. int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
  305. struct fimc_frame *frame, struct fimc_addr *paddr)
  306. {
  307. int ret = 0;
  308. u32 pix_size;
  309. if (vb == NULL || frame == NULL)
  310. return -EINVAL;
  311. pix_size = frame->width * frame->height;
  312. dbg("memplanes= %d, colplanes= %d, pix_size= %d",
  313. frame->fmt->memplanes, frame->fmt->colplanes, pix_size);
  314. paddr->y = vb2_dma_contig_plane_dma_addr(vb, 0);
  315. if (frame->fmt->memplanes == 1) {
  316. switch (frame->fmt->colplanes) {
  317. case 1:
  318. paddr->cb = 0;
  319. paddr->cr = 0;
  320. break;
  321. case 2:
  322. /* decompose Y into Y/Cb */
  323. paddr->cb = (u32)(paddr->y + pix_size);
  324. paddr->cr = 0;
  325. break;
  326. case 3:
  327. paddr->cb = (u32)(paddr->y + pix_size);
  328. /* decompose Y into Y/Cb/Cr */
  329. if (FIMC_FMT_YCBCR420 == frame->fmt->color)
  330. paddr->cr = (u32)(paddr->cb
  331. + (pix_size >> 2));
  332. else /* 422 */
  333. paddr->cr = (u32)(paddr->cb
  334. + (pix_size >> 1));
  335. break;
  336. default:
  337. return -EINVAL;
  338. }
  339. } else {
  340. if (frame->fmt->memplanes >= 2)
  341. paddr->cb = vb2_dma_contig_plane_dma_addr(vb, 1);
  342. if (frame->fmt->memplanes == 3)
  343. paddr->cr = vb2_dma_contig_plane_dma_addr(vb, 2);
  344. }
  345. dbg("PHYS_ADDR: y= 0x%X cb= 0x%X cr= 0x%X ret= %d",
  346. paddr->y, paddr->cb, paddr->cr, ret);
  347. return ret;
  348. }
  349. /* Set order for 1 and 2 plane YCBCR 4:2:2 formats. */
  350. void fimc_set_yuv_order(struct fimc_ctx *ctx)
  351. {
  352. /* The one only mode supported in SoC. */
  353. ctx->in_order_2p = FIMC_REG_CIOCTRL_ORDER422_2P_LSB_CRCB;
  354. ctx->out_order_2p = FIMC_REG_CIOCTRL_ORDER422_2P_LSB_CRCB;
  355. /* Set order for 1 plane input formats. */
  356. switch (ctx->s_frame.fmt->color) {
  357. case FIMC_FMT_YCRYCB422:
  358. ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_CBYCRY;
  359. break;
  360. case FIMC_FMT_CBYCRY422:
  361. ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_YCRYCB;
  362. break;
  363. case FIMC_FMT_CRYCBY422:
  364. ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_YCBYCR;
  365. break;
  366. case FIMC_FMT_YCBYCR422:
  367. default:
  368. ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_CRYCBY;
  369. break;
  370. }
  371. dbg("ctx->in_order_1p= %d", ctx->in_order_1p);
  372. switch (ctx->d_frame.fmt->color) {
  373. case FIMC_FMT_YCRYCB422:
  374. ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_CBYCRY;
  375. break;
  376. case FIMC_FMT_CBYCRY422:
  377. ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_YCRYCB;
  378. break;
  379. case FIMC_FMT_CRYCBY422:
  380. ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_YCBYCR;
  381. break;
  382. case FIMC_FMT_YCBYCR422:
  383. default:
  384. ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_CRYCBY;
  385. break;
  386. }
  387. dbg("ctx->out_order_1p= %d", ctx->out_order_1p);
  388. }
  389. void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f)
  390. {
  391. struct fimc_variant *variant = ctx->fimc_dev->variant;
  392. u32 i, depth = 0;
  393. for (i = 0; i < f->fmt->colplanes; i++)
  394. depth += f->fmt->depth[i];
  395. f->dma_offset.y_h = f->offs_h;
  396. if (!variant->pix_hoff)
  397. f->dma_offset.y_h *= (depth >> 3);
  398. f->dma_offset.y_v = f->offs_v;
  399. f->dma_offset.cb_h = f->offs_h;
  400. f->dma_offset.cb_v = f->offs_v;
  401. f->dma_offset.cr_h = f->offs_h;
  402. f->dma_offset.cr_v = f->offs_v;
  403. if (!variant->pix_hoff) {
  404. if (f->fmt->colplanes == 3) {
  405. f->dma_offset.cb_h >>= 1;
  406. f->dma_offset.cr_h >>= 1;
  407. }
  408. if (f->fmt->color == FIMC_FMT_YCBCR420) {
  409. f->dma_offset.cb_v >>= 1;
  410. f->dma_offset.cr_v >>= 1;
  411. }
  412. }
  413. dbg("in_offset: color= %d, y_h= %d, y_v= %d",
  414. f->fmt->color, f->dma_offset.y_h, f->dma_offset.y_v);
  415. }
  416. int fimc_set_color_effect(struct fimc_ctx *ctx, enum v4l2_colorfx colorfx)
  417. {
  418. struct fimc_effect *effect = &ctx->effect;
  419. switch (colorfx) {
  420. case V4L2_COLORFX_NONE:
  421. effect->type = FIMC_REG_CIIMGEFF_FIN_BYPASS;
  422. break;
  423. case V4L2_COLORFX_BW:
  424. effect->type = FIMC_REG_CIIMGEFF_FIN_ARBITRARY;
  425. effect->pat_cb = 128;
  426. effect->pat_cr = 128;
  427. break;
  428. case V4L2_COLORFX_SEPIA:
  429. effect->type = FIMC_REG_CIIMGEFF_FIN_ARBITRARY;
  430. effect->pat_cb = 115;
  431. effect->pat_cr = 145;
  432. break;
  433. case V4L2_COLORFX_NEGATIVE:
  434. effect->type = FIMC_REG_CIIMGEFF_FIN_NEGATIVE;
  435. break;
  436. case V4L2_COLORFX_EMBOSS:
  437. effect->type = FIMC_REG_CIIMGEFF_FIN_EMBOSSING;
  438. break;
  439. case V4L2_COLORFX_ART_FREEZE:
  440. effect->type = FIMC_REG_CIIMGEFF_FIN_ARTFREEZE;
  441. break;
  442. case V4L2_COLORFX_SILHOUETTE:
  443. effect->type = FIMC_REG_CIIMGEFF_FIN_SILHOUETTE;
  444. break;
  445. case V4L2_COLORFX_SET_CBCR:
  446. effect->type = FIMC_REG_CIIMGEFF_FIN_ARBITRARY;
  447. effect->pat_cb = ctx->ctrls.colorfx_cbcr->val >> 8;
  448. effect->pat_cr = ctx->ctrls.colorfx_cbcr->val & 0xff;
  449. break;
  450. default:
  451. return -EINVAL;
  452. }
  453. return 0;
  454. }
  455. /*
  456. * V4L2 controls handling
  457. */
  458. #define ctrl_to_ctx(__ctrl) \
  459. container_of((__ctrl)->handler, struct fimc_ctx, ctrls.handler)
  460. static int __fimc_s_ctrl(struct fimc_ctx *ctx, struct v4l2_ctrl *ctrl)
  461. {
  462. struct fimc_dev *fimc = ctx->fimc_dev;
  463. struct fimc_variant *variant = fimc->variant;
  464. unsigned int flags = FIMC_DST_FMT | FIMC_SRC_FMT;
  465. int ret = 0;
  466. if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE)
  467. return 0;
  468. switch (ctrl->id) {
  469. case V4L2_CID_HFLIP:
  470. ctx->hflip = ctrl->val;
  471. break;
  472. case V4L2_CID_VFLIP:
  473. ctx->vflip = ctrl->val;
  474. break;
  475. case V4L2_CID_ROTATE:
  476. if (fimc_capture_pending(fimc) ||
  477. (ctx->state & flags) == flags) {
  478. ret = fimc_check_scaler_ratio(ctx, ctx->s_frame.width,
  479. ctx->s_frame.height, ctx->d_frame.width,
  480. ctx->d_frame.height, ctrl->val);
  481. if (ret)
  482. return -EINVAL;
  483. }
  484. if ((ctrl->val == 90 || ctrl->val == 270) &&
  485. !variant->has_out_rot)
  486. return -EINVAL;
  487. ctx->rotation = ctrl->val;
  488. break;
  489. case V4L2_CID_ALPHA_COMPONENT:
  490. ctx->d_frame.alpha = ctrl->val;
  491. break;
  492. case V4L2_CID_COLORFX:
  493. ret = fimc_set_color_effect(ctx, ctrl->val);
  494. if (ret)
  495. return ret;
  496. break;
  497. }
  498. ctx->state |= FIMC_PARAMS;
  499. set_bit(ST_CAPT_APPLY_CFG, &fimc->state);
  500. return 0;
  501. }
  502. static int fimc_s_ctrl(struct v4l2_ctrl *ctrl)
  503. {
  504. struct fimc_ctx *ctx = ctrl_to_ctx(ctrl);
  505. unsigned long flags;
  506. int ret;
  507. spin_lock_irqsave(&ctx->fimc_dev->slock, flags);
  508. ret = __fimc_s_ctrl(ctx, ctrl);
  509. spin_unlock_irqrestore(&ctx->fimc_dev->slock, flags);
  510. return ret;
  511. }
  512. static const struct v4l2_ctrl_ops fimc_ctrl_ops = {
  513. .s_ctrl = fimc_s_ctrl,
  514. };
  515. int fimc_ctrls_create(struct fimc_ctx *ctx)
  516. {
  517. struct fimc_variant *variant = ctx->fimc_dev->variant;
  518. unsigned int max_alpha = fimc_get_alpha_mask(ctx->d_frame.fmt);
  519. struct fimc_ctrls *ctrls = &ctx->ctrls;
  520. struct v4l2_ctrl_handler *handler = &ctrls->handler;
  521. if (ctx->ctrls.ready)
  522. return 0;
  523. v4l2_ctrl_handler_init(handler, 6);
  524. ctrls->rotate = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
  525. V4L2_CID_ROTATE, 0, 270, 90, 0);
  526. ctrls->hflip = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
  527. V4L2_CID_HFLIP, 0, 1, 1, 0);
  528. ctrls->vflip = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
  529. V4L2_CID_VFLIP, 0, 1, 1, 0);
  530. if (variant->has_alpha)
  531. ctrls->alpha = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
  532. V4L2_CID_ALPHA_COMPONENT,
  533. 0, max_alpha, 1, 0);
  534. else
  535. ctrls->alpha = NULL;
  536. ctrls->colorfx = v4l2_ctrl_new_std_menu(handler, &fimc_ctrl_ops,
  537. V4L2_CID_COLORFX, V4L2_COLORFX_SET_CBCR,
  538. ~0x983f, V4L2_COLORFX_NONE);
  539. ctrls->colorfx_cbcr = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
  540. V4L2_CID_COLORFX_CBCR, 0, 0xffff, 1, 0);
  541. ctx->effect.type = FIMC_REG_CIIMGEFF_FIN_BYPASS;
  542. if (!handler->error) {
  543. v4l2_ctrl_cluster(2, &ctrls->colorfx);
  544. ctrls->ready = true;
  545. }
  546. return handler->error;
  547. }
  548. void fimc_ctrls_delete(struct fimc_ctx *ctx)
  549. {
  550. struct fimc_ctrls *ctrls = &ctx->ctrls;
  551. if (ctrls->ready) {
  552. v4l2_ctrl_handler_free(&ctrls->handler);
  553. ctrls->ready = false;
  554. ctrls->alpha = NULL;
  555. }
  556. }
  557. void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active)
  558. {
  559. unsigned int has_alpha = ctx->d_frame.fmt->flags & FMT_HAS_ALPHA;
  560. struct fimc_ctrls *ctrls = &ctx->ctrls;
  561. if (!ctrls->ready)
  562. return;
  563. mutex_lock(ctrls->handler.lock);
  564. v4l2_ctrl_activate(ctrls->rotate, active);
  565. v4l2_ctrl_activate(ctrls->hflip, active);
  566. v4l2_ctrl_activate(ctrls->vflip, active);
  567. v4l2_ctrl_activate(ctrls->colorfx, active);
  568. if (ctrls->alpha)
  569. v4l2_ctrl_activate(ctrls->alpha, active && has_alpha);
  570. if (active) {
  571. fimc_set_color_effect(ctx, ctrls->colorfx->cur.val);
  572. ctx->rotation = ctrls->rotate->val;
  573. ctx->hflip = ctrls->hflip->val;
  574. ctx->vflip = ctrls->vflip->val;
  575. } else {
  576. ctx->effect.type = FIMC_REG_CIIMGEFF_FIN_BYPASS;
  577. ctx->rotation = 0;
  578. ctx->hflip = 0;
  579. ctx->vflip = 0;
  580. }
  581. mutex_unlock(ctrls->handler.lock);
  582. }
  583. /* Update maximum value of the alpha color control */
  584. void fimc_alpha_ctrl_update(struct fimc_ctx *ctx)
  585. {
  586. struct fimc_dev *fimc = ctx->fimc_dev;
  587. struct v4l2_ctrl *ctrl = ctx->ctrls.alpha;
  588. if (ctrl == NULL || !fimc->variant->has_alpha)
  589. return;
  590. v4l2_ctrl_lock(ctrl);
  591. ctrl->maximum = fimc_get_alpha_mask(ctx->d_frame.fmt);
  592. if (ctrl->cur.val > ctrl->maximum)
  593. ctrl->cur.val = ctrl->maximum;
  594. v4l2_ctrl_unlock(ctrl);
  595. }
  596. int fimc_fill_format(struct fimc_frame *frame, struct v4l2_format *f)
  597. {
  598. struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp;
  599. int i;
  600. pixm->width = frame->o_width;
  601. pixm->height = frame->o_height;
  602. pixm->field = V4L2_FIELD_NONE;
  603. pixm->pixelformat = frame->fmt->fourcc;
  604. pixm->colorspace = V4L2_COLORSPACE_JPEG;
  605. pixm->num_planes = frame->fmt->memplanes;
  606. for (i = 0; i < pixm->num_planes; ++i) {
  607. int bpl = frame->f_width;
  608. if (frame->fmt->colplanes == 1) /* packed formats */
  609. bpl = (bpl * frame->fmt->depth[0]) / 8;
  610. pixm->plane_fmt[i].bytesperline = bpl;
  611. pixm->plane_fmt[i].sizeimage = (frame->o_width *
  612. frame->o_height * frame->fmt->depth[i]) / 8;
  613. }
  614. return 0;
  615. }
  616. void fimc_fill_frame(struct fimc_frame *frame, struct v4l2_format *f)
  617. {
  618. struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp;
  619. frame->f_width = pixm->plane_fmt[0].bytesperline;
  620. if (frame->fmt->colplanes == 1)
  621. frame->f_width = (frame->f_width * 8) / frame->fmt->depth[0];
  622. frame->f_height = pixm->height;
  623. frame->width = pixm->width;
  624. frame->height = pixm->height;
  625. frame->o_width = pixm->width;
  626. frame->o_height = pixm->height;
  627. frame->offs_h = 0;
  628. frame->offs_v = 0;
  629. }
  630. /**
  631. * fimc_adjust_mplane_format - adjust bytesperline/sizeimage for each plane
  632. * @fmt: fimc pixel format description (input)
  633. * @width: requested pixel width
  634. * @height: requested pixel height
  635. * @pix: multi-plane format to adjust
  636. */
  637. void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height,
  638. struct v4l2_pix_format_mplane *pix)
  639. {
  640. u32 bytesperline = 0;
  641. int i;
  642. pix->colorspace = V4L2_COLORSPACE_JPEG;
  643. pix->field = V4L2_FIELD_NONE;
  644. pix->num_planes = fmt->memplanes;
  645. pix->pixelformat = fmt->fourcc;
  646. pix->height = height;
  647. pix->width = width;
  648. for (i = 0; i < pix->num_planes; ++i) {
  649. struct v4l2_plane_pix_format *plane_fmt = &pix->plane_fmt[i];
  650. u32 bpl = plane_fmt->bytesperline;
  651. if (fmt->colplanes > 1 && (bpl == 0 || bpl < pix->width))
  652. bpl = pix->width; /* Planar */
  653. if (fmt->colplanes == 1 && /* Packed */
  654. (bpl == 0 || ((bpl * 8) / fmt->depth[i]) < pix->width))
  655. bpl = (pix->width * fmt->depth[0]) / 8;
  656. if (i == 0) /* Same bytesperline for each plane. */
  657. bytesperline = bpl;
  658. plane_fmt->bytesperline = bytesperline;
  659. plane_fmt->sizeimage = max((pix->width * pix->height *
  660. fmt->depth[i]) / 8, plane_fmt->sizeimage);
  661. }
  662. }
  663. /**
  664. * fimc_find_format - lookup fimc color format by fourcc or media bus format
  665. * @pixelformat: fourcc to match, ignored if null
  666. * @mbus_code: media bus code to match, ignored if null
  667. * @mask: the color flags to match
  668. * @index: offset in the fimc_formats array, ignored if negative
  669. */
  670. struct fimc_fmt *fimc_find_format(const u32 *pixelformat, const u32 *mbus_code,
  671. unsigned int mask, int index)
  672. {
  673. struct fimc_fmt *fmt, *def_fmt = NULL;
  674. unsigned int i;
  675. int id = 0;
  676. if (index >= (int)ARRAY_SIZE(fimc_formats))
  677. return NULL;
  678. for (i = 0; i < ARRAY_SIZE(fimc_formats); ++i) {
  679. fmt = &fimc_formats[i];
  680. if (!(fmt->flags & mask))
  681. continue;
  682. if (pixelformat && fmt->fourcc == *pixelformat)
  683. return fmt;
  684. if (mbus_code && fmt->mbus_code == *mbus_code)
  685. return fmt;
  686. if (index == id)
  687. def_fmt = fmt;
  688. id++;
  689. }
  690. return def_fmt;
  691. }
  692. static void fimc_clk_put(struct fimc_dev *fimc)
  693. {
  694. int i;
  695. for (i = 0; i < MAX_FIMC_CLOCKS; i++) {
  696. if (IS_ERR_OR_NULL(fimc->clock[i]))
  697. continue;
  698. clk_unprepare(fimc->clock[i]);
  699. clk_put(fimc->clock[i]);
  700. fimc->clock[i] = NULL;
  701. }
  702. }
  703. static int fimc_clk_get(struct fimc_dev *fimc)
  704. {
  705. int i, ret;
  706. for (i = 0; i < MAX_FIMC_CLOCKS; i++) {
  707. fimc->clock[i] = clk_get(&fimc->pdev->dev, fimc_clocks[i]);
  708. if (IS_ERR(fimc->clock[i]))
  709. goto err;
  710. ret = clk_prepare(fimc->clock[i]);
  711. if (ret < 0) {
  712. clk_put(fimc->clock[i]);
  713. fimc->clock[i] = NULL;
  714. goto err;
  715. }
  716. }
  717. return 0;
  718. err:
  719. fimc_clk_put(fimc);
  720. dev_err(&fimc->pdev->dev, "failed to get clock: %s\n",
  721. fimc_clocks[i]);
  722. return -ENXIO;
  723. }
  724. static int fimc_m2m_suspend(struct fimc_dev *fimc)
  725. {
  726. unsigned long flags;
  727. int timeout;
  728. spin_lock_irqsave(&fimc->slock, flags);
  729. if (!fimc_m2m_pending(fimc)) {
  730. spin_unlock_irqrestore(&fimc->slock, flags);
  731. return 0;
  732. }
  733. clear_bit(ST_M2M_SUSPENDED, &fimc->state);
  734. set_bit(ST_M2M_SUSPENDING, &fimc->state);
  735. spin_unlock_irqrestore(&fimc->slock, flags);
  736. timeout = wait_event_timeout(fimc->irq_queue,
  737. test_bit(ST_M2M_SUSPENDED, &fimc->state),
  738. FIMC_SHUTDOWN_TIMEOUT);
  739. clear_bit(ST_M2M_SUSPENDING, &fimc->state);
  740. return timeout == 0 ? -EAGAIN : 0;
  741. }
  742. static int fimc_m2m_resume(struct fimc_dev *fimc)
  743. {
  744. unsigned long flags;
  745. spin_lock_irqsave(&fimc->slock, flags);
  746. /* Clear for full H/W setup in first run after resume */
  747. fimc->m2m.ctx = NULL;
  748. spin_unlock_irqrestore(&fimc->slock, flags);
  749. if (test_and_clear_bit(ST_M2M_SUSPENDED, &fimc->state))
  750. fimc_m2m_job_finish(fimc->m2m.ctx,
  751. VB2_BUF_STATE_ERROR);
  752. return 0;
  753. }
  754. static int fimc_probe(struct platform_device *pdev)
  755. {
  756. struct fimc_drvdata *drv_data = fimc_get_drvdata(pdev);
  757. struct s5p_platform_fimc *pdata;
  758. struct fimc_dev *fimc;
  759. struct resource *res;
  760. int ret = 0;
  761. if (pdev->id >= drv_data->num_entities) {
  762. dev_err(&pdev->dev, "Invalid platform device id: %d\n",
  763. pdev->id);
  764. return -EINVAL;
  765. }
  766. fimc = devm_kzalloc(&pdev->dev, sizeof(*fimc), GFP_KERNEL);
  767. if (!fimc)
  768. return -ENOMEM;
  769. fimc->id = pdev->id;
  770. fimc->variant = drv_data->variant[fimc->id];
  771. fimc->pdev = pdev;
  772. pdata = pdev->dev.platform_data;
  773. fimc->pdata = pdata;
  774. init_waitqueue_head(&fimc->irq_queue);
  775. spin_lock_init(&fimc->slock);
  776. mutex_init(&fimc->lock);
  777. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  778. fimc->regs = devm_request_and_ioremap(&pdev->dev, res);
  779. if (fimc->regs == NULL) {
  780. dev_err(&pdev->dev, "Failed to obtain io memory\n");
  781. return -ENOENT;
  782. }
  783. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  784. if (res == NULL) {
  785. dev_err(&pdev->dev, "Failed to get IRQ resource\n");
  786. return -ENXIO;
  787. }
  788. ret = fimc_clk_get(fimc);
  789. if (ret)
  790. return ret;
  791. clk_set_rate(fimc->clock[CLK_BUS], drv_data->lclk_frequency);
  792. clk_enable(fimc->clock[CLK_BUS]);
  793. ret = devm_request_irq(&pdev->dev, res->start, fimc_irq_handler,
  794. 0, dev_name(&pdev->dev), fimc);
  795. if (ret) {
  796. dev_err(&pdev->dev, "failed to install irq (%d)\n", ret);
  797. goto err_clk;
  798. }
  799. ret = fimc_initialize_capture_subdev(fimc);
  800. if (ret)
  801. goto err_clk;
  802. platform_set_drvdata(pdev, fimc);
  803. pm_runtime_enable(&pdev->dev);
  804. ret = pm_runtime_get_sync(&pdev->dev);
  805. if (ret < 0)
  806. goto err_sd;
  807. /* Initialize contiguous memory allocator */
  808. fimc->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
  809. if (IS_ERR(fimc->alloc_ctx)) {
  810. ret = PTR_ERR(fimc->alloc_ctx);
  811. goto err_pm;
  812. }
  813. dev_dbg(&pdev->dev, "FIMC.%d registered successfully\n", fimc->id);
  814. pm_runtime_put(&pdev->dev);
  815. return 0;
  816. err_pm:
  817. pm_runtime_put(&pdev->dev);
  818. err_sd:
  819. fimc_unregister_capture_subdev(fimc);
  820. err_clk:
  821. fimc_clk_put(fimc);
  822. return ret;
  823. }
  824. static int fimc_runtime_resume(struct device *dev)
  825. {
  826. struct fimc_dev *fimc = dev_get_drvdata(dev);
  827. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  828. /* Enable clocks and perform basic initalization */
  829. clk_enable(fimc->clock[CLK_GATE]);
  830. fimc_hw_reset(fimc);
  831. /* Resume the capture or mem-to-mem device */
  832. if (fimc_capture_busy(fimc))
  833. return fimc_capture_resume(fimc);
  834. return fimc_m2m_resume(fimc);
  835. }
  836. static int fimc_runtime_suspend(struct device *dev)
  837. {
  838. struct fimc_dev *fimc = dev_get_drvdata(dev);
  839. int ret = 0;
  840. if (fimc_capture_busy(fimc))
  841. ret = fimc_capture_suspend(fimc);
  842. else
  843. ret = fimc_m2m_suspend(fimc);
  844. if (!ret)
  845. clk_disable(fimc->clock[CLK_GATE]);
  846. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  847. return ret;
  848. }
  849. #ifdef CONFIG_PM_SLEEP
  850. static int fimc_resume(struct device *dev)
  851. {
  852. struct fimc_dev *fimc = dev_get_drvdata(dev);
  853. unsigned long flags;
  854. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  855. /* Do not resume if the device was idle before system suspend */
  856. spin_lock_irqsave(&fimc->slock, flags);
  857. if (!test_and_clear_bit(ST_LPM, &fimc->state) ||
  858. (!fimc_m2m_active(fimc) && !fimc_capture_busy(fimc))) {
  859. spin_unlock_irqrestore(&fimc->slock, flags);
  860. return 0;
  861. }
  862. fimc_hw_reset(fimc);
  863. spin_unlock_irqrestore(&fimc->slock, flags);
  864. if (fimc_capture_busy(fimc))
  865. return fimc_capture_resume(fimc);
  866. return fimc_m2m_resume(fimc);
  867. }
  868. static int fimc_suspend(struct device *dev)
  869. {
  870. struct fimc_dev *fimc = dev_get_drvdata(dev);
  871. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  872. if (test_and_set_bit(ST_LPM, &fimc->state))
  873. return 0;
  874. if (fimc_capture_busy(fimc))
  875. return fimc_capture_suspend(fimc);
  876. return fimc_m2m_suspend(fimc);
  877. }
  878. #endif /* CONFIG_PM_SLEEP */
  879. static int __devexit fimc_remove(struct platform_device *pdev)
  880. {
  881. struct fimc_dev *fimc = platform_get_drvdata(pdev);
  882. pm_runtime_disable(&pdev->dev);
  883. pm_runtime_set_suspended(&pdev->dev);
  884. fimc_unregister_capture_subdev(fimc);
  885. vb2_dma_contig_cleanup_ctx(fimc->alloc_ctx);
  886. clk_disable(fimc->clock[CLK_BUS]);
  887. fimc_clk_put(fimc);
  888. dev_info(&pdev->dev, "driver unloaded\n");
  889. return 0;
  890. }
  891. /* Image pixel limits, similar across several FIMC HW revisions. */
  892. static struct fimc_pix_limit s5p_pix_limit[4] = {
  893. [0] = {
  894. .scaler_en_w = 3264,
  895. .scaler_dis_w = 8192,
  896. .in_rot_en_h = 1920,
  897. .in_rot_dis_w = 8192,
  898. .out_rot_en_w = 1920,
  899. .out_rot_dis_w = 4224,
  900. },
  901. [1] = {
  902. .scaler_en_w = 4224,
  903. .scaler_dis_w = 8192,
  904. .in_rot_en_h = 1920,
  905. .in_rot_dis_w = 8192,
  906. .out_rot_en_w = 1920,
  907. .out_rot_dis_w = 4224,
  908. },
  909. [2] = {
  910. .scaler_en_w = 1920,
  911. .scaler_dis_w = 8192,
  912. .in_rot_en_h = 1280,
  913. .in_rot_dis_w = 8192,
  914. .out_rot_en_w = 1280,
  915. .out_rot_dis_w = 1920,
  916. },
  917. [3] = {
  918. .scaler_en_w = 1920,
  919. .scaler_dis_w = 8192,
  920. .in_rot_en_h = 1366,
  921. .in_rot_dis_w = 8192,
  922. .out_rot_en_w = 1366,
  923. .out_rot_dis_w = 1920,
  924. },
  925. };
  926. static struct fimc_variant fimc0_variant_s5p = {
  927. .has_inp_rot = 1,
  928. .has_out_rot = 1,
  929. .has_cam_if = 1,
  930. .min_inp_pixsize = 16,
  931. .min_out_pixsize = 16,
  932. .hor_offs_align = 8,
  933. .min_vsize_align = 16,
  934. .out_buf_count = 4,
  935. .pix_limit = &s5p_pix_limit[0],
  936. };
  937. static struct fimc_variant fimc2_variant_s5p = {
  938. .has_cam_if = 1,
  939. .min_inp_pixsize = 16,
  940. .min_out_pixsize = 16,
  941. .hor_offs_align = 8,
  942. .min_vsize_align = 16,
  943. .out_buf_count = 4,
  944. .pix_limit = &s5p_pix_limit[1],
  945. };
  946. static struct fimc_variant fimc0_variant_s5pv210 = {
  947. .pix_hoff = 1,
  948. .has_inp_rot = 1,
  949. .has_out_rot = 1,
  950. .has_cam_if = 1,
  951. .min_inp_pixsize = 16,
  952. .min_out_pixsize = 16,
  953. .hor_offs_align = 8,
  954. .min_vsize_align = 16,
  955. .out_buf_count = 4,
  956. .pix_limit = &s5p_pix_limit[1],
  957. };
  958. static struct fimc_variant fimc1_variant_s5pv210 = {
  959. .pix_hoff = 1,
  960. .has_inp_rot = 1,
  961. .has_out_rot = 1,
  962. .has_cam_if = 1,
  963. .has_mainscaler_ext = 1,
  964. .min_inp_pixsize = 16,
  965. .min_out_pixsize = 16,
  966. .hor_offs_align = 1,
  967. .min_vsize_align = 1,
  968. .out_buf_count = 4,
  969. .pix_limit = &s5p_pix_limit[2],
  970. };
  971. static struct fimc_variant fimc2_variant_s5pv210 = {
  972. .has_cam_if = 1,
  973. .pix_hoff = 1,
  974. .min_inp_pixsize = 16,
  975. .min_out_pixsize = 16,
  976. .hor_offs_align = 8,
  977. .min_vsize_align = 16,
  978. .out_buf_count = 4,
  979. .pix_limit = &s5p_pix_limit[2],
  980. };
  981. static struct fimc_variant fimc0_variant_exynos4 = {
  982. .pix_hoff = 1,
  983. .has_inp_rot = 1,
  984. .has_out_rot = 1,
  985. .has_cam_if = 1,
  986. .has_cistatus2 = 1,
  987. .has_mainscaler_ext = 1,
  988. .has_alpha = 1,
  989. .min_inp_pixsize = 16,
  990. .min_out_pixsize = 16,
  991. .hor_offs_align = 2,
  992. .min_vsize_align = 1,
  993. .out_buf_count = 32,
  994. .pix_limit = &s5p_pix_limit[1],
  995. };
  996. static struct fimc_variant fimc3_variant_exynos4 = {
  997. .pix_hoff = 1,
  998. .has_cam_if = 1,
  999. .has_cistatus2 = 1,
  1000. .has_mainscaler_ext = 1,
  1001. .has_alpha = 1,
  1002. .min_inp_pixsize = 16,
  1003. .min_out_pixsize = 16,
  1004. .hor_offs_align = 2,
  1005. .min_vsize_align = 1,
  1006. .out_buf_count = 32,
  1007. .pix_limit = &s5p_pix_limit[3],
  1008. };
  1009. /* S5PC100 */
  1010. static struct fimc_drvdata fimc_drvdata_s5p = {
  1011. .variant = {
  1012. [0] = &fimc0_variant_s5p,
  1013. [1] = &fimc0_variant_s5p,
  1014. [2] = &fimc2_variant_s5p,
  1015. },
  1016. .num_entities = 3,
  1017. .lclk_frequency = 133000000UL,
  1018. };
  1019. /* S5PV210, S5PC110 */
  1020. static struct fimc_drvdata fimc_drvdata_s5pv210 = {
  1021. .variant = {
  1022. [0] = &fimc0_variant_s5pv210,
  1023. [1] = &fimc1_variant_s5pv210,
  1024. [2] = &fimc2_variant_s5pv210,
  1025. },
  1026. .num_entities = 3,
  1027. .lclk_frequency = 166000000UL,
  1028. };
  1029. /* EXYNOS4210, S5PV310, S5PC210 */
  1030. static struct fimc_drvdata fimc_drvdata_exynos4 = {
  1031. .variant = {
  1032. [0] = &fimc0_variant_exynos4,
  1033. [1] = &fimc0_variant_exynos4,
  1034. [2] = &fimc0_variant_exynos4,
  1035. [3] = &fimc3_variant_exynos4,
  1036. },
  1037. .num_entities = 4,
  1038. .lclk_frequency = 166000000UL,
  1039. };
  1040. static struct platform_device_id fimc_driver_ids[] = {
  1041. {
  1042. .name = "s5p-fimc",
  1043. .driver_data = (unsigned long)&fimc_drvdata_s5p,
  1044. }, {
  1045. .name = "s5pv210-fimc",
  1046. .driver_data = (unsigned long)&fimc_drvdata_s5pv210,
  1047. }, {
  1048. .name = "exynos4-fimc",
  1049. .driver_data = (unsigned long)&fimc_drvdata_exynos4,
  1050. },
  1051. {},
  1052. };
  1053. MODULE_DEVICE_TABLE(platform, fimc_driver_ids);
  1054. static const struct dev_pm_ops fimc_pm_ops = {
  1055. SET_SYSTEM_SLEEP_PM_OPS(fimc_suspend, fimc_resume)
  1056. SET_RUNTIME_PM_OPS(fimc_runtime_suspend, fimc_runtime_resume, NULL)
  1057. };
  1058. static struct platform_driver fimc_driver = {
  1059. .probe = fimc_probe,
  1060. .remove = __devexit_p(fimc_remove),
  1061. .id_table = fimc_driver_ids,
  1062. .driver = {
  1063. .name = FIMC_MODULE_NAME,
  1064. .owner = THIS_MODULE,
  1065. .pm = &fimc_pm_ops,
  1066. }
  1067. };
  1068. int __init fimc_register_driver(void)
  1069. {
  1070. return platform_driver_register(&fimc_driver);
  1071. }
  1072. void __exit fimc_unregister_driver(void)
  1073. {
  1074. platform_driver_unregister(&fimc_driver);
  1075. }