fimc-core.c 32 KB

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