fimc-core.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832
  1. /*
  2. * S5P camera interface (video postprocessor) driver
  3. *
  4. * Copyright (c) 2010 Samsung Electronics Co., Ltd
  5. *
  6. * Sylwester Nawrocki, <s.nawrocki@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published
  10. * by the Free Software Foundation, either version 2 of the License,
  11. * or (at your option) any later version.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/version.h>
  16. #include <linux/types.h>
  17. #include <linux/errno.h>
  18. #include <linux/bug.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/device.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/list.h>
  23. #include <linux/io.h>
  24. #include <linux/slab.h>
  25. #include <linux/clk.h>
  26. #include <media/v4l2-ioctl.h>
  27. #include <media/videobuf2-core.h>
  28. #include <media/videobuf2-dma-contig.h>
  29. #include "fimc-core.h"
  30. static char *fimc_clock_name[NUM_FIMC_CLOCKS] = { "sclk_fimc", "fimc" };
  31. static struct fimc_fmt fimc_formats[] = {
  32. {
  33. .name = "RGB565",
  34. .fourcc = V4L2_PIX_FMT_RGB565X,
  35. .depth = 16,
  36. .color = S5P_FIMC_RGB565,
  37. .buff_cnt = 1,
  38. .planes_cnt = 1,
  39. .mbus_code = V4L2_MBUS_FMT_RGB565_2X8_BE,
  40. .flags = FMT_FLAGS_M2M,
  41. }, {
  42. .name = "BGR666",
  43. .fourcc = V4L2_PIX_FMT_BGR666,
  44. .depth = 32,
  45. .color = S5P_FIMC_RGB666,
  46. .buff_cnt = 1,
  47. .planes_cnt = 1,
  48. .flags = FMT_FLAGS_M2M,
  49. }, {
  50. .name = "XRGB-8-8-8-8, 32 bpp",
  51. .fourcc = V4L2_PIX_FMT_RGB32,
  52. .depth = 32,
  53. .color = S5P_FIMC_RGB888,
  54. .buff_cnt = 1,
  55. .planes_cnt = 1,
  56. .flags = FMT_FLAGS_M2M,
  57. }, {
  58. .name = "YUV 4:2:2 packed, YCbYCr",
  59. .fourcc = V4L2_PIX_FMT_YUYV,
  60. .depth = 16,
  61. .color = S5P_FIMC_YCBYCR422,
  62. .buff_cnt = 1,
  63. .planes_cnt = 1,
  64. .mbus_code = V4L2_MBUS_FMT_YUYV8_2X8,
  65. .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM,
  66. }, {
  67. .name = "YUV 4:2:2 packed, CbYCrY",
  68. .fourcc = V4L2_PIX_FMT_UYVY,
  69. .depth = 16,
  70. .color = S5P_FIMC_CBYCRY422,
  71. .buff_cnt = 1,
  72. .planes_cnt = 1,
  73. .mbus_code = V4L2_MBUS_FMT_UYVY8_2X8,
  74. .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM,
  75. }, {
  76. .name = "YUV 4:2:2 packed, CrYCbY",
  77. .fourcc = V4L2_PIX_FMT_VYUY,
  78. .depth = 16,
  79. .color = S5P_FIMC_CRYCBY422,
  80. .buff_cnt = 1,
  81. .planes_cnt = 1,
  82. .mbus_code = V4L2_MBUS_FMT_VYUY8_2X8,
  83. .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM,
  84. }, {
  85. .name = "YUV 4:2:2 packed, YCrYCb",
  86. .fourcc = V4L2_PIX_FMT_YVYU,
  87. .depth = 16,
  88. .color = S5P_FIMC_YCRYCB422,
  89. .buff_cnt = 1,
  90. .planes_cnt = 1,
  91. .mbus_code = V4L2_MBUS_FMT_YVYU8_2X8,
  92. .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM,
  93. }, {
  94. .name = "YUV 4:2:2 planar, Y/Cb/Cr",
  95. .fourcc = V4L2_PIX_FMT_YUV422P,
  96. .depth = 12,
  97. .color = S5P_FIMC_YCBCR422,
  98. .buff_cnt = 1,
  99. .planes_cnt = 3,
  100. .flags = FMT_FLAGS_M2M,
  101. }, {
  102. .name = "YUV 4:2:2 planar, Y/CbCr",
  103. .fourcc = V4L2_PIX_FMT_NV16,
  104. .depth = 16,
  105. .color = S5P_FIMC_YCBCR422,
  106. .buff_cnt = 1,
  107. .planes_cnt = 2,
  108. .flags = FMT_FLAGS_M2M,
  109. }, {
  110. .name = "YUV 4:2:2 planar, Y/CrCb",
  111. .fourcc = V4L2_PIX_FMT_NV61,
  112. .depth = 16,
  113. .color = S5P_FIMC_RGB565,
  114. .buff_cnt = 1,
  115. .planes_cnt = 2,
  116. .flags = FMT_FLAGS_M2M,
  117. }, {
  118. .name = "YUV 4:2:0 planar, YCbCr",
  119. .fourcc = V4L2_PIX_FMT_YUV420,
  120. .depth = 12,
  121. .color = S5P_FIMC_YCBCR420,
  122. .buff_cnt = 1,
  123. .planes_cnt = 3,
  124. .flags = FMT_FLAGS_M2M,
  125. }, {
  126. .name = "YUV 4:2:0 planar, Y/CbCr",
  127. .fourcc = V4L2_PIX_FMT_NV12,
  128. .depth = 12,
  129. .color = S5P_FIMC_YCBCR420,
  130. .buff_cnt = 1,
  131. .planes_cnt = 2,
  132. .flags = FMT_FLAGS_M2M,
  133. },
  134. };
  135. static struct v4l2_queryctrl fimc_ctrls[] = {
  136. {
  137. .id = V4L2_CID_HFLIP,
  138. .type = V4L2_CTRL_TYPE_BOOLEAN,
  139. .name = "Horizontal flip",
  140. .minimum = 0,
  141. .maximum = 1,
  142. .default_value = 0,
  143. }, {
  144. .id = V4L2_CID_VFLIP,
  145. .type = V4L2_CTRL_TYPE_BOOLEAN,
  146. .name = "Vertical flip",
  147. .minimum = 0,
  148. .maximum = 1,
  149. .default_value = 0,
  150. }, {
  151. .id = V4L2_CID_ROTATE,
  152. .type = V4L2_CTRL_TYPE_INTEGER,
  153. .name = "Rotation (CCW)",
  154. .minimum = 0,
  155. .maximum = 270,
  156. .step = 90,
  157. .default_value = 0,
  158. },
  159. };
  160. static struct v4l2_queryctrl *get_ctrl(int id)
  161. {
  162. int i;
  163. for (i = 0; i < ARRAY_SIZE(fimc_ctrls); ++i)
  164. if (id == fimc_ctrls[i].id)
  165. return &fimc_ctrls[i];
  166. return NULL;
  167. }
  168. int fimc_check_scaler_ratio(struct v4l2_rect *r, struct fimc_frame *f)
  169. {
  170. if (r->width > f->width) {
  171. if (f->width > (r->width * SCALER_MAX_HRATIO))
  172. return -EINVAL;
  173. } else {
  174. if ((f->width * SCALER_MAX_HRATIO) < r->width)
  175. return -EINVAL;
  176. }
  177. if (r->height > f->height) {
  178. if (f->height > (r->height * SCALER_MAX_VRATIO))
  179. return -EINVAL;
  180. } else {
  181. if ((f->height * SCALER_MAX_VRATIO) < r->height)
  182. return -EINVAL;
  183. }
  184. return 0;
  185. }
  186. static int fimc_get_scaler_factor(u32 src, u32 tar, u32 *ratio, u32 *shift)
  187. {
  188. u32 sh = 6;
  189. if (src >= 64 * tar)
  190. return -EINVAL;
  191. while (sh--) {
  192. u32 tmp = 1 << sh;
  193. if (src >= tar * tmp) {
  194. *shift = sh, *ratio = tmp;
  195. return 0;
  196. }
  197. }
  198. *shift = 0, *ratio = 1;
  199. dbg("s: %d, t: %d, shift: %d, ratio: %d",
  200. src, tar, *shift, *ratio);
  201. return 0;
  202. }
  203. int fimc_set_scaler_info(struct fimc_ctx *ctx)
  204. {
  205. struct fimc_scaler *sc = &ctx->scaler;
  206. struct fimc_frame *s_frame = &ctx->s_frame;
  207. struct fimc_frame *d_frame = &ctx->d_frame;
  208. int tx, ty, sx, sy;
  209. int ret;
  210. if (ctx->rotation == 90 || ctx->rotation == 270) {
  211. ty = d_frame->width;
  212. tx = d_frame->height;
  213. } else {
  214. tx = d_frame->width;
  215. ty = d_frame->height;
  216. }
  217. if (tx <= 0 || ty <= 0) {
  218. v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
  219. "invalid target size: %d x %d", tx, ty);
  220. return -EINVAL;
  221. }
  222. sx = s_frame->width;
  223. sy = s_frame->height;
  224. if (sx <= 0 || sy <= 0) {
  225. err("invalid source size: %d x %d", sx, sy);
  226. return -EINVAL;
  227. }
  228. sc->real_width = sx;
  229. sc->real_height = sy;
  230. dbg("sx= %d, sy= %d, tx= %d, ty= %d", sx, sy, tx, ty);
  231. ret = fimc_get_scaler_factor(sx, tx, &sc->pre_hratio, &sc->hfactor);
  232. if (ret)
  233. return ret;
  234. ret = fimc_get_scaler_factor(sy, ty, &sc->pre_vratio, &sc->vfactor);
  235. if (ret)
  236. return ret;
  237. sc->pre_dst_width = sx / sc->pre_hratio;
  238. sc->pre_dst_height = sy / sc->pre_vratio;
  239. sc->main_hratio = (sx << 8) / (tx << sc->hfactor);
  240. sc->main_vratio = (sy << 8) / (ty << sc->vfactor);
  241. sc->scaleup_h = (tx >= sx) ? 1 : 0;
  242. sc->scaleup_v = (ty >= sy) ? 1 : 0;
  243. /* check to see if input and output size/format differ */
  244. if (s_frame->fmt->color == d_frame->fmt->color
  245. && s_frame->width == d_frame->width
  246. && s_frame->height == d_frame->height)
  247. sc->copy_mode = 1;
  248. else
  249. sc->copy_mode = 0;
  250. return 0;
  251. }
  252. static void fimc_capture_handler(struct fimc_dev *fimc)
  253. {
  254. struct fimc_vid_cap *cap = &fimc->vid_cap;
  255. struct fimc_vid_buffer *v_buf = NULL;
  256. if (!list_empty(&cap->active_buf_q)) {
  257. v_buf = active_queue_pop(cap);
  258. vb2_buffer_done(&v_buf->vb, VB2_BUF_STATE_DONE);
  259. }
  260. if (test_and_clear_bit(ST_CAPT_SHUT, &fimc->state)) {
  261. wake_up(&fimc->irq_queue);
  262. return;
  263. }
  264. if (!list_empty(&cap->pending_buf_q)) {
  265. v_buf = pending_queue_pop(cap);
  266. fimc_hw_set_output_addr(fimc, &v_buf->paddr, cap->buf_index);
  267. v_buf->index = cap->buf_index;
  268. dbg("hw ptr: %d, sw ptr: %d",
  269. fimc_hw_get_frame_index(fimc), cap->buf_index);
  270. /* Move the buffer to the capture active queue */
  271. active_queue_add(cap, v_buf);
  272. dbg("next frame: %d, done frame: %d",
  273. fimc_hw_get_frame_index(fimc), v_buf->index);
  274. if (++cap->buf_index >= FIMC_MAX_OUT_BUFS)
  275. cap->buf_index = 0;
  276. } else if (test_and_clear_bit(ST_CAPT_STREAM, &fimc->state) &&
  277. cap->active_buf_cnt <= 1) {
  278. fimc_deactivate_capture(fimc);
  279. }
  280. dbg("frame: %d, active_buf_cnt= %d",
  281. fimc_hw_get_frame_index(fimc), cap->active_buf_cnt);
  282. }
  283. static irqreturn_t fimc_isr(int irq, void *priv)
  284. {
  285. struct fimc_dev *fimc = priv;
  286. BUG_ON(!fimc);
  287. fimc_hw_clear_irq(fimc);
  288. spin_lock(&fimc->slock);
  289. if (test_and_clear_bit(ST_M2M_PEND, &fimc->state)) {
  290. struct vb2_buffer *src_vb, *dst_vb;
  291. struct fimc_ctx *ctx = v4l2_m2m_get_curr_priv(fimc->m2m.m2m_dev);
  292. if (!ctx || !ctx->m2m_ctx)
  293. goto isr_unlock;
  294. src_vb = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
  295. dst_vb = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
  296. if (src_vb && dst_vb) {
  297. v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_DONE);
  298. v4l2_m2m_buf_done(dst_vb, VB2_BUF_STATE_DONE);
  299. v4l2_m2m_job_finish(fimc->m2m.m2m_dev, ctx->m2m_ctx);
  300. }
  301. goto isr_unlock;
  302. }
  303. if (test_bit(ST_CAPT_RUN, &fimc->state))
  304. fimc_capture_handler(fimc);
  305. if (test_and_clear_bit(ST_CAPT_PEND, &fimc->state)) {
  306. set_bit(ST_CAPT_RUN, &fimc->state);
  307. wake_up(&fimc->irq_queue);
  308. }
  309. isr_unlock:
  310. spin_unlock(&fimc->slock);
  311. return IRQ_HANDLED;
  312. }
  313. /* The color format (planes_cnt, buff_cnt) must be already configured. */
  314. int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
  315. struct fimc_frame *frame, struct fimc_addr *paddr)
  316. {
  317. int ret = 0;
  318. u32 pix_size;
  319. if (vb == NULL || frame == NULL)
  320. return -EINVAL;
  321. pix_size = frame->width * frame->height;
  322. dbg("buff_cnt= %d, planes_cnt= %d, frame->size= %d, pix_size= %d",
  323. frame->fmt->buff_cnt, frame->fmt->planes_cnt,
  324. frame->size, pix_size);
  325. if (frame->fmt->buff_cnt == 1) {
  326. paddr->y = vb2_dma_contig_plane_paddr(vb, 0);
  327. switch (frame->fmt->planes_cnt) {
  328. case 1:
  329. paddr->cb = 0;
  330. paddr->cr = 0;
  331. break;
  332. case 2:
  333. /* decompose Y into Y/Cb */
  334. paddr->cb = (u32)(paddr->y + pix_size);
  335. paddr->cr = 0;
  336. break;
  337. case 3:
  338. paddr->cb = (u32)(paddr->y + pix_size);
  339. /* decompose Y into Y/Cb/Cr */
  340. if (S5P_FIMC_YCBCR420 == frame->fmt->color)
  341. paddr->cr = (u32)(paddr->cb
  342. + (pix_size >> 2));
  343. else /* 422 */
  344. paddr->cr = (u32)(paddr->cb
  345. + (pix_size >> 1));
  346. break;
  347. default:
  348. return -EINVAL;
  349. }
  350. }
  351. dbg("PHYS_ADDR: y= 0x%X cb= 0x%X cr= 0x%X ret= %d",
  352. paddr->y, paddr->cb, paddr->cr, ret);
  353. return ret;
  354. }
  355. /* Set order for 1 and 2 plane YCBCR 4:2:2 formats. */
  356. static void fimc_set_yuv_order(struct fimc_ctx *ctx)
  357. {
  358. /* The one only mode supported in SoC. */
  359. ctx->in_order_2p = S5P_FIMC_LSB_CRCB;
  360. ctx->out_order_2p = S5P_FIMC_LSB_CRCB;
  361. /* Set order for 1 plane input formats. */
  362. switch (ctx->s_frame.fmt->color) {
  363. case S5P_FIMC_YCRYCB422:
  364. ctx->in_order_1p = S5P_FIMC_IN_YCRYCB;
  365. break;
  366. case S5P_FIMC_CBYCRY422:
  367. ctx->in_order_1p = S5P_FIMC_IN_CBYCRY;
  368. break;
  369. case S5P_FIMC_CRYCBY422:
  370. ctx->in_order_1p = S5P_FIMC_IN_CRYCBY;
  371. break;
  372. case S5P_FIMC_YCBYCR422:
  373. default:
  374. ctx->in_order_1p = S5P_FIMC_IN_YCBYCR;
  375. break;
  376. }
  377. dbg("ctx->in_order_1p= %d", ctx->in_order_1p);
  378. switch (ctx->d_frame.fmt->color) {
  379. case S5P_FIMC_YCRYCB422:
  380. ctx->out_order_1p = S5P_FIMC_OUT_YCRYCB;
  381. break;
  382. case S5P_FIMC_CBYCRY422:
  383. ctx->out_order_1p = S5P_FIMC_OUT_CBYCRY;
  384. break;
  385. case S5P_FIMC_CRYCBY422:
  386. ctx->out_order_1p = S5P_FIMC_OUT_CRYCBY;
  387. break;
  388. case S5P_FIMC_YCBYCR422:
  389. default:
  390. ctx->out_order_1p = S5P_FIMC_OUT_YCBYCR;
  391. break;
  392. }
  393. dbg("ctx->out_order_1p= %d", ctx->out_order_1p);
  394. }
  395. static void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f)
  396. {
  397. struct samsung_fimc_variant *variant = ctx->fimc_dev->variant;
  398. f->dma_offset.y_h = f->offs_h;
  399. if (!variant->pix_hoff)
  400. f->dma_offset.y_h *= (f->fmt->depth >> 3);
  401. f->dma_offset.y_v = f->offs_v;
  402. f->dma_offset.cb_h = f->offs_h;
  403. f->dma_offset.cb_v = f->offs_v;
  404. f->dma_offset.cr_h = f->offs_h;
  405. f->dma_offset.cr_v = f->offs_v;
  406. if (!variant->pix_hoff) {
  407. if (f->fmt->planes_cnt == 3) {
  408. f->dma_offset.cb_h >>= 1;
  409. f->dma_offset.cr_h >>= 1;
  410. }
  411. if (f->fmt->color == S5P_FIMC_YCBCR420) {
  412. f->dma_offset.cb_v >>= 1;
  413. f->dma_offset.cr_v >>= 1;
  414. }
  415. }
  416. dbg("in_offset: color= %d, y_h= %d, y_v= %d",
  417. f->fmt->color, f->dma_offset.y_h, f->dma_offset.y_v);
  418. }
  419. /**
  420. * fimc_prepare_config - check dimensions, operation and color mode
  421. * and pre-calculate offset and the scaling coefficients.
  422. *
  423. * @ctx: hardware context information
  424. * @flags: flags indicating which parameters to check/update
  425. *
  426. * Return: 0 if dimensions are valid or non zero otherwise.
  427. */
  428. int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags)
  429. {
  430. struct fimc_frame *s_frame, *d_frame;
  431. struct vb2_buffer *vb = NULL;
  432. int ret = 0;
  433. s_frame = &ctx->s_frame;
  434. d_frame = &ctx->d_frame;
  435. if (flags & FIMC_PARAMS) {
  436. /* Prepare the DMA offset ratios for scaler. */
  437. fimc_prepare_dma_offset(ctx, &ctx->s_frame);
  438. fimc_prepare_dma_offset(ctx, &ctx->d_frame);
  439. if (s_frame->height > (SCALER_MAX_VRATIO * d_frame->height) ||
  440. s_frame->width > (SCALER_MAX_HRATIO * d_frame->width)) {
  441. err("out of scaler range");
  442. return -EINVAL;
  443. }
  444. fimc_set_yuv_order(ctx);
  445. }
  446. /* Input DMA mode is not allowed when the scaler is disabled. */
  447. ctx->scaler.enabled = 1;
  448. if (flags & FIMC_SRC_ADDR) {
  449. vb = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
  450. ret = fimc_prepare_addr(ctx, vb, s_frame, &s_frame->paddr);
  451. if (ret)
  452. return ret;
  453. }
  454. if (flags & FIMC_DST_ADDR) {
  455. vb = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
  456. ret = fimc_prepare_addr(ctx, vb, d_frame, &d_frame->paddr);
  457. }
  458. return ret;
  459. }
  460. static void fimc_dma_run(void *priv)
  461. {
  462. struct fimc_ctx *ctx = priv;
  463. struct fimc_dev *fimc;
  464. unsigned long flags;
  465. u32 ret;
  466. if (WARN(!ctx, "null hardware context\n"))
  467. return;
  468. fimc = ctx->fimc_dev;
  469. spin_lock_irqsave(&ctx->slock, flags);
  470. set_bit(ST_M2M_PEND, &fimc->state);
  471. ctx->state |= (FIMC_SRC_ADDR | FIMC_DST_ADDR);
  472. ret = fimc_prepare_config(ctx, ctx->state);
  473. if (ret) {
  474. err("Wrong parameters");
  475. goto dma_unlock;
  476. }
  477. /* Reconfigure hardware if the context has changed. */
  478. if (fimc->m2m.ctx != ctx) {
  479. ctx->state |= FIMC_PARAMS;
  480. fimc->m2m.ctx = ctx;
  481. }
  482. fimc_hw_set_input_addr(fimc, &ctx->s_frame.paddr);
  483. if (ctx->state & FIMC_PARAMS) {
  484. fimc_hw_set_input_path(ctx);
  485. fimc_hw_set_in_dma(ctx);
  486. if (fimc_set_scaler_info(ctx)) {
  487. err("Scaler setup error");
  488. goto dma_unlock;
  489. }
  490. fimc_hw_set_scaler(ctx);
  491. fimc_hw_set_target_format(ctx);
  492. fimc_hw_set_rotation(ctx);
  493. fimc_hw_set_effect(ctx);
  494. }
  495. fimc_hw_set_output_path(ctx);
  496. if (ctx->state & (FIMC_DST_ADDR | FIMC_PARAMS))
  497. fimc_hw_set_output_addr(fimc, &ctx->d_frame.paddr, -1);
  498. if (ctx->state & FIMC_PARAMS)
  499. fimc_hw_set_out_dma(ctx);
  500. fimc_activate_capture(ctx);
  501. ctx->state &= (FIMC_CTX_M2M | FIMC_CTX_CAP |
  502. FIMC_SRC_FMT | FIMC_DST_FMT);
  503. fimc_hw_activate_input_dma(fimc, true);
  504. dma_unlock:
  505. spin_unlock_irqrestore(&ctx->slock, flags);
  506. }
  507. static void fimc_job_abort(void *priv)
  508. {
  509. /* Nothing done in job_abort. */
  510. }
  511. static int fimc_queue_setup(struct vb2_queue *vq, unsigned int *num_buffers,
  512. unsigned int *num_planes, unsigned long sizes[],
  513. void *allocators[])
  514. {
  515. struct fimc_ctx *ctx = vb2_get_drv_priv(vq);
  516. struct fimc_frame *fr;
  517. fr = ctx_get_frame(ctx, vq->type);
  518. if (IS_ERR(fr))
  519. return PTR_ERR(fr);
  520. *num_planes = 1;
  521. sizes[0] = (fr->width * fr->height * fr->fmt->depth) >> 3;
  522. allocators[0] = ctx->fimc_dev->alloc_ctx;
  523. return 0;
  524. }
  525. static int fimc_buf_prepare(struct vb2_buffer *vb)
  526. {
  527. struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
  528. struct fimc_frame *frame;
  529. frame = ctx_get_frame(ctx, vb->vb2_queue->type);
  530. if (IS_ERR(frame))
  531. return PTR_ERR(frame);
  532. if (vb2_plane_size(vb, 0) < frame->size) {
  533. dbg("%s data will not fit into plane (%lu < %lu)\n",
  534. __func__, vb2_plane_size(vb, 0), (long)frame->size);
  535. return -EINVAL;
  536. }
  537. vb2_set_plane_payload(vb, 0, frame->size);
  538. return 0;
  539. }
  540. static void fimc_buf_queue(struct vb2_buffer *vb)
  541. {
  542. struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
  543. dbg("ctx: %p, ctx->state: 0x%x", ctx, ctx->state);
  544. if (ctx->m2m_ctx)
  545. v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
  546. }
  547. static void fimc_lock(struct vb2_queue *vq)
  548. {
  549. struct fimc_ctx *ctx = vb2_get_drv_priv(vq);
  550. mutex_lock(&ctx->fimc_dev->lock);
  551. }
  552. static void fimc_unlock(struct vb2_queue *vq)
  553. {
  554. struct fimc_ctx *ctx = vb2_get_drv_priv(vq);
  555. mutex_unlock(&ctx->fimc_dev->lock);
  556. }
  557. struct vb2_ops fimc_qops = {
  558. .queue_setup = fimc_queue_setup,
  559. .buf_prepare = fimc_buf_prepare,
  560. .buf_queue = fimc_buf_queue,
  561. .wait_prepare = fimc_unlock,
  562. .wait_finish = fimc_lock,
  563. };
  564. static int fimc_m2m_querycap(struct file *file, void *priv,
  565. struct v4l2_capability *cap)
  566. {
  567. struct fimc_ctx *ctx = file->private_data;
  568. struct fimc_dev *fimc = ctx->fimc_dev;
  569. strncpy(cap->driver, fimc->pdev->name, sizeof(cap->driver) - 1);
  570. strncpy(cap->card, fimc->pdev->name, sizeof(cap->card) - 1);
  571. cap->bus_info[0] = 0;
  572. cap->version = KERNEL_VERSION(1, 0, 0);
  573. cap->capabilities = V4L2_CAP_STREAMING |
  574. V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT;
  575. return 0;
  576. }
  577. int fimc_vidioc_enum_fmt(struct file *file, void *priv,
  578. struct v4l2_fmtdesc *f)
  579. {
  580. struct fimc_fmt *fmt;
  581. if (f->index >= ARRAY_SIZE(fimc_formats))
  582. return -EINVAL;
  583. fmt = &fimc_formats[f->index];
  584. strncpy(f->description, fmt->name, sizeof(f->description) - 1);
  585. f->pixelformat = fmt->fourcc;
  586. return 0;
  587. }
  588. int fimc_vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
  589. {
  590. struct fimc_ctx *ctx = priv;
  591. struct fimc_dev *fimc = ctx->fimc_dev;
  592. struct fimc_frame *frame;
  593. frame = ctx_get_frame(ctx, f->type);
  594. if (IS_ERR(frame))
  595. return PTR_ERR(frame);
  596. if (mutex_lock_interruptible(&fimc->lock))
  597. return -ERESTARTSYS;
  598. f->fmt.pix.width = frame->width;
  599. f->fmt.pix.height = frame->height;
  600. f->fmt.pix.field = V4L2_FIELD_NONE;
  601. f->fmt.pix.pixelformat = frame->fmt->fourcc;
  602. mutex_unlock(&fimc->lock);
  603. return 0;
  604. }
  605. struct fimc_fmt *find_format(struct v4l2_format *f, unsigned int mask)
  606. {
  607. struct fimc_fmt *fmt;
  608. unsigned int i;
  609. for (i = 0; i < ARRAY_SIZE(fimc_formats); ++i) {
  610. fmt = &fimc_formats[i];
  611. if (fmt->fourcc == f->fmt.pix.pixelformat &&
  612. (fmt->flags & mask))
  613. break;
  614. }
  615. return (i == ARRAY_SIZE(fimc_formats)) ? NULL : fmt;
  616. }
  617. struct fimc_fmt *find_mbus_format(struct v4l2_mbus_framefmt *f,
  618. unsigned int mask)
  619. {
  620. struct fimc_fmt *fmt;
  621. unsigned int i;
  622. for (i = 0; i < ARRAY_SIZE(fimc_formats); ++i) {
  623. fmt = &fimc_formats[i];
  624. if (fmt->mbus_code == f->code && (fmt->flags & mask))
  625. break;
  626. }
  627. return (i == ARRAY_SIZE(fimc_formats)) ? NULL : fmt;
  628. }
  629. int fimc_vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f)
  630. {
  631. struct fimc_ctx *ctx = priv;
  632. struct fimc_dev *fimc = ctx->fimc_dev;
  633. struct samsung_fimc_variant *variant = fimc->variant;
  634. struct v4l2_pix_format *pix = &f->fmt.pix;
  635. struct fimc_fmt *fmt;
  636. u32 max_width, mod_x, mod_y, mask;
  637. int ret = -EINVAL, is_output = 0;
  638. if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
  639. if (ctx->state & FIMC_CTX_CAP)
  640. return -EINVAL;
  641. is_output = 1;
  642. } else if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  643. return -EINVAL;
  644. }
  645. dbg("w: %d, h: %d, bpl: %d",
  646. pix->width, pix->height, pix->bytesperline);
  647. if (mutex_lock_interruptible(&fimc->lock))
  648. return -ERESTARTSYS;
  649. mask = is_output ? FMT_FLAGS_M2M : FMT_FLAGS_M2M | FMT_FLAGS_CAM;
  650. fmt = find_format(f, mask);
  651. if (!fmt) {
  652. v4l2_err(&fimc->m2m.v4l2_dev, "Fourcc format (0x%X) invalid.\n",
  653. pix->pixelformat);
  654. goto tf_out;
  655. }
  656. if (pix->field == V4L2_FIELD_ANY)
  657. pix->field = V4L2_FIELD_NONE;
  658. else if (V4L2_FIELD_NONE != pix->field)
  659. goto tf_out;
  660. if (is_output) {
  661. max_width = variant->pix_limit->scaler_dis_w;
  662. mod_x = ffs(variant->min_inp_pixsize) - 1;
  663. } else {
  664. max_width = variant->pix_limit->out_rot_dis_w;
  665. mod_x = ffs(variant->min_out_pixsize) - 1;
  666. }
  667. if (tiled_fmt(fmt)) {
  668. mod_x = 6; /* 64 x 32 pixels tile */
  669. mod_y = 5;
  670. } else {
  671. if (fimc->id == 1 && fimc->variant->pix_hoff)
  672. mod_y = fimc_fmt_is_rgb(fmt->color) ? 0 : 1;
  673. else
  674. mod_y = mod_x;
  675. }
  676. dbg("mod_x: %d, mod_y: %d, max_w: %d", mod_x, mod_y, max_width);
  677. v4l_bound_align_image(&pix->width, 16, max_width, mod_x,
  678. &pix->height, 8, variant->pix_limit->scaler_dis_w, mod_y, 0);
  679. if (pix->bytesperline == 0 ||
  680. (pix->bytesperline * 8 / fmt->depth) > pix->width)
  681. pix->bytesperline = (pix->width * fmt->depth) >> 3;
  682. if (pix->sizeimage == 0)
  683. pix->sizeimage = pix->height * pix->bytesperline;
  684. dbg("w: %d, h: %d, bpl: %d, depth: %d",
  685. pix->width, pix->height, pix->bytesperline, fmt->depth);
  686. ret = 0;
  687. tf_out:
  688. mutex_unlock(&fimc->lock);
  689. return ret;
  690. }
  691. static int fimc_m2m_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
  692. {
  693. struct fimc_ctx *ctx = priv;
  694. struct fimc_dev *fimc = ctx->fimc_dev;
  695. struct v4l2_device *v4l2_dev = &fimc->m2m.v4l2_dev;
  696. struct vb2_queue *vq;
  697. struct fimc_frame *frame;
  698. struct v4l2_pix_format *pix;
  699. unsigned long flags;
  700. int ret = 0;
  701. ret = fimc_vidioc_try_fmt(file, priv, f);
  702. if (ret)
  703. return ret;
  704. if (mutex_lock_interruptible(&fimc->lock))
  705. return -ERESTARTSYS;
  706. vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
  707. if (vb2_is_streaming(vq)) {
  708. v4l2_err(v4l2_dev, "%s: queue (%d) busy\n", __func__, f->type);
  709. ret = -EBUSY;
  710. goto sf_out;
  711. }
  712. spin_lock_irqsave(&ctx->slock, flags);
  713. if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
  714. frame = &ctx->s_frame;
  715. ctx->state |= FIMC_SRC_FMT;
  716. } else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  717. frame = &ctx->d_frame;
  718. ctx->state |= FIMC_DST_FMT;
  719. } else {
  720. spin_unlock_irqrestore(&ctx->slock, flags);
  721. v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
  722. "Wrong buffer/video queue type (%d)\n", f->type);
  723. ret = -EINVAL;
  724. goto sf_out;
  725. }
  726. spin_unlock_irqrestore(&ctx->slock, flags);
  727. pix = &f->fmt.pix;
  728. frame->fmt = find_format(f, FMT_FLAGS_M2M);
  729. if (!frame->fmt) {
  730. ret = -EINVAL;
  731. goto sf_out;
  732. }
  733. frame->f_width = pix->bytesperline * 8 / frame->fmt->depth;
  734. frame->f_height = pix->height;
  735. frame->width = pix->width;
  736. frame->height = pix->height;
  737. frame->o_width = pix->width;
  738. frame->o_height = pix->height;
  739. frame->offs_h = 0;
  740. frame->offs_v = 0;
  741. frame->size = (pix->width * pix->height * frame->fmt->depth) >> 3;
  742. spin_lock_irqsave(&ctx->slock, flags);
  743. ctx->state |= FIMC_PARAMS;
  744. spin_unlock_irqrestore(&ctx->slock, flags);
  745. dbg("f_w: %d, f_h: %d", frame->f_width, frame->f_height);
  746. sf_out:
  747. mutex_unlock(&fimc->lock);
  748. return ret;
  749. }
  750. static int fimc_m2m_reqbufs(struct file *file, void *priv,
  751. struct v4l2_requestbuffers *reqbufs)
  752. {
  753. struct fimc_ctx *ctx = priv;
  754. return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
  755. }
  756. static int fimc_m2m_querybuf(struct file *file, void *priv,
  757. struct v4l2_buffer *buf)
  758. {
  759. struct fimc_ctx *ctx = priv;
  760. return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
  761. }
  762. static int fimc_m2m_qbuf(struct file *file, void *priv,
  763. struct v4l2_buffer *buf)
  764. {
  765. struct fimc_ctx *ctx = priv;
  766. return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
  767. }
  768. static int fimc_m2m_dqbuf(struct file *file, void *priv,
  769. struct v4l2_buffer *buf)
  770. {
  771. struct fimc_ctx *ctx = priv;
  772. return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf);
  773. }
  774. static int fimc_m2m_streamon(struct file *file, void *priv,
  775. enum v4l2_buf_type type)
  776. {
  777. struct fimc_ctx *ctx = priv;
  778. /* The source and target color format need to be set */
  779. if (~ctx->state & (FIMC_DST_FMT | FIMC_SRC_FMT))
  780. return -EINVAL;
  781. return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
  782. }
  783. static int fimc_m2m_streamoff(struct file *file, void *priv,
  784. enum v4l2_buf_type type)
  785. {
  786. struct fimc_ctx *ctx = priv;
  787. return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type);
  788. }
  789. int fimc_vidioc_queryctrl(struct file *file, void *priv,
  790. struct v4l2_queryctrl *qc)
  791. {
  792. struct fimc_ctx *ctx = priv;
  793. struct v4l2_queryctrl *c;
  794. int ret = -EINVAL;
  795. c = get_ctrl(qc->id);
  796. if (c) {
  797. *qc = *c;
  798. return 0;
  799. }
  800. if (ctx->state & FIMC_CTX_CAP) {
  801. if (mutex_lock_interruptible(&ctx->fimc_dev->lock))
  802. return -ERESTARTSYS;
  803. ret = v4l2_subdev_call(ctx->fimc_dev->vid_cap.sd,
  804. core, queryctrl, qc);
  805. mutex_unlock(&ctx->fimc_dev->lock);
  806. }
  807. return ret;
  808. }
  809. int fimc_vidioc_g_ctrl(struct file *file, void *priv,
  810. struct v4l2_control *ctrl)
  811. {
  812. struct fimc_ctx *ctx = priv;
  813. struct fimc_dev *fimc = ctx->fimc_dev;
  814. int ret = 0;
  815. if (mutex_lock_interruptible(&fimc->lock))
  816. return -ERESTARTSYS;
  817. switch (ctrl->id) {
  818. case V4L2_CID_HFLIP:
  819. ctrl->value = (FLIP_X_AXIS & ctx->flip) ? 1 : 0;
  820. break;
  821. case V4L2_CID_VFLIP:
  822. ctrl->value = (FLIP_Y_AXIS & ctx->flip) ? 1 : 0;
  823. break;
  824. case V4L2_CID_ROTATE:
  825. ctrl->value = ctx->rotation;
  826. break;
  827. default:
  828. if (ctx->state & FIMC_CTX_CAP) {
  829. ret = v4l2_subdev_call(fimc->vid_cap.sd, core,
  830. g_ctrl, ctrl);
  831. } else {
  832. v4l2_err(&fimc->m2m.v4l2_dev,
  833. "Invalid control\n");
  834. ret = -EINVAL;
  835. }
  836. }
  837. dbg("ctrl->value= %d", ctrl->value);
  838. mutex_unlock(&fimc->lock);
  839. return ret;
  840. }
  841. int check_ctrl_val(struct fimc_ctx *ctx, struct v4l2_control *ctrl)
  842. {
  843. struct v4l2_queryctrl *c;
  844. c = get_ctrl(ctrl->id);
  845. if (!c)
  846. return -EINVAL;
  847. if (ctrl->value < c->minimum || ctrl->value > c->maximum
  848. || (c->step != 0 && ctrl->value % c->step != 0)) {
  849. v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
  850. "Invalid control value\n");
  851. return -ERANGE;
  852. }
  853. return 0;
  854. }
  855. int fimc_s_ctrl(struct fimc_ctx *ctx, struct v4l2_control *ctrl)
  856. {
  857. struct samsung_fimc_variant *variant = ctx->fimc_dev->variant;
  858. struct fimc_dev *fimc = ctx->fimc_dev;
  859. unsigned long flags;
  860. if (ctx->rotation != 0 &&
  861. (ctrl->id == V4L2_CID_HFLIP || ctrl->id == V4L2_CID_VFLIP)) {
  862. v4l2_err(&fimc->m2m.v4l2_dev,
  863. "Simultaneous flip and rotation is not supported\n");
  864. return -EINVAL;
  865. }
  866. spin_lock_irqsave(&ctx->slock, flags);
  867. switch (ctrl->id) {
  868. case V4L2_CID_HFLIP:
  869. if (ctrl->value)
  870. ctx->flip |= FLIP_X_AXIS;
  871. else
  872. ctx->flip &= ~FLIP_X_AXIS;
  873. break;
  874. case V4L2_CID_VFLIP:
  875. if (ctrl->value)
  876. ctx->flip |= FLIP_Y_AXIS;
  877. else
  878. ctx->flip &= ~FLIP_Y_AXIS;
  879. break;
  880. case V4L2_CID_ROTATE:
  881. /* Check for the output rotator availability */
  882. if ((ctrl->value == 90 || ctrl->value == 270) &&
  883. (ctx->in_path == FIMC_DMA && !variant->has_out_rot)) {
  884. spin_unlock_irqrestore(&ctx->slock, flags);
  885. return -EINVAL;
  886. } else {
  887. ctx->rotation = ctrl->value;
  888. }
  889. break;
  890. default:
  891. spin_unlock_irqrestore(&ctx->slock, flags);
  892. v4l2_err(&fimc->m2m.v4l2_dev, "Invalid control\n");
  893. return -EINVAL;
  894. }
  895. ctx->state |= FIMC_PARAMS;
  896. spin_unlock_irqrestore(&ctx->slock, flags);
  897. return 0;
  898. }
  899. static int fimc_m2m_s_ctrl(struct file *file, void *priv,
  900. struct v4l2_control *ctrl)
  901. {
  902. struct fimc_ctx *ctx = priv;
  903. int ret = 0;
  904. ret = check_ctrl_val(ctx, ctrl);
  905. if (ret)
  906. return ret;
  907. ret = fimc_s_ctrl(ctx, ctrl);
  908. return 0;
  909. }
  910. static int fimc_m2m_cropcap(struct file *file, void *fh,
  911. struct v4l2_cropcap *cr)
  912. {
  913. struct fimc_frame *frame;
  914. struct fimc_ctx *ctx = fh;
  915. struct fimc_dev *fimc = ctx->fimc_dev;
  916. frame = ctx_get_frame(ctx, cr->type);
  917. if (IS_ERR(frame))
  918. return PTR_ERR(frame);
  919. if (mutex_lock_interruptible(&fimc->lock))
  920. return -ERESTARTSYS;
  921. cr->bounds.left = 0;
  922. cr->bounds.top = 0;
  923. cr->bounds.width = frame->f_width;
  924. cr->bounds.height = frame->f_height;
  925. cr->defrect = cr->bounds;
  926. mutex_unlock(&fimc->lock);
  927. return 0;
  928. }
  929. static int fimc_m2m_g_crop(struct file *file, void *fh, struct v4l2_crop *cr)
  930. {
  931. struct fimc_frame *frame;
  932. struct fimc_ctx *ctx = file->private_data;
  933. struct fimc_dev *fimc = ctx->fimc_dev;
  934. frame = ctx_get_frame(ctx, cr->type);
  935. if (IS_ERR(frame))
  936. return PTR_ERR(frame);
  937. if (mutex_lock_interruptible(&fimc->lock))
  938. return -ERESTARTSYS;
  939. cr->c.left = frame->offs_h;
  940. cr->c.top = frame->offs_v;
  941. cr->c.width = frame->width;
  942. cr->c.height = frame->height;
  943. mutex_unlock(&fimc->lock);
  944. return 0;
  945. }
  946. int fimc_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr)
  947. {
  948. struct fimc_dev *fimc = ctx->fimc_dev;
  949. struct fimc_frame *f;
  950. u32 min_size, halign;
  951. if (cr->c.top < 0 || cr->c.left < 0) {
  952. v4l2_err(&fimc->m2m.v4l2_dev,
  953. "doesn't support negative values for top & left\n");
  954. return -EINVAL;
  955. }
  956. if (cr->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  957. f = (ctx->state & FIMC_CTX_CAP) ? &ctx->s_frame : &ctx->d_frame;
  958. else if (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
  959. ctx->state & FIMC_CTX_M2M)
  960. f = &ctx->s_frame;
  961. else
  962. return -EINVAL;
  963. min_size = (f == &ctx->s_frame) ?
  964. fimc->variant->min_inp_pixsize : fimc->variant->min_out_pixsize;
  965. if (ctx->state & FIMC_CTX_M2M) {
  966. if (fimc->id == 1 && fimc->variant->pix_hoff)
  967. halign = fimc_fmt_is_rgb(f->fmt->color) ? 0 : 1;
  968. else
  969. halign = ffs(min_size) - 1;
  970. /* there are more strict aligment requirements at camera interface */
  971. } else {
  972. min_size = 16;
  973. halign = 4;
  974. }
  975. v4l_bound_align_image(&cr->c.width, min_size, f->o_width,
  976. ffs(min_size) - 1,
  977. &cr->c.height, min_size, f->o_height,
  978. halign, 64/(ALIGN(f->fmt->depth, 8)));
  979. /* adjust left/top if cropping rectangle is out of bounds */
  980. if (cr->c.left + cr->c.width > f->o_width)
  981. cr->c.left = f->o_width - cr->c.width;
  982. if (cr->c.top + cr->c.height > f->o_height)
  983. cr->c.top = f->o_height - cr->c.height;
  984. cr->c.left = round_down(cr->c.left, min_size);
  985. cr->c.top = round_down(cr->c.top,
  986. ctx->state & FIMC_CTX_M2M ? 8 : 16);
  987. dbg("l:%d, t:%d, w:%d, h:%d, f_w: %d, f_h: %d",
  988. cr->c.left, cr->c.top, cr->c.width, cr->c.height,
  989. f->f_width, f->f_height);
  990. return 0;
  991. }
  992. static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
  993. {
  994. struct fimc_ctx *ctx = file->private_data;
  995. struct fimc_dev *fimc = ctx->fimc_dev;
  996. unsigned long flags;
  997. struct fimc_frame *f;
  998. int ret;
  999. ret = fimc_try_crop(ctx, cr);
  1000. if (ret)
  1001. return ret;
  1002. f = (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) ?
  1003. &ctx->s_frame : &ctx->d_frame;
  1004. if (mutex_lock_interruptible(&fimc->lock))
  1005. return -ERESTARTSYS;
  1006. spin_lock_irqsave(&ctx->slock, flags);
  1007. if (~ctx->state & (FIMC_SRC_FMT | FIMC_DST_FMT)) {
  1008. /* Check to see if scaling ratio is within supported range */
  1009. if (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
  1010. ret = fimc_check_scaler_ratio(&cr->c, &ctx->d_frame);
  1011. else
  1012. ret = fimc_check_scaler_ratio(&cr->c, &ctx->s_frame);
  1013. if (ret) {
  1014. v4l2_err(&fimc->m2m.v4l2_dev, "Out of scaler range");
  1015. ret = -EINVAL;
  1016. goto scr_unlock;
  1017. }
  1018. }
  1019. ctx->state |= FIMC_PARAMS;
  1020. f->offs_h = cr->c.left;
  1021. f->offs_v = cr->c.top;
  1022. f->width = cr->c.width;
  1023. f->height = cr->c.height;
  1024. scr_unlock:
  1025. spin_unlock_irqrestore(&ctx->slock, flags);
  1026. mutex_unlock(&fimc->lock);
  1027. return 0;
  1028. }
  1029. static const struct v4l2_ioctl_ops fimc_m2m_ioctl_ops = {
  1030. .vidioc_querycap = fimc_m2m_querycap,
  1031. .vidioc_enum_fmt_vid_cap = fimc_vidioc_enum_fmt,
  1032. .vidioc_enum_fmt_vid_out = fimc_vidioc_enum_fmt,
  1033. .vidioc_g_fmt_vid_cap = fimc_vidioc_g_fmt,
  1034. .vidioc_g_fmt_vid_out = fimc_vidioc_g_fmt,
  1035. .vidioc_try_fmt_vid_cap = fimc_vidioc_try_fmt,
  1036. .vidioc_try_fmt_vid_out = fimc_vidioc_try_fmt,
  1037. .vidioc_s_fmt_vid_cap = fimc_m2m_s_fmt,
  1038. .vidioc_s_fmt_vid_out = fimc_m2m_s_fmt,
  1039. .vidioc_reqbufs = fimc_m2m_reqbufs,
  1040. .vidioc_querybuf = fimc_m2m_querybuf,
  1041. .vidioc_qbuf = fimc_m2m_qbuf,
  1042. .vidioc_dqbuf = fimc_m2m_dqbuf,
  1043. .vidioc_streamon = fimc_m2m_streamon,
  1044. .vidioc_streamoff = fimc_m2m_streamoff,
  1045. .vidioc_queryctrl = fimc_vidioc_queryctrl,
  1046. .vidioc_g_ctrl = fimc_vidioc_g_ctrl,
  1047. .vidioc_s_ctrl = fimc_m2m_s_ctrl,
  1048. .vidioc_g_crop = fimc_m2m_g_crop,
  1049. .vidioc_s_crop = fimc_m2m_s_crop,
  1050. .vidioc_cropcap = fimc_m2m_cropcap
  1051. };
  1052. static int queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq)
  1053. {
  1054. struct fimc_ctx *ctx = priv;
  1055. int ret;
  1056. memset(src_vq, 0, sizeof(*src_vq));
  1057. src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
  1058. src_vq->io_modes = VB2_MMAP | VB2_USERPTR;
  1059. src_vq->drv_priv = ctx;
  1060. src_vq->ops = &fimc_qops;
  1061. src_vq->mem_ops = &vb2_dma_contig_memops;
  1062. src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
  1063. ret = vb2_queue_init(src_vq);
  1064. if (ret)
  1065. return ret;
  1066. memset(dst_vq, 0, sizeof(*dst_vq));
  1067. dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
  1068. dst_vq->io_modes = VB2_MMAP | VB2_USERPTR;
  1069. dst_vq->drv_priv = ctx;
  1070. dst_vq->ops = &fimc_qops;
  1071. dst_vq->mem_ops = &vb2_dma_contig_memops;
  1072. dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
  1073. return vb2_queue_init(dst_vq);
  1074. }
  1075. static int fimc_m2m_open(struct file *file)
  1076. {
  1077. struct fimc_dev *fimc = video_drvdata(file);
  1078. struct fimc_ctx *ctx = NULL;
  1079. int err = 0;
  1080. if (mutex_lock_interruptible(&fimc->lock))
  1081. return -ERESTARTSYS;
  1082. dbg("pid: %d, state: 0x%lx, refcnt: %d",
  1083. task_pid_nr(current), fimc->state, fimc->vid_cap.refcnt);
  1084. /*
  1085. * Return if the corresponding video capture node
  1086. * is already opened.
  1087. */
  1088. if (fimc->vid_cap.refcnt > 0) {
  1089. err = -EBUSY;
  1090. goto err_unlock;
  1091. }
  1092. fimc->m2m.refcnt++;
  1093. set_bit(ST_OUTDMA_RUN, &fimc->state);
  1094. ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
  1095. if (!ctx) {
  1096. err = -ENOMEM;
  1097. goto err_unlock;
  1098. }
  1099. file->private_data = ctx;
  1100. ctx->fimc_dev = fimc;
  1101. /* Default color format */
  1102. ctx->s_frame.fmt = &fimc_formats[0];
  1103. ctx->d_frame.fmt = &fimc_formats[0];
  1104. /* Setup the device context for mem2mem mode. */
  1105. ctx->state = FIMC_CTX_M2M;
  1106. ctx->flags = 0;
  1107. ctx->in_path = FIMC_DMA;
  1108. ctx->out_path = FIMC_DMA;
  1109. spin_lock_init(&ctx->slock);
  1110. ctx->m2m_ctx = v4l2_m2m_ctx_init(fimc->m2m.m2m_dev, ctx, queue_init);
  1111. if (IS_ERR(ctx->m2m_ctx)) {
  1112. err = PTR_ERR(ctx->m2m_ctx);
  1113. kfree(ctx);
  1114. }
  1115. err_unlock:
  1116. mutex_unlock(&fimc->lock);
  1117. return err;
  1118. }
  1119. static int fimc_m2m_release(struct file *file)
  1120. {
  1121. struct fimc_ctx *ctx = file->private_data;
  1122. struct fimc_dev *fimc = ctx->fimc_dev;
  1123. mutex_lock(&fimc->lock);
  1124. dbg("pid: %d, state: 0x%lx, refcnt= %d",
  1125. task_pid_nr(current), fimc->state, fimc->m2m.refcnt);
  1126. v4l2_m2m_ctx_release(ctx->m2m_ctx);
  1127. kfree(ctx);
  1128. if (--fimc->m2m.refcnt <= 0)
  1129. clear_bit(ST_OUTDMA_RUN, &fimc->state);
  1130. mutex_unlock(&fimc->lock);
  1131. return 0;
  1132. }
  1133. static unsigned int fimc_m2m_poll(struct file *file,
  1134. struct poll_table_struct *wait)
  1135. {
  1136. struct fimc_ctx *ctx = file->private_data;
  1137. return v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
  1138. }
  1139. static int fimc_m2m_mmap(struct file *file, struct vm_area_struct *vma)
  1140. {
  1141. struct fimc_ctx *ctx = file->private_data;
  1142. return v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);
  1143. }
  1144. static const struct v4l2_file_operations fimc_m2m_fops = {
  1145. .owner = THIS_MODULE,
  1146. .open = fimc_m2m_open,
  1147. .release = fimc_m2m_release,
  1148. .poll = fimc_m2m_poll,
  1149. .unlocked_ioctl = video_ioctl2,
  1150. .mmap = fimc_m2m_mmap,
  1151. };
  1152. static struct v4l2_m2m_ops m2m_ops = {
  1153. .device_run = fimc_dma_run,
  1154. .job_abort = fimc_job_abort,
  1155. };
  1156. static int fimc_register_m2m_device(struct fimc_dev *fimc)
  1157. {
  1158. struct video_device *vfd;
  1159. struct platform_device *pdev;
  1160. struct v4l2_device *v4l2_dev;
  1161. int ret = 0;
  1162. if (!fimc)
  1163. return -ENODEV;
  1164. pdev = fimc->pdev;
  1165. v4l2_dev = &fimc->m2m.v4l2_dev;
  1166. /* set name if it is empty */
  1167. if (!v4l2_dev->name[0])
  1168. snprintf(v4l2_dev->name, sizeof(v4l2_dev->name),
  1169. "%s.m2m", dev_name(&pdev->dev));
  1170. ret = v4l2_device_register(&pdev->dev, v4l2_dev);
  1171. if (ret)
  1172. goto err_m2m_r1;
  1173. vfd = video_device_alloc();
  1174. if (!vfd) {
  1175. v4l2_err(v4l2_dev, "Failed to allocate video device\n");
  1176. goto err_m2m_r1;
  1177. }
  1178. vfd->fops = &fimc_m2m_fops;
  1179. vfd->ioctl_ops = &fimc_m2m_ioctl_ops;
  1180. vfd->minor = -1;
  1181. vfd->release = video_device_release;
  1182. snprintf(vfd->name, sizeof(vfd->name), "%s:m2m", dev_name(&pdev->dev));
  1183. video_set_drvdata(vfd, fimc);
  1184. platform_set_drvdata(pdev, fimc);
  1185. fimc->m2m.vfd = vfd;
  1186. fimc->m2m.m2m_dev = v4l2_m2m_init(&m2m_ops);
  1187. if (IS_ERR(fimc->m2m.m2m_dev)) {
  1188. v4l2_err(v4l2_dev, "failed to initialize v4l2-m2m device\n");
  1189. ret = PTR_ERR(fimc->m2m.m2m_dev);
  1190. goto err_m2m_r2;
  1191. }
  1192. ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
  1193. if (ret) {
  1194. v4l2_err(v4l2_dev,
  1195. "%s(): failed to register video device\n", __func__);
  1196. goto err_m2m_r3;
  1197. }
  1198. v4l2_info(v4l2_dev,
  1199. "FIMC m2m driver registered as /dev/video%d\n", vfd->num);
  1200. return 0;
  1201. err_m2m_r3:
  1202. v4l2_m2m_release(fimc->m2m.m2m_dev);
  1203. err_m2m_r2:
  1204. video_device_release(fimc->m2m.vfd);
  1205. err_m2m_r1:
  1206. v4l2_device_unregister(v4l2_dev);
  1207. return ret;
  1208. }
  1209. static void fimc_unregister_m2m_device(struct fimc_dev *fimc)
  1210. {
  1211. if (fimc) {
  1212. v4l2_m2m_release(fimc->m2m.m2m_dev);
  1213. video_unregister_device(fimc->m2m.vfd);
  1214. v4l2_device_unregister(&fimc->m2m.v4l2_dev);
  1215. }
  1216. }
  1217. static void fimc_clk_release(struct fimc_dev *fimc)
  1218. {
  1219. int i;
  1220. for (i = 0; i < NUM_FIMC_CLOCKS; i++) {
  1221. if (fimc->clock[i]) {
  1222. clk_disable(fimc->clock[i]);
  1223. clk_put(fimc->clock[i]);
  1224. }
  1225. }
  1226. }
  1227. static int fimc_clk_get(struct fimc_dev *fimc)
  1228. {
  1229. int i;
  1230. for (i = 0; i < NUM_FIMC_CLOCKS; i++) {
  1231. fimc->clock[i] = clk_get(&fimc->pdev->dev, fimc_clock_name[i]);
  1232. if (IS_ERR(fimc->clock[i])) {
  1233. dev_err(&fimc->pdev->dev,
  1234. "failed to get fimc clock: %s\n",
  1235. fimc_clock_name[i]);
  1236. return -ENXIO;
  1237. }
  1238. clk_enable(fimc->clock[i]);
  1239. }
  1240. return 0;
  1241. }
  1242. static int fimc_probe(struct platform_device *pdev)
  1243. {
  1244. struct fimc_dev *fimc;
  1245. struct resource *res;
  1246. struct samsung_fimc_driverdata *drv_data;
  1247. int ret = 0;
  1248. dev_dbg(&pdev->dev, "%s():\n", __func__);
  1249. drv_data = (struct samsung_fimc_driverdata *)
  1250. platform_get_device_id(pdev)->driver_data;
  1251. if (pdev->id >= drv_data->num_entities) {
  1252. dev_err(&pdev->dev, "Invalid platform device id: %d\n",
  1253. pdev->id);
  1254. return -EINVAL;
  1255. }
  1256. fimc = kzalloc(sizeof(struct fimc_dev), GFP_KERNEL);
  1257. if (!fimc)
  1258. return -ENOMEM;
  1259. fimc->id = pdev->id;
  1260. fimc->variant = drv_data->variant[fimc->id];
  1261. fimc->pdev = pdev;
  1262. fimc->pdata = pdev->dev.platform_data;
  1263. fimc->state = ST_IDLE;
  1264. init_waitqueue_head(&fimc->irq_queue);
  1265. spin_lock_init(&fimc->slock);
  1266. mutex_init(&fimc->lock);
  1267. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1268. if (!res) {
  1269. dev_err(&pdev->dev, "failed to find the registers\n");
  1270. ret = -ENOENT;
  1271. goto err_info;
  1272. }
  1273. fimc->regs_res = request_mem_region(res->start, resource_size(res),
  1274. dev_name(&pdev->dev));
  1275. if (!fimc->regs_res) {
  1276. dev_err(&pdev->dev, "failed to obtain register region\n");
  1277. ret = -ENOENT;
  1278. goto err_info;
  1279. }
  1280. fimc->regs = ioremap(res->start, resource_size(res));
  1281. if (!fimc->regs) {
  1282. dev_err(&pdev->dev, "failed to map registers\n");
  1283. ret = -ENXIO;
  1284. goto err_req_region;
  1285. }
  1286. ret = fimc_clk_get(fimc);
  1287. if (ret)
  1288. goto err_regs_unmap;
  1289. clk_set_rate(fimc->clock[0], drv_data->lclk_frequency);
  1290. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1291. if (!res) {
  1292. dev_err(&pdev->dev, "failed to get IRQ resource\n");
  1293. ret = -ENXIO;
  1294. goto err_clk;
  1295. }
  1296. fimc->irq = res->start;
  1297. fimc_hw_reset(fimc);
  1298. ret = request_irq(fimc->irq, fimc_isr, 0, pdev->name, fimc);
  1299. if (ret) {
  1300. dev_err(&pdev->dev, "failed to install irq (%d)\n", ret);
  1301. goto err_clk;
  1302. }
  1303. /* Initialize contiguous memory allocator */
  1304. fimc->alloc_ctx = vb2_dma_contig_init_ctx(&fimc->pdev->dev);
  1305. if (IS_ERR(fimc->alloc_ctx)) {
  1306. ret = PTR_ERR(fimc->alloc_ctx);
  1307. goto err_irq;
  1308. }
  1309. ret = fimc_register_m2m_device(fimc);
  1310. if (ret)
  1311. goto err_irq;
  1312. /* At least one camera sensor is required to register capture node */
  1313. if (fimc->pdata) {
  1314. int i;
  1315. for (i = 0; i < FIMC_MAX_CAMIF_CLIENTS; ++i)
  1316. if (fimc->pdata->isp_info[i])
  1317. break;
  1318. if (i < FIMC_MAX_CAMIF_CLIENTS) {
  1319. ret = fimc_register_capture_device(fimc);
  1320. if (ret)
  1321. goto err_m2m;
  1322. }
  1323. }
  1324. /*
  1325. * Exclude the additional output DMA address registers by masking
  1326. * them out on HW revisions that provide extended capabilites.
  1327. */
  1328. if (fimc->variant->out_buf_count > 4)
  1329. fimc_hw_set_dma_seq(fimc, 0xF);
  1330. dev_dbg(&pdev->dev, "%s(): fimc-%d registered successfully\n",
  1331. __func__, fimc->id);
  1332. return 0;
  1333. err_m2m:
  1334. fimc_unregister_m2m_device(fimc);
  1335. err_irq:
  1336. free_irq(fimc->irq, fimc);
  1337. err_clk:
  1338. fimc_clk_release(fimc);
  1339. err_regs_unmap:
  1340. iounmap(fimc->regs);
  1341. err_req_region:
  1342. release_resource(fimc->regs_res);
  1343. kfree(fimc->regs_res);
  1344. err_info:
  1345. kfree(fimc);
  1346. return ret;
  1347. }
  1348. static int __devexit fimc_remove(struct platform_device *pdev)
  1349. {
  1350. struct fimc_dev *fimc =
  1351. (struct fimc_dev *)platform_get_drvdata(pdev);
  1352. free_irq(fimc->irq, fimc);
  1353. fimc_hw_reset(fimc);
  1354. fimc_unregister_m2m_device(fimc);
  1355. fimc_unregister_capture_device(fimc);
  1356. fimc_clk_release(fimc);
  1357. vb2_dma_contig_cleanup_ctx(fimc->alloc_ctx);
  1358. iounmap(fimc->regs);
  1359. release_resource(fimc->regs_res);
  1360. kfree(fimc->regs_res);
  1361. kfree(fimc);
  1362. dev_info(&pdev->dev, "%s driver unloaded\n", pdev->name);
  1363. return 0;
  1364. }
  1365. /* Image pixel limits, similar across several FIMC HW revisions. */
  1366. static struct fimc_pix_limit s5p_pix_limit[3] = {
  1367. [0] = {
  1368. .scaler_en_w = 3264,
  1369. .scaler_dis_w = 8192,
  1370. .in_rot_en_h = 1920,
  1371. .in_rot_dis_w = 8192,
  1372. .out_rot_en_w = 1920,
  1373. .out_rot_dis_w = 4224,
  1374. },
  1375. [1] = {
  1376. .scaler_en_w = 4224,
  1377. .scaler_dis_w = 8192,
  1378. .in_rot_en_h = 1920,
  1379. .in_rot_dis_w = 8192,
  1380. .out_rot_en_w = 1920,
  1381. .out_rot_dis_w = 4224,
  1382. },
  1383. [2] = {
  1384. .scaler_en_w = 1920,
  1385. .scaler_dis_w = 8192,
  1386. .in_rot_en_h = 1280,
  1387. .in_rot_dis_w = 8192,
  1388. .out_rot_en_w = 1280,
  1389. .out_rot_dis_w = 1920,
  1390. },
  1391. };
  1392. static struct samsung_fimc_variant fimc0_variant_s5p = {
  1393. .has_inp_rot = 1,
  1394. .has_out_rot = 1,
  1395. .min_inp_pixsize = 16,
  1396. .min_out_pixsize = 16,
  1397. .hor_offs_align = 8,
  1398. .out_buf_count = 4,
  1399. .pix_limit = &s5p_pix_limit[0],
  1400. };
  1401. static struct samsung_fimc_variant fimc2_variant_s5p = {
  1402. .min_inp_pixsize = 16,
  1403. .min_out_pixsize = 16,
  1404. .hor_offs_align = 8,
  1405. .out_buf_count = 4,
  1406. .pix_limit = &s5p_pix_limit[1],
  1407. };
  1408. static struct samsung_fimc_variant fimc0_variant_s5pv210 = {
  1409. .pix_hoff = 1,
  1410. .has_inp_rot = 1,
  1411. .has_out_rot = 1,
  1412. .min_inp_pixsize = 16,
  1413. .min_out_pixsize = 16,
  1414. .hor_offs_align = 8,
  1415. .out_buf_count = 4,
  1416. .pix_limit = &s5p_pix_limit[1],
  1417. };
  1418. static struct samsung_fimc_variant fimc1_variant_s5pv210 = {
  1419. .pix_hoff = 1,
  1420. .has_inp_rot = 1,
  1421. .has_out_rot = 1,
  1422. .min_inp_pixsize = 16,
  1423. .min_out_pixsize = 16,
  1424. .hor_offs_align = 1,
  1425. .out_buf_count = 4,
  1426. .pix_limit = &s5p_pix_limit[2],
  1427. };
  1428. static struct samsung_fimc_variant fimc2_variant_s5pv210 = {
  1429. .pix_hoff = 1,
  1430. .min_inp_pixsize = 16,
  1431. .min_out_pixsize = 16,
  1432. .hor_offs_align = 8,
  1433. .out_buf_count = 4,
  1434. .pix_limit = &s5p_pix_limit[2],
  1435. };
  1436. static struct samsung_fimc_variant fimc0_variant_s5pv310 = {
  1437. .pix_hoff = 1,
  1438. .has_inp_rot = 1,
  1439. .has_out_rot = 1,
  1440. .has_cistatus2 = 1,
  1441. .min_inp_pixsize = 16,
  1442. .min_out_pixsize = 16,
  1443. .hor_offs_align = 1,
  1444. .out_buf_count = 32,
  1445. .pix_limit = &s5p_pix_limit[1],
  1446. };
  1447. static struct samsung_fimc_variant fimc2_variant_s5pv310 = {
  1448. .pix_hoff = 1,
  1449. .has_cistatus2 = 1,
  1450. .min_inp_pixsize = 16,
  1451. .min_out_pixsize = 16,
  1452. .hor_offs_align = 1,
  1453. .out_buf_count = 32,
  1454. .pix_limit = &s5p_pix_limit[2],
  1455. };
  1456. /* S5PC100 */
  1457. static struct samsung_fimc_driverdata fimc_drvdata_s5p = {
  1458. .variant = {
  1459. [0] = &fimc0_variant_s5p,
  1460. [1] = &fimc0_variant_s5p,
  1461. [2] = &fimc2_variant_s5p,
  1462. },
  1463. .num_entities = 3,
  1464. .lclk_frequency = 133000000UL,
  1465. };
  1466. /* S5PV210, S5PC110 */
  1467. static struct samsung_fimc_driverdata fimc_drvdata_s5pv210 = {
  1468. .variant = {
  1469. [0] = &fimc0_variant_s5pv210,
  1470. [1] = &fimc1_variant_s5pv210,
  1471. [2] = &fimc2_variant_s5pv210,
  1472. },
  1473. .num_entities = 3,
  1474. .lclk_frequency = 166000000UL,
  1475. };
  1476. /* S5PV310, S5PC210 */
  1477. static struct samsung_fimc_driverdata fimc_drvdata_s5pv310 = {
  1478. .variant = {
  1479. [0] = &fimc0_variant_s5pv310,
  1480. [1] = &fimc0_variant_s5pv310,
  1481. [2] = &fimc0_variant_s5pv310,
  1482. [3] = &fimc2_variant_s5pv310,
  1483. },
  1484. .num_entities = 4,
  1485. .lclk_frequency = 166000000UL,
  1486. };
  1487. static struct platform_device_id fimc_driver_ids[] = {
  1488. {
  1489. .name = "s5p-fimc",
  1490. .driver_data = (unsigned long)&fimc_drvdata_s5p,
  1491. }, {
  1492. .name = "s5pv210-fimc",
  1493. .driver_data = (unsigned long)&fimc_drvdata_s5pv210,
  1494. }, {
  1495. .name = "s5pv310-fimc",
  1496. .driver_data = (unsigned long)&fimc_drvdata_s5pv310,
  1497. },
  1498. {},
  1499. };
  1500. MODULE_DEVICE_TABLE(platform, fimc_driver_ids);
  1501. static struct platform_driver fimc_driver = {
  1502. .probe = fimc_probe,
  1503. .remove = __devexit_p(fimc_remove),
  1504. .id_table = fimc_driver_ids,
  1505. .driver = {
  1506. .name = MODULE_NAME,
  1507. .owner = THIS_MODULE,
  1508. }
  1509. };
  1510. static int __init fimc_init(void)
  1511. {
  1512. int ret = platform_driver_register(&fimc_driver);
  1513. if (ret)
  1514. err("platform_driver_register failed: %d\n", ret);
  1515. return ret;
  1516. }
  1517. static void __exit fimc_exit(void)
  1518. {
  1519. platform_driver_unregister(&fimc_driver);
  1520. }
  1521. module_init(fimc_init);
  1522. module_exit(fimc_exit);
  1523. MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
  1524. MODULE_DESCRIPTION("S5P FIMC camera host interface/video postprocessor driver");
  1525. MODULE_LICENSE("GPL");