fimc-core.c 30 KB

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