fimc-core.c 43 KB

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