fimc-core.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  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 | FMT_FLAGS_COMPRESSED,
  184. }, {
  185. .name = "S5C73MX interleaved UYVY/JPEG",
  186. .fourcc = V4L2_PIX_FMT_S5C_UYVY_JPG,
  187. .color = FIMC_FMT_YUYV_JPEG,
  188. .depth = { 8 },
  189. .memplanes = 2,
  190. .colplanes = 1,
  191. .mdataplanes = 0x2, /* plane 1 holds frame meta data */
  192. .mbus_code = V4L2_MBUS_FMT_S5C_UYVY_JPEG_1X8,
  193. .flags = FMT_FLAGS_CAM | FMT_FLAGS_COMPRESSED,
  194. },
  195. };
  196. struct fimc_fmt *fimc_get_format(unsigned int index)
  197. {
  198. if (index >= ARRAY_SIZE(fimc_formats))
  199. return NULL;
  200. return &fimc_formats[index];
  201. }
  202. int fimc_check_scaler_ratio(struct fimc_ctx *ctx, int sw, int sh,
  203. int dw, int dh, int rotation)
  204. {
  205. if (rotation == 90 || rotation == 270)
  206. swap(dw, dh);
  207. if (!ctx->scaler.enabled)
  208. return (sw == dw && sh == dh) ? 0 : -EINVAL;
  209. if ((sw >= SCALER_MAX_HRATIO * dw) || (sh >= SCALER_MAX_VRATIO * dh))
  210. return -EINVAL;
  211. return 0;
  212. }
  213. static int fimc_get_scaler_factor(u32 src, u32 tar, u32 *ratio, u32 *shift)
  214. {
  215. u32 sh = 6;
  216. if (src >= 64 * tar)
  217. return -EINVAL;
  218. while (sh--) {
  219. u32 tmp = 1 << sh;
  220. if (src >= tar * tmp) {
  221. *shift = sh, *ratio = tmp;
  222. return 0;
  223. }
  224. }
  225. *shift = 0, *ratio = 1;
  226. return 0;
  227. }
  228. int fimc_set_scaler_info(struct fimc_ctx *ctx)
  229. {
  230. const struct fimc_variant *variant = ctx->fimc_dev->variant;
  231. struct device *dev = &ctx->fimc_dev->pdev->dev;
  232. struct fimc_scaler *sc = &ctx->scaler;
  233. struct fimc_frame *s_frame = &ctx->s_frame;
  234. struct fimc_frame *d_frame = &ctx->d_frame;
  235. int tx, ty, sx, sy;
  236. int ret;
  237. if (ctx->rotation == 90 || ctx->rotation == 270) {
  238. ty = d_frame->width;
  239. tx = d_frame->height;
  240. } else {
  241. tx = d_frame->width;
  242. ty = d_frame->height;
  243. }
  244. if (tx <= 0 || ty <= 0) {
  245. dev_err(dev, "Invalid target size: %dx%d\n", tx, ty);
  246. return -EINVAL;
  247. }
  248. sx = s_frame->width;
  249. sy = s_frame->height;
  250. if (sx <= 0 || sy <= 0) {
  251. dev_err(dev, "Invalid source size: %dx%d\n", sx, sy);
  252. return -EINVAL;
  253. }
  254. sc->real_width = sx;
  255. sc->real_height = sy;
  256. ret = fimc_get_scaler_factor(sx, tx, &sc->pre_hratio, &sc->hfactor);
  257. if (ret)
  258. return ret;
  259. ret = fimc_get_scaler_factor(sy, ty, &sc->pre_vratio, &sc->vfactor);
  260. if (ret)
  261. return ret;
  262. sc->pre_dst_width = sx / sc->pre_hratio;
  263. sc->pre_dst_height = sy / sc->pre_vratio;
  264. if (variant->has_mainscaler_ext) {
  265. sc->main_hratio = (sx << 14) / (tx << sc->hfactor);
  266. sc->main_vratio = (sy << 14) / (ty << sc->vfactor);
  267. } else {
  268. sc->main_hratio = (sx << 8) / (tx << sc->hfactor);
  269. sc->main_vratio = (sy << 8) / (ty << sc->vfactor);
  270. }
  271. sc->scaleup_h = (tx >= sx) ? 1 : 0;
  272. sc->scaleup_v = (ty >= sy) ? 1 : 0;
  273. /* check to see if input and output size/format differ */
  274. if (s_frame->fmt->color == d_frame->fmt->color
  275. && s_frame->width == d_frame->width
  276. && s_frame->height == d_frame->height)
  277. sc->copy_mode = 1;
  278. else
  279. sc->copy_mode = 0;
  280. return 0;
  281. }
  282. static irqreturn_t fimc_irq_handler(int irq, void *priv)
  283. {
  284. struct fimc_dev *fimc = priv;
  285. struct fimc_ctx *ctx;
  286. fimc_hw_clear_irq(fimc);
  287. spin_lock(&fimc->slock);
  288. if (test_and_clear_bit(ST_M2M_PEND, &fimc->state)) {
  289. if (test_and_clear_bit(ST_M2M_SUSPENDING, &fimc->state)) {
  290. set_bit(ST_M2M_SUSPENDED, &fimc->state);
  291. wake_up(&fimc->irq_queue);
  292. goto out;
  293. }
  294. ctx = v4l2_m2m_get_curr_priv(fimc->m2m.m2m_dev);
  295. if (ctx != NULL) {
  296. spin_unlock(&fimc->slock);
  297. fimc_m2m_job_finish(ctx, VB2_BUF_STATE_DONE);
  298. if (ctx->state & FIMC_CTX_SHUT) {
  299. ctx->state &= ~FIMC_CTX_SHUT;
  300. wake_up(&fimc->irq_queue);
  301. }
  302. return IRQ_HANDLED;
  303. }
  304. } else if (test_bit(ST_CAPT_PEND, &fimc->state)) {
  305. int last_buf = test_bit(ST_CAPT_JPEG, &fimc->state) &&
  306. fimc->vid_cap.reqbufs_count == 1;
  307. fimc_capture_irq_handler(fimc, !last_buf);
  308. }
  309. out:
  310. spin_unlock(&fimc->slock);
  311. return IRQ_HANDLED;
  312. }
  313. /* The color format (colplanes, memplanes) must be already configured. */
  314. int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
  315. struct fimc_frame *frame, struct fimc_addr *paddr)
  316. {
  317. int ret = 0;
  318. u32 pix_size;
  319. if (vb == NULL || frame == NULL)
  320. return -EINVAL;
  321. pix_size = frame->width * frame->height;
  322. dbg("memplanes= %d, colplanes= %d, pix_size= %d",
  323. frame->fmt->memplanes, frame->fmt->colplanes, pix_size);
  324. paddr->y = vb2_dma_contig_plane_dma_addr(vb, 0);
  325. if (frame->fmt->memplanes == 1) {
  326. switch (frame->fmt->colplanes) {
  327. case 1:
  328. paddr->cb = 0;
  329. paddr->cr = 0;
  330. break;
  331. case 2:
  332. /* decompose Y into Y/Cb */
  333. paddr->cb = (u32)(paddr->y + pix_size);
  334. paddr->cr = 0;
  335. break;
  336. case 3:
  337. paddr->cb = (u32)(paddr->y + pix_size);
  338. /* decompose Y into Y/Cb/Cr */
  339. if (FIMC_FMT_YCBCR420 == frame->fmt->color)
  340. paddr->cr = (u32)(paddr->cb
  341. + (pix_size >> 2));
  342. else /* 422 */
  343. paddr->cr = (u32)(paddr->cb
  344. + (pix_size >> 1));
  345. break;
  346. default:
  347. return -EINVAL;
  348. }
  349. } else if (!frame->fmt->mdataplanes) {
  350. if (frame->fmt->memplanes >= 2)
  351. paddr->cb = vb2_dma_contig_plane_dma_addr(vb, 1);
  352. if (frame->fmt->memplanes == 3)
  353. paddr->cr = vb2_dma_contig_plane_dma_addr(vb, 2);
  354. }
  355. dbg("PHYS_ADDR: y= 0x%X cb= 0x%X cr= 0x%X ret= %d",
  356. paddr->y, paddr->cb, paddr->cr, ret);
  357. return ret;
  358. }
  359. /* Set order for 1 and 2 plane YCBCR 4:2:2 formats. */
  360. void fimc_set_yuv_order(struct fimc_ctx *ctx)
  361. {
  362. /* The one only mode supported in SoC. */
  363. ctx->in_order_2p = FIMC_REG_CIOCTRL_ORDER422_2P_LSB_CRCB;
  364. ctx->out_order_2p = FIMC_REG_CIOCTRL_ORDER422_2P_LSB_CRCB;
  365. /* Set order for 1 plane input formats. */
  366. switch (ctx->s_frame.fmt->color) {
  367. case FIMC_FMT_YCRYCB422:
  368. ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_CBYCRY;
  369. break;
  370. case FIMC_FMT_CBYCRY422:
  371. ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_YCRYCB;
  372. break;
  373. case FIMC_FMT_CRYCBY422:
  374. ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_YCBYCR;
  375. break;
  376. case FIMC_FMT_YCBYCR422:
  377. default:
  378. ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_CRYCBY;
  379. break;
  380. }
  381. dbg("ctx->in_order_1p= %d", ctx->in_order_1p);
  382. switch (ctx->d_frame.fmt->color) {
  383. case FIMC_FMT_YCRYCB422:
  384. ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_CBYCRY;
  385. break;
  386. case FIMC_FMT_CBYCRY422:
  387. ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_YCRYCB;
  388. break;
  389. case FIMC_FMT_CRYCBY422:
  390. ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_YCBYCR;
  391. break;
  392. case FIMC_FMT_YCBYCR422:
  393. default:
  394. ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_CRYCBY;
  395. break;
  396. }
  397. dbg("ctx->out_order_1p= %d", ctx->out_order_1p);
  398. }
  399. void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f)
  400. {
  401. const struct fimc_variant *variant = ctx->fimc_dev->variant;
  402. u32 i, depth = 0;
  403. for (i = 0; i < f->fmt->colplanes; i++)
  404. depth += f->fmt->depth[i];
  405. f->dma_offset.y_h = f->offs_h;
  406. if (!variant->pix_hoff)
  407. f->dma_offset.y_h *= (depth >> 3);
  408. f->dma_offset.y_v = f->offs_v;
  409. f->dma_offset.cb_h = f->offs_h;
  410. f->dma_offset.cb_v = f->offs_v;
  411. f->dma_offset.cr_h = f->offs_h;
  412. f->dma_offset.cr_v = f->offs_v;
  413. if (!variant->pix_hoff) {
  414. if (f->fmt->colplanes == 3) {
  415. f->dma_offset.cb_h >>= 1;
  416. f->dma_offset.cr_h >>= 1;
  417. }
  418. if (f->fmt->color == FIMC_FMT_YCBCR420) {
  419. f->dma_offset.cb_v >>= 1;
  420. f->dma_offset.cr_v >>= 1;
  421. }
  422. }
  423. dbg("in_offset: color= %d, y_h= %d, y_v= %d",
  424. f->fmt->color, f->dma_offset.y_h, f->dma_offset.y_v);
  425. }
  426. static int fimc_set_color_effect(struct fimc_ctx *ctx, enum v4l2_colorfx colorfx)
  427. {
  428. struct fimc_effect *effect = &ctx->effect;
  429. switch (colorfx) {
  430. case V4L2_COLORFX_NONE:
  431. effect->type = FIMC_REG_CIIMGEFF_FIN_BYPASS;
  432. break;
  433. case V4L2_COLORFX_BW:
  434. effect->type = FIMC_REG_CIIMGEFF_FIN_ARBITRARY;
  435. effect->pat_cb = 128;
  436. effect->pat_cr = 128;
  437. break;
  438. case V4L2_COLORFX_SEPIA:
  439. effect->type = FIMC_REG_CIIMGEFF_FIN_ARBITRARY;
  440. effect->pat_cb = 115;
  441. effect->pat_cr = 145;
  442. break;
  443. case V4L2_COLORFX_NEGATIVE:
  444. effect->type = FIMC_REG_CIIMGEFF_FIN_NEGATIVE;
  445. break;
  446. case V4L2_COLORFX_EMBOSS:
  447. effect->type = FIMC_REG_CIIMGEFF_FIN_EMBOSSING;
  448. break;
  449. case V4L2_COLORFX_ART_FREEZE:
  450. effect->type = FIMC_REG_CIIMGEFF_FIN_ARTFREEZE;
  451. break;
  452. case V4L2_COLORFX_SILHOUETTE:
  453. effect->type = FIMC_REG_CIIMGEFF_FIN_SILHOUETTE;
  454. break;
  455. case V4L2_COLORFX_SET_CBCR:
  456. effect->type = FIMC_REG_CIIMGEFF_FIN_ARBITRARY;
  457. effect->pat_cb = ctx->ctrls.colorfx_cbcr->val >> 8;
  458. effect->pat_cr = ctx->ctrls.colorfx_cbcr->val & 0xff;
  459. break;
  460. default:
  461. return -EINVAL;
  462. }
  463. return 0;
  464. }
  465. /*
  466. * V4L2 controls handling
  467. */
  468. #define ctrl_to_ctx(__ctrl) \
  469. container_of((__ctrl)->handler, struct fimc_ctx, ctrls.handler)
  470. static int __fimc_s_ctrl(struct fimc_ctx *ctx, struct v4l2_ctrl *ctrl)
  471. {
  472. struct fimc_dev *fimc = ctx->fimc_dev;
  473. const struct fimc_variant *variant = fimc->variant;
  474. int ret = 0;
  475. if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE)
  476. return 0;
  477. switch (ctrl->id) {
  478. case V4L2_CID_HFLIP:
  479. ctx->hflip = ctrl->val;
  480. break;
  481. case V4L2_CID_VFLIP:
  482. ctx->vflip = ctrl->val;
  483. break;
  484. case V4L2_CID_ROTATE:
  485. if (fimc_capture_pending(fimc)) {
  486. ret = fimc_check_scaler_ratio(ctx, ctx->s_frame.width,
  487. ctx->s_frame.height, ctx->d_frame.width,
  488. ctx->d_frame.height, ctrl->val);
  489. if (ret)
  490. return -EINVAL;
  491. }
  492. if ((ctrl->val == 90 || ctrl->val == 270) &&
  493. !variant->has_out_rot)
  494. return -EINVAL;
  495. ctx->rotation = ctrl->val;
  496. break;
  497. case V4L2_CID_ALPHA_COMPONENT:
  498. ctx->d_frame.alpha = ctrl->val;
  499. break;
  500. case V4L2_CID_COLORFX:
  501. ret = fimc_set_color_effect(ctx, ctrl->val);
  502. if (ret)
  503. return ret;
  504. break;
  505. }
  506. ctx->state |= FIMC_PARAMS;
  507. set_bit(ST_CAPT_APPLY_CFG, &fimc->state);
  508. return 0;
  509. }
  510. static int fimc_s_ctrl(struct v4l2_ctrl *ctrl)
  511. {
  512. struct fimc_ctx *ctx = ctrl_to_ctx(ctrl);
  513. unsigned long flags;
  514. int ret;
  515. spin_lock_irqsave(&ctx->fimc_dev->slock, flags);
  516. ret = __fimc_s_ctrl(ctx, ctrl);
  517. spin_unlock_irqrestore(&ctx->fimc_dev->slock, flags);
  518. return ret;
  519. }
  520. static const struct v4l2_ctrl_ops fimc_ctrl_ops = {
  521. .s_ctrl = fimc_s_ctrl,
  522. };
  523. int fimc_ctrls_create(struct fimc_ctx *ctx)
  524. {
  525. const struct fimc_variant *variant = ctx->fimc_dev->variant;
  526. unsigned int max_alpha = fimc_get_alpha_mask(ctx->d_frame.fmt);
  527. struct fimc_ctrls *ctrls = &ctx->ctrls;
  528. struct v4l2_ctrl_handler *handler = &ctrls->handler;
  529. if (ctx->ctrls.ready)
  530. return 0;
  531. v4l2_ctrl_handler_init(handler, 6);
  532. ctrls->rotate = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
  533. V4L2_CID_ROTATE, 0, 270, 90, 0);
  534. ctrls->hflip = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
  535. V4L2_CID_HFLIP, 0, 1, 1, 0);
  536. ctrls->vflip = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
  537. V4L2_CID_VFLIP, 0, 1, 1, 0);
  538. if (variant->has_alpha)
  539. ctrls->alpha = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
  540. V4L2_CID_ALPHA_COMPONENT,
  541. 0, max_alpha, 1, 0);
  542. else
  543. ctrls->alpha = NULL;
  544. ctrls->colorfx = v4l2_ctrl_new_std_menu(handler, &fimc_ctrl_ops,
  545. V4L2_CID_COLORFX, V4L2_COLORFX_SET_CBCR,
  546. ~0x983f, V4L2_COLORFX_NONE);
  547. ctrls->colorfx_cbcr = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
  548. V4L2_CID_COLORFX_CBCR, 0, 0xffff, 1, 0);
  549. ctx->effect.type = FIMC_REG_CIIMGEFF_FIN_BYPASS;
  550. if (!handler->error) {
  551. v4l2_ctrl_cluster(2, &ctrls->colorfx);
  552. ctrls->ready = true;
  553. }
  554. return handler->error;
  555. }
  556. void fimc_ctrls_delete(struct fimc_ctx *ctx)
  557. {
  558. struct fimc_ctrls *ctrls = &ctx->ctrls;
  559. if (ctrls->ready) {
  560. v4l2_ctrl_handler_free(&ctrls->handler);
  561. ctrls->ready = false;
  562. ctrls->alpha = NULL;
  563. }
  564. }
  565. void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active)
  566. {
  567. unsigned int has_alpha = ctx->d_frame.fmt->flags & FMT_HAS_ALPHA;
  568. struct fimc_ctrls *ctrls = &ctx->ctrls;
  569. if (!ctrls->ready)
  570. return;
  571. mutex_lock(ctrls->handler.lock);
  572. v4l2_ctrl_activate(ctrls->rotate, active);
  573. v4l2_ctrl_activate(ctrls->hflip, active);
  574. v4l2_ctrl_activate(ctrls->vflip, active);
  575. v4l2_ctrl_activate(ctrls->colorfx, active);
  576. if (ctrls->alpha)
  577. v4l2_ctrl_activate(ctrls->alpha, active && has_alpha);
  578. if (active) {
  579. fimc_set_color_effect(ctx, ctrls->colorfx->cur.val);
  580. ctx->rotation = ctrls->rotate->val;
  581. ctx->hflip = ctrls->hflip->val;
  582. ctx->vflip = ctrls->vflip->val;
  583. } else {
  584. ctx->effect.type = FIMC_REG_CIIMGEFF_FIN_BYPASS;
  585. ctx->rotation = 0;
  586. ctx->hflip = 0;
  587. ctx->vflip = 0;
  588. }
  589. mutex_unlock(ctrls->handler.lock);
  590. }
  591. /* Update maximum value of the alpha color control */
  592. void fimc_alpha_ctrl_update(struct fimc_ctx *ctx)
  593. {
  594. struct fimc_dev *fimc = ctx->fimc_dev;
  595. struct v4l2_ctrl *ctrl = ctx->ctrls.alpha;
  596. if (ctrl == NULL || !fimc->variant->has_alpha)
  597. return;
  598. v4l2_ctrl_lock(ctrl);
  599. ctrl->maximum = fimc_get_alpha_mask(ctx->d_frame.fmt);
  600. if (ctrl->cur.val > ctrl->maximum)
  601. ctrl->cur.val = ctrl->maximum;
  602. v4l2_ctrl_unlock(ctrl);
  603. }
  604. void __fimc_get_format(struct fimc_frame *frame, struct v4l2_format *f)
  605. {
  606. struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp;
  607. int i;
  608. pixm->width = frame->o_width;
  609. pixm->height = frame->o_height;
  610. pixm->field = V4L2_FIELD_NONE;
  611. pixm->pixelformat = frame->fmt->fourcc;
  612. pixm->colorspace = V4L2_COLORSPACE_JPEG;
  613. pixm->num_planes = frame->fmt->memplanes;
  614. for (i = 0; i < pixm->num_planes; ++i) {
  615. pixm->plane_fmt[i].bytesperline = frame->bytesperline[i];
  616. pixm->plane_fmt[i].sizeimage = frame->payload[i];
  617. }
  618. }
  619. /**
  620. * fimc_adjust_mplane_format - adjust bytesperline/sizeimage for each plane
  621. * @fmt: fimc pixel format description (input)
  622. * @width: requested pixel width
  623. * @height: requested pixel height
  624. * @pix: multi-plane format to adjust
  625. */
  626. void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height,
  627. struct v4l2_pix_format_mplane *pix)
  628. {
  629. u32 bytesperline = 0;
  630. int i;
  631. pix->colorspace = V4L2_COLORSPACE_JPEG;
  632. pix->field = V4L2_FIELD_NONE;
  633. pix->num_planes = fmt->memplanes;
  634. pix->pixelformat = fmt->fourcc;
  635. pix->height = height;
  636. pix->width = width;
  637. for (i = 0; i < pix->num_planes; ++i) {
  638. struct v4l2_plane_pix_format *plane_fmt = &pix->plane_fmt[i];
  639. u32 bpl = plane_fmt->bytesperline;
  640. if (fmt->colplanes > 1 && (bpl == 0 || bpl < pix->width))
  641. bpl = pix->width; /* Planar */
  642. if (fmt->colplanes == 1 && /* Packed */
  643. (bpl == 0 || ((bpl * 8) / fmt->depth[i]) < pix->width))
  644. bpl = (pix->width * fmt->depth[0]) / 8;
  645. /*
  646. * Currently bytesperline for each plane is same, except
  647. * V4L2_PIX_FMT_YUV420M format. This calculation may need
  648. * to be changed when other multi-planar formats are added
  649. * to the fimc_formats[] array.
  650. */
  651. if (i == 0)
  652. bytesperline = bpl;
  653. else if (i == 1 && fmt->memplanes == 3)
  654. bytesperline /= 2;
  655. plane_fmt->bytesperline = bytesperline;
  656. plane_fmt->sizeimage = max((pix->width * pix->height *
  657. fmt->depth[i]) / 8, plane_fmt->sizeimage);
  658. }
  659. }
  660. /**
  661. * fimc_find_format - lookup fimc color format by fourcc or media bus format
  662. * @pixelformat: fourcc to match, ignored if null
  663. * @mbus_code: media bus code to match, ignored if null
  664. * @mask: the color flags to match
  665. * @index: offset in the fimc_formats array, ignored if negative
  666. */
  667. struct fimc_fmt *fimc_find_format(const u32 *pixelformat, const u32 *mbus_code,
  668. unsigned int mask, int index)
  669. {
  670. struct fimc_fmt *fmt, *def_fmt = NULL;
  671. unsigned int i;
  672. int id = 0;
  673. if (index >= (int)ARRAY_SIZE(fimc_formats))
  674. return NULL;
  675. for (i = 0; i < ARRAY_SIZE(fimc_formats); ++i) {
  676. fmt = &fimc_formats[i];
  677. if (!(fmt->flags & mask))
  678. continue;
  679. if (pixelformat && fmt->fourcc == *pixelformat)
  680. return fmt;
  681. if (mbus_code && fmt->mbus_code == *mbus_code)
  682. return fmt;
  683. if (index == id)
  684. def_fmt = fmt;
  685. id++;
  686. }
  687. return def_fmt;
  688. }
  689. static void fimc_clk_put(struct fimc_dev *fimc)
  690. {
  691. int i;
  692. for (i = 0; i < MAX_FIMC_CLOCKS; i++) {
  693. if (IS_ERR(fimc->clock[i]))
  694. continue;
  695. clk_unprepare(fimc->clock[i]);
  696. clk_put(fimc->clock[i]);
  697. fimc->clock[i] = ERR_PTR(-EINVAL);
  698. }
  699. }
  700. static int fimc_clk_get(struct fimc_dev *fimc)
  701. {
  702. int i, ret;
  703. for (i = 0; i < MAX_FIMC_CLOCKS; i++)
  704. fimc->clock[i] = ERR_PTR(-EINVAL);
  705. for (i = 0; i < MAX_FIMC_CLOCKS; i++) {
  706. fimc->clock[i] = clk_get(&fimc->pdev->dev, fimc_clocks[i]);
  707. if (IS_ERR(fimc->clock[i])) {
  708. ret = PTR_ERR(fimc->clock[i]);
  709. goto err;
  710. }
  711. ret = clk_prepare(fimc->clock[i]);
  712. if (ret < 0) {
  713. clk_put(fimc->clock[i]);
  714. fimc->clock[i] = ERR_PTR(-EINVAL);
  715. goto err;
  716. }
  717. }
  718. return 0;
  719. err:
  720. fimc_clk_put(fimc);
  721. dev_err(&fimc->pdev->dev, "failed to get clock: %s\n",
  722. fimc_clocks[i]);
  723. return -ENXIO;
  724. }
  725. static int fimc_m2m_suspend(struct fimc_dev *fimc)
  726. {
  727. unsigned long flags;
  728. int timeout;
  729. spin_lock_irqsave(&fimc->slock, flags);
  730. if (!fimc_m2m_pending(fimc)) {
  731. spin_unlock_irqrestore(&fimc->slock, flags);
  732. return 0;
  733. }
  734. clear_bit(ST_M2M_SUSPENDED, &fimc->state);
  735. set_bit(ST_M2M_SUSPENDING, &fimc->state);
  736. spin_unlock_irqrestore(&fimc->slock, flags);
  737. timeout = wait_event_timeout(fimc->irq_queue,
  738. test_bit(ST_M2M_SUSPENDED, &fimc->state),
  739. FIMC_SHUTDOWN_TIMEOUT);
  740. clear_bit(ST_M2M_SUSPENDING, &fimc->state);
  741. return timeout == 0 ? -EAGAIN : 0;
  742. }
  743. static int fimc_m2m_resume(struct fimc_dev *fimc)
  744. {
  745. unsigned long flags;
  746. spin_lock_irqsave(&fimc->slock, flags);
  747. /* Clear for full H/W setup in first run after resume */
  748. fimc->m2m.ctx = NULL;
  749. spin_unlock_irqrestore(&fimc->slock, flags);
  750. if (test_and_clear_bit(ST_M2M_SUSPENDED, &fimc->state))
  751. fimc_m2m_job_finish(fimc->m2m.ctx,
  752. VB2_BUF_STATE_ERROR);
  753. return 0;
  754. }
  755. static int fimc_probe(struct platform_device *pdev)
  756. {
  757. const struct fimc_drvdata *drv_data = fimc_get_drvdata(pdev);
  758. struct s5p_platform_fimc *pdata;
  759. struct fimc_dev *fimc;
  760. struct resource *res;
  761. int ret = 0;
  762. if (pdev->id >= drv_data->num_entities) {
  763. dev_err(&pdev->dev, "Invalid platform device id: %d\n",
  764. pdev->id);
  765. return -EINVAL;
  766. }
  767. fimc = devm_kzalloc(&pdev->dev, sizeof(*fimc), GFP_KERNEL);
  768. if (!fimc)
  769. return -ENOMEM;
  770. fimc->id = pdev->id;
  771. fimc->variant = drv_data->variant[fimc->id];
  772. fimc->pdev = pdev;
  773. pdata = pdev->dev.platform_data;
  774. fimc->pdata = pdata;
  775. init_waitqueue_head(&fimc->irq_queue);
  776. spin_lock_init(&fimc->slock);
  777. mutex_init(&fimc->lock);
  778. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  779. fimc->regs = devm_ioremap_resource(&pdev->dev, res);
  780. if (IS_ERR(fimc->regs))
  781. return PTR_ERR(fimc->regs);
  782. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  783. if (res == NULL) {
  784. dev_err(&pdev->dev, "Failed to get IRQ resource\n");
  785. return -ENXIO;
  786. }
  787. ret = fimc_clk_get(fimc);
  788. if (ret)
  789. return ret;
  790. ret = clk_set_rate(fimc->clock[CLK_BUS], drv_data->lclk_frequency);
  791. if (ret < 0)
  792. return ret;
  793. ret = clk_enable(fimc->clock[CLK_BUS]);
  794. if (ret < 0)
  795. return ret;
  796. ret = devm_request_irq(&pdev->dev, res->start, fimc_irq_handler,
  797. 0, dev_name(&pdev->dev), fimc);
  798. if (ret) {
  799. dev_err(&pdev->dev, "failed to install irq (%d)\n", ret);
  800. goto err_clk;
  801. }
  802. ret = fimc_initialize_capture_subdev(fimc);
  803. if (ret)
  804. goto err_clk;
  805. platform_set_drvdata(pdev, fimc);
  806. pm_runtime_enable(&pdev->dev);
  807. ret = pm_runtime_get_sync(&pdev->dev);
  808. if (ret < 0)
  809. goto err_sd;
  810. /* Initialize contiguous memory allocator */
  811. fimc->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
  812. if (IS_ERR(fimc->alloc_ctx)) {
  813. ret = PTR_ERR(fimc->alloc_ctx);
  814. goto err_pm;
  815. }
  816. dev_dbg(&pdev->dev, "FIMC.%d registered successfully\n", fimc->id);
  817. pm_runtime_put(&pdev->dev);
  818. return 0;
  819. err_pm:
  820. pm_runtime_put(&pdev->dev);
  821. err_sd:
  822. fimc_unregister_capture_subdev(fimc);
  823. err_clk:
  824. clk_disable(fimc->clock[CLK_BUS]);
  825. fimc_clk_put(fimc);
  826. return ret;
  827. }
  828. static int fimc_runtime_resume(struct device *dev)
  829. {
  830. struct fimc_dev *fimc = dev_get_drvdata(dev);
  831. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  832. /* Enable clocks and perform basic initalization */
  833. clk_enable(fimc->clock[CLK_GATE]);
  834. fimc_hw_reset(fimc);
  835. /* Resume the capture or mem-to-mem device */
  836. if (fimc_capture_busy(fimc))
  837. return fimc_capture_resume(fimc);
  838. return fimc_m2m_resume(fimc);
  839. }
  840. static int fimc_runtime_suspend(struct device *dev)
  841. {
  842. struct fimc_dev *fimc = dev_get_drvdata(dev);
  843. int ret = 0;
  844. if (fimc_capture_busy(fimc))
  845. ret = fimc_capture_suspend(fimc);
  846. else
  847. ret = fimc_m2m_suspend(fimc);
  848. if (!ret)
  849. clk_disable(fimc->clock[CLK_GATE]);
  850. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  851. return ret;
  852. }
  853. #ifdef CONFIG_PM_SLEEP
  854. static int fimc_resume(struct device *dev)
  855. {
  856. struct fimc_dev *fimc = dev_get_drvdata(dev);
  857. unsigned long flags;
  858. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  859. /* Do not resume if the device was idle before system suspend */
  860. spin_lock_irqsave(&fimc->slock, flags);
  861. if (!test_and_clear_bit(ST_LPM, &fimc->state) ||
  862. (!fimc_m2m_active(fimc) && !fimc_capture_busy(fimc))) {
  863. spin_unlock_irqrestore(&fimc->slock, flags);
  864. return 0;
  865. }
  866. fimc_hw_reset(fimc);
  867. spin_unlock_irqrestore(&fimc->slock, flags);
  868. if (fimc_capture_busy(fimc))
  869. return fimc_capture_resume(fimc);
  870. return fimc_m2m_resume(fimc);
  871. }
  872. static int fimc_suspend(struct device *dev)
  873. {
  874. struct fimc_dev *fimc = dev_get_drvdata(dev);
  875. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  876. if (test_and_set_bit(ST_LPM, &fimc->state))
  877. return 0;
  878. if (fimc_capture_busy(fimc))
  879. return fimc_capture_suspend(fimc);
  880. return fimc_m2m_suspend(fimc);
  881. }
  882. #endif /* CONFIG_PM_SLEEP */
  883. static int fimc_remove(struct platform_device *pdev)
  884. {
  885. struct fimc_dev *fimc = platform_get_drvdata(pdev);
  886. pm_runtime_disable(&pdev->dev);
  887. pm_runtime_set_suspended(&pdev->dev);
  888. fimc_unregister_capture_subdev(fimc);
  889. vb2_dma_contig_cleanup_ctx(fimc->alloc_ctx);
  890. clk_disable(fimc->clock[CLK_BUS]);
  891. fimc_clk_put(fimc);
  892. dev_info(&pdev->dev, "driver unloaded\n");
  893. return 0;
  894. }
  895. /* Image pixel limits, similar across several FIMC HW revisions. */
  896. static const struct fimc_pix_limit s5p_pix_limit[4] = {
  897. [0] = {
  898. .scaler_en_w = 3264,
  899. .scaler_dis_w = 8192,
  900. .in_rot_en_h = 1920,
  901. .in_rot_dis_w = 8192,
  902. .out_rot_en_w = 1920,
  903. .out_rot_dis_w = 4224,
  904. },
  905. [1] = {
  906. .scaler_en_w = 4224,
  907. .scaler_dis_w = 8192,
  908. .in_rot_en_h = 1920,
  909. .in_rot_dis_w = 8192,
  910. .out_rot_en_w = 1920,
  911. .out_rot_dis_w = 4224,
  912. },
  913. [2] = {
  914. .scaler_en_w = 1920,
  915. .scaler_dis_w = 8192,
  916. .in_rot_en_h = 1280,
  917. .in_rot_dis_w = 8192,
  918. .out_rot_en_w = 1280,
  919. .out_rot_dis_w = 1920,
  920. },
  921. [3] = {
  922. .scaler_en_w = 1920,
  923. .scaler_dis_w = 8192,
  924. .in_rot_en_h = 1366,
  925. .in_rot_dis_w = 8192,
  926. .out_rot_en_w = 1366,
  927. .out_rot_dis_w = 1920,
  928. },
  929. };
  930. static const struct fimc_variant fimc0_variant_s5p = {
  931. .has_inp_rot = 1,
  932. .has_out_rot = 1,
  933. .has_cam_if = 1,
  934. .min_inp_pixsize = 16,
  935. .min_out_pixsize = 16,
  936. .hor_offs_align = 8,
  937. .min_vsize_align = 16,
  938. .out_buf_count = 4,
  939. .pix_limit = &s5p_pix_limit[0],
  940. };
  941. static const struct fimc_variant fimc2_variant_s5p = {
  942. .has_cam_if = 1,
  943. .min_inp_pixsize = 16,
  944. .min_out_pixsize = 16,
  945. .hor_offs_align = 8,
  946. .min_vsize_align = 16,
  947. .out_buf_count = 4,
  948. .pix_limit = &s5p_pix_limit[1],
  949. };
  950. static const struct fimc_variant fimc0_variant_s5pv210 = {
  951. .pix_hoff = 1,
  952. .has_inp_rot = 1,
  953. .has_out_rot = 1,
  954. .has_cam_if = 1,
  955. .min_inp_pixsize = 16,
  956. .min_out_pixsize = 16,
  957. .hor_offs_align = 8,
  958. .min_vsize_align = 16,
  959. .out_buf_count = 4,
  960. .pix_limit = &s5p_pix_limit[1],
  961. };
  962. static const struct fimc_variant fimc1_variant_s5pv210 = {
  963. .pix_hoff = 1,
  964. .has_inp_rot = 1,
  965. .has_out_rot = 1,
  966. .has_cam_if = 1,
  967. .has_mainscaler_ext = 1,
  968. .min_inp_pixsize = 16,
  969. .min_out_pixsize = 16,
  970. .hor_offs_align = 1,
  971. .min_vsize_align = 1,
  972. .out_buf_count = 4,
  973. .pix_limit = &s5p_pix_limit[2],
  974. };
  975. static const struct fimc_variant fimc2_variant_s5pv210 = {
  976. .has_cam_if = 1,
  977. .pix_hoff = 1,
  978. .min_inp_pixsize = 16,
  979. .min_out_pixsize = 16,
  980. .hor_offs_align = 8,
  981. .min_vsize_align = 16,
  982. .out_buf_count = 4,
  983. .pix_limit = &s5p_pix_limit[2],
  984. };
  985. static const struct fimc_variant fimc0_variant_exynos4210 = {
  986. .pix_hoff = 1,
  987. .has_inp_rot = 1,
  988. .has_out_rot = 1,
  989. .has_cam_if = 1,
  990. .has_cistatus2 = 1,
  991. .has_mainscaler_ext = 1,
  992. .has_alpha = 1,
  993. .min_inp_pixsize = 16,
  994. .min_out_pixsize = 16,
  995. .hor_offs_align = 2,
  996. .min_vsize_align = 1,
  997. .out_buf_count = 32,
  998. .pix_limit = &s5p_pix_limit[1],
  999. };
  1000. static const struct fimc_variant fimc3_variant_exynos4210 = {
  1001. .pix_hoff = 1,
  1002. .has_cistatus2 = 1,
  1003. .has_mainscaler_ext = 1,
  1004. .has_alpha = 1,
  1005. .min_inp_pixsize = 16,
  1006. .min_out_pixsize = 16,
  1007. .hor_offs_align = 2,
  1008. .min_vsize_align = 1,
  1009. .out_buf_count = 32,
  1010. .pix_limit = &s5p_pix_limit[3],
  1011. };
  1012. static const struct fimc_variant fimc0_variant_exynos4x12 = {
  1013. .pix_hoff = 1,
  1014. .has_inp_rot = 1,
  1015. .has_out_rot = 1,
  1016. .has_cam_if = 1,
  1017. .has_isp_wb = 1,
  1018. .has_cistatus2 = 1,
  1019. .has_mainscaler_ext = 1,
  1020. .has_alpha = 1,
  1021. .min_inp_pixsize = 16,
  1022. .min_out_pixsize = 16,
  1023. .hor_offs_align = 2,
  1024. .min_vsize_align = 1,
  1025. .out_buf_count = 32,
  1026. .pix_limit = &s5p_pix_limit[1],
  1027. };
  1028. static const struct fimc_variant fimc3_variant_exynos4x12 = {
  1029. .pix_hoff = 1,
  1030. .has_cistatus2 = 1,
  1031. .has_mainscaler_ext = 1,
  1032. .has_alpha = 1,
  1033. .min_inp_pixsize = 16,
  1034. .min_out_pixsize = 16,
  1035. .hor_offs_align = 2,
  1036. .min_vsize_align = 1,
  1037. .out_buf_count = 32,
  1038. .pix_limit = &s5p_pix_limit[3],
  1039. };
  1040. /* S5PC100 */
  1041. static const struct fimc_drvdata fimc_drvdata_s5p = {
  1042. .variant = {
  1043. [0] = &fimc0_variant_s5p,
  1044. [1] = &fimc0_variant_s5p,
  1045. [2] = &fimc2_variant_s5p,
  1046. },
  1047. .num_entities = 3,
  1048. .lclk_frequency = 133000000UL,
  1049. };
  1050. /* S5PV210, S5PC110 */
  1051. static const struct fimc_drvdata fimc_drvdata_s5pv210 = {
  1052. .variant = {
  1053. [0] = &fimc0_variant_s5pv210,
  1054. [1] = &fimc1_variant_s5pv210,
  1055. [2] = &fimc2_variant_s5pv210,
  1056. },
  1057. .num_entities = 3,
  1058. .lclk_frequency = 166000000UL,
  1059. };
  1060. /* EXYNOS4210, S5PV310, S5PC210 */
  1061. static const struct fimc_drvdata fimc_drvdata_exynos4210 = {
  1062. .variant = {
  1063. [0] = &fimc0_variant_exynos4210,
  1064. [1] = &fimc0_variant_exynos4210,
  1065. [2] = &fimc0_variant_exynos4210,
  1066. [3] = &fimc3_variant_exynos4210,
  1067. },
  1068. .num_entities = 4,
  1069. .lclk_frequency = 166000000UL,
  1070. };
  1071. /* EXYNOS4212, EXYNOS4412 */
  1072. static const struct fimc_drvdata fimc_drvdata_exynos4x12 = {
  1073. .variant = {
  1074. [0] = &fimc0_variant_exynos4x12,
  1075. [1] = &fimc0_variant_exynos4x12,
  1076. [2] = &fimc0_variant_exynos4x12,
  1077. [3] = &fimc3_variant_exynos4x12,
  1078. },
  1079. .num_entities = 4,
  1080. .lclk_frequency = 166000000UL,
  1081. };
  1082. static const struct platform_device_id fimc_driver_ids[] = {
  1083. {
  1084. .name = "s5p-fimc",
  1085. .driver_data = (unsigned long)&fimc_drvdata_s5p,
  1086. }, {
  1087. .name = "s5pv210-fimc",
  1088. .driver_data = (unsigned long)&fimc_drvdata_s5pv210,
  1089. }, {
  1090. .name = "exynos4-fimc",
  1091. .driver_data = (unsigned long)&fimc_drvdata_exynos4210,
  1092. }, {
  1093. .name = "exynos4x12-fimc",
  1094. .driver_data = (unsigned long)&fimc_drvdata_exynos4x12,
  1095. },
  1096. {},
  1097. };
  1098. MODULE_DEVICE_TABLE(platform, fimc_driver_ids);
  1099. static const struct dev_pm_ops fimc_pm_ops = {
  1100. SET_SYSTEM_SLEEP_PM_OPS(fimc_suspend, fimc_resume)
  1101. SET_RUNTIME_PM_OPS(fimc_runtime_suspend, fimc_runtime_resume, NULL)
  1102. };
  1103. static struct platform_driver fimc_driver = {
  1104. .probe = fimc_probe,
  1105. .remove = fimc_remove,
  1106. .id_table = fimc_driver_ids,
  1107. .driver = {
  1108. .name = FIMC_MODULE_NAME,
  1109. .owner = THIS_MODULE,
  1110. .pm = &fimc_pm_ops,
  1111. }
  1112. };
  1113. int __init fimc_register_driver(void)
  1114. {
  1115. return platform_driver_register(&fimc_driver);
  1116. }
  1117. void __exit fimc_unregister_driver(void)
  1118. {
  1119. platform_driver_unregister(&fimc_driver);
  1120. }