fimc-core.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289
  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. struct fimc_ctx *ctx;
  746. unsigned long flags;
  747. spin_lock_irqsave(&fimc->slock, flags);
  748. /* Clear for full H/W setup in first run after resume */
  749. ctx = fimc->m2m.ctx;
  750. fimc->m2m.ctx = NULL;
  751. spin_unlock_irqrestore(&fimc->slock, flags);
  752. if (test_and_clear_bit(ST_M2M_SUSPENDED, &fimc->state))
  753. fimc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
  754. return 0;
  755. }
  756. static int fimc_probe(struct platform_device *pdev)
  757. {
  758. const struct fimc_drvdata *drv_data = fimc_get_drvdata(pdev);
  759. struct s5p_platform_fimc *pdata;
  760. struct fimc_dev *fimc;
  761. struct resource *res;
  762. int ret = 0;
  763. if (pdev->id >= drv_data->num_entities) {
  764. dev_err(&pdev->dev, "Invalid platform device id: %d\n",
  765. pdev->id);
  766. return -EINVAL;
  767. }
  768. fimc = devm_kzalloc(&pdev->dev, sizeof(*fimc), GFP_KERNEL);
  769. if (!fimc)
  770. return -ENOMEM;
  771. fimc->id = pdev->id;
  772. fimc->variant = drv_data->variant[fimc->id];
  773. fimc->pdev = pdev;
  774. pdata = pdev->dev.platform_data;
  775. fimc->pdata = pdata;
  776. init_waitqueue_head(&fimc->irq_queue);
  777. spin_lock_init(&fimc->slock);
  778. mutex_init(&fimc->lock);
  779. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  780. fimc->regs = devm_ioremap_resource(&pdev->dev, res);
  781. if (IS_ERR(fimc->regs))
  782. return PTR_ERR(fimc->regs);
  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. ret = clk_set_rate(fimc->clock[CLK_BUS], drv_data->lclk_frequency);
  792. if (ret < 0)
  793. return ret;
  794. ret = clk_enable(fimc->clock[CLK_BUS]);
  795. if (ret < 0)
  796. return ret;
  797. ret = devm_request_irq(&pdev->dev, res->start, fimc_irq_handler,
  798. 0, dev_name(&pdev->dev), fimc);
  799. if (ret) {
  800. dev_err(&pdev->dev, "failed to install irq (%d)\n", ret);
  801. goto err_clk;
  802. }
  803. ret = fimc_initialize_capture_subdev(fimc);
  804. if (ret)
  805. goto err_clk;
  806. platform_set_drvdata(pdev, fimc);
  807. pm_runtime_enable(&pdev->dev);
  808. ret = pm_runtime_get_sync(&pdev->dev);
  809. if (ret < 0)
  810. goto err_sd;
  811. /* Initialize contiguous memory allocator */
  812. fimc->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
  813. if (IS_ERR(fimc->alloc_ctx)) {
  814. ret = PTR_ERR(fimc->alloc_ctx);
  815. goto err_pm;
  816. }
  817. dev_dbg(&pdev->dev, "FIMC.%d registered successfully\n", fimc->id);
  818. pm_runtime_put(&pdev->dev);
  819. return 0;
  820. err_pm:
  821. pm_runtime_put(&pdev->dev);
  822. err_sd:
  823. fimc_unregister_capture_subdev(fimc);
  824. err_clk:
  825. clk_disable(fimc->clock[CLK_BUS]);
  826. fimc_clk_put(fimc);
  827. return ret;
  828. }
  829. static int fimc_runtime_resume(struct device *dev)
  830. {
  831. struct fimc_dev *fimc = dev_get_drvdata(dev);
  832. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  833. /* Enable clocks and perform basic initalization */
  834. clk_enable(fimc->clock[CLK_GATE]);
  835. fimc_hw_reset(fimc);
  836. /* Resume the capture or mem-to-mem device */
  837. if (fimc_capture_busy(fimc))
  838. return fimc_capture_resume(fimc);
  839. return fimc_m2m_resume(fimc);
  840. }
  841. static int fimc_runtime_suspend(struct device *dev)
  842. {
  843. struct fimc_dev *fimc = dev_get_drvdata(dev);
  844. int ret = 0;
  845. if (fimc_capture_busy(fimc))
  846. ret = fimc_capture_suspend(fimc);
  847. else
  848. ret = fimc_m2m_suspend(fimc);
  849. if (!ret)
  850. clk_disable(fimc->clock[CLK_GATE]);
  851. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  852. return ret;
  853. }
  854. #ifdef CONFIG_PM_SLEEP
  855. static int fimc_resume(struct device *dev)
  856. {
  857. struct fimc_dev *fimc = dev_get_drvdata(dev);
  858. unsigned long flags;
  859. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  860. /* Do not resume if the device was idle before system suspend */
  861. spin_lock_irqsave(&fimc->slock, flags);
  862. if (!test_and_clear_bit(ST_LPM, &fimc->state) ||
  863. (!fimc_m2m_active(fimc) && !fimc_capture_busy(fimc))) {
  864. spin_unlock_irqrestore(&fimc->slock, flags);
  865. return 0;
  866. }
  867. fimc_hw_reset(fimc);
  868. spin_unlock_irqrestore(&fimc->slock, flags);
  869. if (fimc_capture_busy(fimc))
  870. return fimc_capture_resume(fimc);
  871. return fimc_m2m_resume(fimc);
  872. }
  873. static int fimc_suspend(struct device *dev)
  874. {
  875. struct fimc_dev *fimc = dev_get_drvdata(dev);
  876. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  877. if (test_and_set_bit(ST_LPM, &fimc->state))
  878. return 0;
  879. if (fimc_capture_busy(fimc))
  880. return fimc_capture_suspend(fimc);
  881. return fimc_m2m_suspend(fimc);
  882. }
  883. #endif /* CONFIG_PM_SLEEP */
  884. static int fimc_remove(struct platform_device *pdev)
  885. {
  886. struct fimc_dev *fimc = platform_get_drvdata(pdev);
  887. pm_runtime_disable(&pdev->dev);
  888. pm_runtime_set_suspended(&pdev->dev);
  889. fimc_unregister_capture_subdev(fimc);
  890. vb2_dma_contig_cleanup_ctx(fimc->alloc_ctx);
  891. clk_disable(fimc->clock[CLK_BUS]);
  892. fimc_clk_put(fimc);
  893. dev_info(&pdev->dev, "driver unloaded\n");
  894. return 0;
  895. }
  896. /* Image pixel limits, similar across several FIMC HW revisions. */
  897. static const struct fimc_pix_limit s5p_pix_limit[4] = {
  898. [0] = {
  899. .scaler_en_w = 3264,
  900. .scaler_dis_w = 8192,
  901. .in_rot_en_h = 1920,
  902. .in_rot_dis_w = 8192,
  903. .out_rot_en_w = 1920,
  904. .out_rot_dis_w = 4224,
  905. },
  906. [1] = {
  907. .scaler_en_w = 4224,
  908. .scaler_dis_w = 8192,
  909. .in_rot_en_h = 1920,
  910. .in_rot_dis_w = 8192,
  911. .out_rot_en_w = 1920,
  912. .out_rot_dis_w = 4224,
  913. },
  914. [2] = {
  915. .scaler_en_w = 1920,
  916. .scaler_dis_w = 8192,
  917. .in_rot_en_h = 1280,
  918. .in_rot_dis_w = 8192,
  919. .out_rot_en_w = 1280,
  920. .out_rot_dis_w = 1920,
  921. },
  922. [3] = {
  923. .scaler_en_w = 1920,
  924. .scaler_dis_w = 8192,
  925. .in_rot_en_h = 1366,
  926. .in_rot_dis_w = 8192,
  927. .out_rot_en_w = 1366,
  928. .out_rot_dis_w = 1920,
  929. },
  930. };
  931. static const struct fimc_variant fimc0_variant_s5p = {
  932. .has_inp_rot = 1,
  933. .has_out_rot = 1,
  934. .has_cam_if = 1,
  935. .min_inp_pixsize = 16,
  936. .min_out_pixsize = 16,
  937. .hor_offs_align = 8,
  938. .min_vsize_align = 16,
  939. .out_buf_count = 4,
  940. .pix_limit = &s5p_pix_limit[0],
  941. };
  942. static const struct fimc_variant fimc2_variant_s5p = {
  943. .has_cam_if = 1,
  944. .min_inp_pixsize = 16,
  945. .min_out_pixsize = 16,
  946. .hor_offs_align = 8,
  947. .min_vsize_align = 16,
  948. .out_buf_count = 4,
  949. .pix_limit = &s5p_pix_limit[1],
  950. };
  951. static const struct fimc_variant fimc0_variant_s5pv210 = {
  952. .pix_hoff = 1,
  953. .has_inp_rot = 1,
  954. .has_out_rot = 1,
  955. .has_cam_if = 1,
  956. .min_inp_pixsize = 16,
  957. .min_out_pixsize = 16,
  958. .hor_offs_align = 8,
  959. .min_vsize_align = 16,
  960. .out_buf_count = 4,
  961. .pix_limit = &s5p_pix_limit[1],
  962. };
  963. static const struct fimc_variant fimc1_variant_s5pv210 = {
  964. .pix_hoff = 1,
  965. .has_inp_rot = 1,
  966. .has_out_rot = 1,
  967. .has_cam_if = 1,
  968. .has_mainscaler_ext = 1,
  969. .min_inp_pixsize = 16,
  970. .min_out_pixsize = 16,
  971. .hor_offs_align = 1,
  972. .min_vsize_align = 1,
  973. .out_buf_count = 4,
  974. .pix_limit = &s5p_pix_limit[2],
  975. };
  976. static const struct fimc_variant fimc2_variant_s5pv210 = {
  977. .has_cam_if = 1,
  978. .pix_hoff = 1,
  979. .min_inp_pixsize = 16,
  980. .min_out_pixsize = 16,
  981. .hor_offs_align = 8,
  982. .min_vsize_align = 16,
  983. .out_buf_count = 4,
  984. .pix_limit = &s5p_pix_limit[2],
  985. };
  986. static const struct fimc_variant fimc0_variant_exynos4210 = {
  987. .pix_hoff = 1,
  988. .has_inp_rot = 1,
  989. .has_out_rot = 1,
  990. .has_cam_if = 1,
  991. .has_cistatus2 = 1,
  992. .has_mainscaler_ext = 1,
  993. .has_alpha = 1,
  994. .min_inp_pixsize = 16,
  995. .min_out_pixsize = 16,
  996. .hor_offs_align = 2,
  997. .min_vsize_align = 1,
  998. .out_buf_count = 32,
  999. .pix_limit = &s5p_pix_limit[1],
  1000. };
  1001. static const struct fimc_variant fimc3_variant_exynos4210 = {
  1002. .pix_hoff = 1,
  1003. .has_cistatus2 = 1,
  1004. .has_mainscaler_ext = 1,
  1005. .has_alpha = 1,
  1006. .min_inp_pixsize = 16,
  1007. .min_out_pixsize = 16,
  1008. .hor_offs_align = 2,
  1009. .min_vsize_align = 1,
  1010. .out_buf_count = 32,
  1011. .pix_limit = &s5p_pix_limit[3],
  1012. };
  1013. static const struct fimc_variant fimc0_variant_exynos4x12 = {
  1014. .pix_hoff = 1,
  1015. .has_inp_rot = 1,
  1016. .has_out_rot = 1,
  1017. .has_cam_if = 1,
  1018. .has_isp_wb = 1,
  1019. .has_cistatus2 = 1,
  1020. .has_mainscaler_ext = 1,
  1021. .has_alpha = 1,
  1022. .min_inp_pixsize = 16,
  1023. .min_out_pixsize = 16,
  1024. .hor_offs_align = 2,
  1025. .min_vsize_align = 1,
  1026. .out_buf_count = 32,
  1027. .pix_limit = &s5p_pix_limit[1],
  1028. };
  1029. static const struct fimc_variant fimc3_variant_exynos4x12 = {
  1030. .pix_hoff = 1,
  1031. .has_cistatus2 = 1,
  1032. .has_mainscaler_ext = 1,
  1033. .has_alpha = 1,
  1034. .min_inp_pixsize = 16,
  1035. .min_out_pixsize = 16,
  1036. .hor_offs_align = 2,
  1037. .min_vsize_align = 1,
  1038. .out_buf_count = 32,
  1039. .pix_limit = &s5p_pix_limit[3],
  1040. };
  1041. /* S5PC100 */
  1042. static const struct fimc_drvdata fimc_drvdata_s5p = {
  1043. .variant = {
  1044. [0] = &fimc0_variant_s5p,
  1045. [1] = &fimc0_variant_s5p,
  1046. [2] = &fimc2_variant_s5p,
  1047. },
  1048. .num_entities = 3,
  1049. .lclk_frequency = 133000000UL,
  1050. };
  1051. /* S5PV210, S5PC110 */
  1052. static const struct fimc_drvdata fimc_drvdata_s5pv210 = {
  1053. .variant = {
  1054. [0] = &fimc0_variant_s5pv210,
  1055. [1] = &fimc1_variant_s5pv210,
  1056. [2] = &fimc2_variant_s5pv210,
  1057. },
  1058. .num_entities = 3,
  1059. .lclk_frequency = 166000000UL,
  1060. };
  1061. /* EXYNOS4210, S5PV310, S5PC210 */
  1062. static const struct fimc_drvdata fimc_drvdata_exynos4210 = {
  1063. .variant = {
  1064. [0] = &fimc0_variant_exynos4210,
  1065. [1] = &fimc0_variant_exynos4210,
  1066. [2] = &fimc0_variant_exynos4210,
  1067. [3] = &fimc3_variant_exynos4210,
  1068. },
  1069. .num_entities = 4,
  1070. .lclk_frequency = 166000000UL,
  1071. };
  1072. /* EXYNOS4212, EXYNOS4412 */
  1073. static const struct fimc_drvdata fimc_drvdata_exynos4x12 = {
  1074. .variant = {
  1075. [0] = &fimc0_variant_exynos4x12,
  1076. [1] = &fimc0_variant_exynos4x12,
  1077. [2] = &fimc0_variant_exynos4x12,
  1078. [3] = &fimc3_variant_exynos4x12,
  1079. },
  1080. .num_entities = 4,
  1081. .lclk_frequency = 166000000UL,
  1082. };
  1083. static const struct platform_device_id fimc_driver_ids[] = {
  1084. {
  1085. .name = "s5p-fimc",
  1086. .driver_data = (unsigned long)&fimc_drvdata_s5p,
  1087. }, {
  1088. .name = "s5pv210-fimc",
  1089. .driver_data = (unsigned long)&fimc_drvdata_s5pv210,
  1090. }, {
  1091. .name = "exynos4-fimc",
  1092. .driver_data = (unsigned long)&fimc_drvdata_exynos4210,
  1093. }, {
  1094. .name = "exynos4x12-fimc",
  1095. .driver_data = (unsigned long)&fimc_drvdata_exynos4x12,
  1096. },
  1097. {},
  1098. };
  1099. MODULE_DEVICE_TABLE(platform, fimc_driver_ids);
  1100. static const struct dev_pm_ops fimc_pm_ops = {
  1101. SET_SYSTEM_SLEEP_PM_OPS(fimc_suspend, fimc_resume)
  1102. SET_RUNTIME_PM_OPS(fimc_runtime_suspend, fimc_runtime_resume, NULL)
  1103. };
  1104. static struct platform_driver fimc_driver = {
  1105. .probe = fimc_probe,
  1106. .remove = fimc_remove,
  1107. .id_table = fimc_driver_ids,
  1108. .driver = {
  1109. .name = FIMC_MODULE_NAME,
  1110. .owner = THIS_MODULE,
  1111. .pm = &fimc_pm_ops,
  1112. }
  1113. };
  1114. int __init fimc_register_driver(void)
  1115. {
  1116. return platform_driver_register(&fimc_driver);
  1117. }
  1118. void __exit fimc_unregister_driver(void)
  1119. {
  1120. platform_driver_unregister(&fimc_driver);
  1121. }