fimc-core.c 30 KB

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