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