fimc-core.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844
  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, 32 bpp",
  50. .fourcc = V4L2_PIX_FMT_RGB32,
  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. int ret = -EINVAL;
  833. c = get_ctrl(qc->id);
  834. if (c) {
  835. *qc = *c;
  836. return 0;
  837. }
  838. if (ctx->state & FIMC_CTX_CAP) {
  839. if (mutex_lock_interruptible(&ctx->fimc_dev->lock))
  840. return -ERESTARTSYS;
  841. ret = v4l2_subdev_call(ctx->fimc_dev->vid_cap.sd,
  842. core, queryctrl, qc);
  843. mutex_unlock(&ctx->fimc_dev->lock);
  844. }
  845. return ret;
  846. }
  847. int fimc_vidioc_g_ctrl(struct file *file, void *priv,
  848. struct v4l2_control *ctrl)
  849. {
  850. struct fimc_ctx *ctx = priv;
  851. struct fimc_dev *fimc = ctx->fimc_dev;
  852. int ret = 0;
  853. if (mutex_lock_interruptible(&fimc->lock))
  854. return -ERESTARTSYS;
  855. switch (ctrl->id) {
  856. case V4L2_CID_HFLIP:
  857. ctrl->value = (FLIP_X_AXIS & ctx->flip) ? 1 : 0;
  858. break;
  859. case V4L2_CID_VFLIP:
  860. ctrl->value = (FLIP_Y_AXIS & ctx->flip) ? 1 : 0;
  861. break;
  862. case V4L2_CID_ROTATE:
  863. ctrl->value = ctx->rotation;
  864. break;
  865. default:
  866. if (ctx->state & FIMC_CTX_CAP) {
  867. ret = v4l2_subdev_call(fimc->vid_cap.sd, core,
  868. g_ctrl, ctrl);
  869. } else {
  870. v4l2_err(&fimc->m2m.v4l2_dev,
  871. "Invalid control\n");
  872. ret = -EINVAL;
  873. }
  874. }
  875. dbg("ctrl->value= %d", ctrl->value);
  876. mutex_unlock(&fimc->lock);
  877. return ret;
  878. }
  879. int check_ctrl_val(struct fimc_ctx *ctx, struct v4l2_control *ctrl)
  880. {
  881. struct v4l2_queryctrl *c;
  882. c = get_ctrl(ctrl->id);
  883. if (!c)
  884. return -EINVAL;
  885. if (ctrl->value < c->minimum || ctrl->value > c->maximum
  886. || (c->step != 0 && ctrl->value % c->step != 0)) {
  887. v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
  888. "Invalid control value\n");
  889. return -ERANGE;
  890. }
  891. return 0;
  892. }
  893. int fimc_s_ctrl(struct fimc_ctx *ctx, struct v4l2_control *ctrl)
  894. {
  895. struct samsung_fimc_variant *variant = ctx->fimc_dev->variant;
  896. struct fimc_dev *fimc = ctx->fimc_dev;
  897. unsigned long flags;
  898. if (ctx->rotation != 0 &&
  899. (ctrl->id == V4L2_CID_HFLIP || ctrl->id == V4L2_CID_VFLIP)) {
  900. v4l2_err(&fimc->m2m.v4l2_dev,
  901. "Simultaneous flip and rotation is not supported\n");
  902. return -EINVAL;
  903. }
  904. spin_lock_irqsave(&ctx->slock, flags);
  905. switch (ctrl->id) {
  906. case V4L2_CID_HFLIP:
  907. if (ctrl->value)
  908. ctx->flip |= FLIP_X_AXIS;
  909. else
  910. ctx->flip &= ~FLIP_X_AXIS;
  911. break;
  912. case V4L2_CID_VFLIP:
  913. if (ctrl->value)
  914. ctx->flip |= FLIP_Y_AXIS;
  915. else
  916. ctx->flip &= ~FLIP_Y_AXIS;
  917. break;
  918. case V4L2_CID_ROTATE:
  919. /* Check for the output rotator availability */
  920. if ((ctrl->value == 90 || ctrl->value == 270) &&
  921. (ctx->in_path == FIMC_DMA && !variant->has_out_rot)) {
  922. spin_unlock_irqrestore(&ctx->slock, flags);
  923. return -EINVAL;
  924. } else {
  925. ctx->rotation = ctrl->value;
  926. }
  927. break;
  928. default:
  929. spin_unlock_irqrestore(&ctx->slock, flags);
  930. v4l2_err(&fimc->m2m.v4l2_dev, "Invalid control\n");
  931. return -EINVAL;
  932. }
  933. ctx->state |= FIMC_PARAMS;
  934. spin_unlock_irqrestore(&ctx->slock, flags);
  935. return 0;
  936. }
  937. static int fimc_m2m_s_ctrl(struct file *file, void *priv,
  938. struct v4l2_control *ctrl)
  939. {
  940. struct fimc_ctx *ctx = priv;
  941. int ret = 0;
  942. ret = check_ctrl_val(ctx, ctrl);
  943. if (ret)
  944. return ret;
  945. ret = fimc_s_ctrl(ctx, ctrl);
  946. return 0;
  947. }
  948. static int fimc_m2m_cropcap(struct file *file, void *fh,
  949. struct v4l2_cropcap *cr)
  950. {
  951. struct fimc_frame *frame;
  952. struct fimc_ctx *ctx = fh;
  953. struct fimc_dev *fimc = ctx->fimc_dev;
  954. frame = ctx_get_frame(ctx, cr->type);
  955. if (IS_ERR(frame))
  956. return PTR_ERR(frame);
  957. if (mutex_lock_interruptible(&fimc->lock))
  958. return -ERESTARTSYS;
  959. cr->bounds.left = 0;
  960. cr->bounds.top = 0;
  961. cr->bounds.width = frame->f_width;
  962. cr->bounds.height = frame->f_height;
  963. cr->defrect = cr->bounds;
  964. mutex_unlock(&fimc->lock);
  965. return 0;
  966. }
  967. static int fimc_m2m_g_crop(struct file *file, void *fh, struct v4l2_crop *cr)
  968. {
  969. struct fimc_frame *frame;
  970. struct fimc_ctx *ctx = file->private_data;
  971. struct fimc_dev *fimc = ctx->fimc_dev;
  972. frame = ctx_get_frame(ctx, cr->type);
  973. if (IS_ERR(frame))
  974. return PTR_ERR(frame);
  975. if (mutex_lock_interruptible(&fimc->lock))
  976. return -ERESTARTSYS;
  977. cr->c.left = frame->offs_h;
  978. cr->c.top = frame->offs_v;
  979. cr->c.width = frame->width;
  980. cr->c.height = frame->height;
  981. mutex_unlock(&fimc->lock);
  982. return 0;
  983. }
  984. int fimc_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr)
  985. {
  986. struct fimc_dev *fimc = ctx->fimc_dev;
  987. struct fimc_frame *f;
  988. u32 min_size, halign;
  989. if (cr->c.top < 0 || cr->c.left < 0) {
  990. v4l2_err(&fimc->m2m.v4l2_dev,
  991. "doesn't support negative values for top & left\n");
  992. return -EINVAL;
  993. }
  994. if (cr->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  995. f = (ctx->state & FIMC_CTX_CAP) ? &ctx->s_frame : &ctx->d_frame;
  996. else if (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
  997. ctx->state & FIMC_CTX_M2M)
  998. f = &ctx->s_frame;
  999. else
  1000. return -EINVAL;
  1001. min_size = (f == &ctx->s_frame) ?
  1002. fimc->variant->min_inp_pixsize : fimc->variant->min_out_pixsize;
  1003. if (ctx->state & FIMC_CTX_M2M) {
  1004. if (fimc->id == 1 && fimc->variant->pix_hoff)
  1005. halign = fimc_fmt_is_rgb(f->fmt->color) ? 0 : 1;
  1006. else
  1007. halign = ffs(min_size) - 1;
  1008. /* there are more strict aligment requirements at camera interface */
  1009. } else {
  1010. min_size = 16;
  1011. halign = 4;
  1012. }
  1013. v4l_bound_align_image(&cr->c.width, min_size, f->o_width,
  1014. ffs(min_size) - 1,
  1015. &cr->c.height, min_size, f->o_height,
  1016. halign, 64/(ALIGN(f->fmt->depth, 8)));
  1017. /* adjust left/top if cropping rectangle is out of bounds */
  1018. if (cr->c.left + cr->c.width > f->o_width)
  1019. cr->c.left = f->o_width - cr->c.width;
  1020. if (cr->c.top + cr->c.height > f->o_height)
  1021. cr->c.top = f->o_height - cr->c.height;
  1022. cr->c.left = round_down(cr->c.left, min_size);
  1023. cr->c.top = round_down(cr->c.top,
  1024. ctx->state & FIMC_CTX_M2M ? 8 : 16);
  1025. dbg("l:%d, t:%d, w:%d, h:%d, f_w: %d, f_h: %d",
  1026. cr->c.left, cr->c.top, cr->c.width, cr->c.height,
  1027. f->f_width, f->f_height);
  1028. return 0;
  1029. }
  1030. static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
  1031. {
  1032. struct fimc_ctx *ctx = file->private_data;
  1033. struct fimc_dev *fimc = ctx->fimc_dev;
  1034. unsigned long flags;
  1035. struct fimc_frame *f;
  1036. int ret;
  1037. ret = fimc_try_crop(ctx, cr);
  1038. if (ret)
  1039. return ret;
  1040. f = (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) ?
  1041. &ctx->s_frame : &ctx->d_frame;
  1042. if (mutex_lock_interruptible(&fimc->lock))
  1043. return -ERESTARTSYS;
  1044. spin_lock_irqsave(&ctx->slock, flags);
  1045. if (~ctx->state & (FIMC_SRC_FMT | FIMC_DST_FMT)) {
  1046. /* Check to see if scaling ratio is within supported range */
  1047. if (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
  1048. ret = fimc_check_scaler_ratio(&cr->c, &ctx->d_frame);
  1049. else
  1050. ret = fimc_check_scaler_ratio(&cr->c, &ctx->s_frame);
  1051. if (ret) {
  1052. v4l2_err(&fimc->m2m.v4l2_dev, "Out of scaler range");
  1053. ret = -EINVAL;
  1054. goto scr_unlock;
  1055. }
  1056. }
  1057. ctx->state |= FIMC_PARAMS;
  1058. f->offs_h = cr->c.left;
  1059. f->offs_v = cr->c.top;
  1060. f->width = cr->c.width;
  1061. f->height = cr->c.height;
  1062. scr_unlock:
  1063. spin_unlock_irqrestore(&ctx->slock, flags);
  1064. mutex_unlock(&fimc->lock);
  1065. return 0;
  1066. }
  1067. static const struct v4l2_ioctl_ops fimc_m2m_ioctl_ops = {
  1068. .vidioc_querycap = fimc_m2m_querycap,
  1069. .vidioc_enum_fmt_vid_cap = fimc_vidioc_enum_fmt,
  1070. .vidioc_enum_fmt_vid_out = fimc_vidioc_enum_fmt,
  1071. .vidioc_g_fmt_vid_cap = fimc_vidioc_g_fmt,
  1072. .vidioc_g_fmt_vid_out = fimc_vidioc_g_fmt,
  1073. .vidioc_try_fmt_vid_cap = fimc_vidioc_try_fmt,
  1074. .vidioc_try_fmt_vid_out = fimc_vidioc_try_fmt,
  1075. .vidioc_s_fmt_vid_cap = fimc_m2m_s_fmt,
  1076. .vidioc_s_fmt_vid_out = fimc_m2m_s_fmt,
  1077. .vidioc_reqbufs = fimc_m2m_reqbufs,
  1078. .vidioc_querybuf = fimc_m2m_querybuf,
  1079. .vidioc_qbuf = fimc_m2m_qbuf,
  1080. .vidioc_dqbuf = fimc_m2m_dqbuf,
  1081. .vidioc_streamon = fimc_m2m_streamon,
  1082. .vidioc_streamoff = fimc_m2m_streamoff,
  1083. .vidioc_queryctrl = fimc_vidioc_queryctrl,
  1084. .vidioc_g_ctrl = fimc_vidioc_g_ctrl,
  1085. .vidioc_s_ctrl = fimc_m2m_s_ctrl,
  1086. .vidioc_g_crop = fimc_m2m_g_crop,
  1087. .vidioc_s_crop = fimc_m2m_s_crop,
  1088. .vidioc_cropcap = fimc_m2m_cropcap
  1089. };
  1090. static void queue_init(void *priv, struct videobuf_queue *vq,
  1091. enum v4l2_buf_type type)
  1092. {
  1093. struct fimc_ctx *ctx = priv;
  1094. struct fimc_dev *fimc = ctx->fimc_dev;
  1095. videobuf_queue_dma_contig_init(vq, &fimc_qops,
  1096. &fimc->pdev->dev,
  1097. &fimc->irqlock, type, V4L2_FIELD_NONE,
  1098. sizeof(struct fimc_vid_buffer), priv, NULL);
  1099. }
  1100. static int fimc_m2m_open(struct file *file)
  1101. {
  1102. struct fimc_dev *fimc = video_drvdata(file);
  1103. struct fimc_ctx *ctx = NULL;
  1104. int err = 0;
  1105. if (mutex_lock_interruptible(&fimc->lock))
  1106. return -ERESTARTSYS;
  1107. dbg("pid: %d, state: 0x%lx, refcnt: %d",
  1108. task_pid_nr(current), fimc->state, fimc->vid_cap.refcnt);
  1109. /*
  1110. * Return if the corresponding video capture node
  1111. * is already opened.
  1112. */
  1113. if (fimc->vid_cap.refcnt > 0) {
  1114. err = -EBUSY;
  1115. goto err_unlock;
  1116. }
  1117. fimc->m2m.refcnt++;
  1118. set_bit(ST_OUTDMA_RUN, &fimc->state);
  1119. ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
  1120. if (!ctx) {
  1121. err = -ENOMEM;
  1122. goto err_unlock;
  1123. }
  1124. file->private_data = ctx;
  1125. ctx->fimc_dev = fimc;
  1126. /* Default color format */
  1127. ctx->s_frame.fmt = &fimc_formats[0];
  1128. ctx->d_frame.fmt = &fimc_formats[0];
  1129. /* Setup the device context for mem2mem mode. */
  1130. ctx->state = FIMC_CTX_M2M;
  1131. ctx->flags = 0;
  1132. ctx->in_path = FIMC_DMA;
  1133. ctx->out_path = FIMC_DMA;
  1134. spin_lock_init(&ctx->slock);
  1135. ctx->m2m_ctx = v4l2_m2m_ctx_init(ctx, fimc->m2m.m2m_dev, queue_init);
  1136. if (IS_ERR(ctx->m2m_ctx)) {
  1137. err = PTR_ERR(ctx->m2m_ctx);
  1138. kfree(ctx);
  1139. }
  1140. err_unlock:
  1141. mutex_unlock(&fimc->lock);
  1142. return err;
  1143. }
  1144. static int fimc_m2m_release(struct file *file)
  1145. {
  1146. struct fimc_ctx *ctx = file->private_data;
  1147. struct fimc_dev *fimc = ctx->fimc_dev;
  1148. mutex_lock(&fimc->lock);
  1149. dbg("pid: %d, state: 0x%lx, refcnt= %d",
  1150. task_pid_nr(current), fimc->state, fimc->m2m.refcnt);
  1151. v4l2_m2m_ctx_release(ctx->m2m_ctx);
  1152. kfree(ctx);
  1153. if (--fimc->m2m.refcnt <= 0)
  1154. clear_bit(ST_OUTDMA_RUN, &fimc->state);
  1155. mutex_unlock(&fimc->lock);
  1156. return 0;
  1157. }
  1158. static unsigned int fimc_m2m_poll(struct file *file,
  1159. struct poll_table_struct *wait)
  1160. {
  1161. struct fimc_ctx *ctx = file->private_data;
  1162. return v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
  1163. }
  1164. static int fimc_m2m_mmap(struct file *file, struct vm_area_struct *vma)
  1165. {
  1166. struct fimc_ctx *ctx = file->private_data;
  1167. return v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);
  1168. }
  1169. static const struct v4l2_file_operations fimc_m2m_fops = {
  1170. .owner = THIS_MODULE,
  1171. .open = fimc_m2m_open,
  1172. .release = fimc_m2m_release,
  1173. .poll = fimc_m2m_poll,
  1174. .unlocked_ioctl = video_ioctl2,
  1175. .mmap = fimc_m2m_mmap,
  1176. };
  1177. static struct v4l2_m2m_ops m2m_ops = {
  1178. .device_run = fimc_dma_run,
  1179. .job_abort = fimc_job_abort,
  1180. };
  1181. static int fimc_register_m2m_device(struct fimc_dev *fimc)
  1182. {
  1183. struct video_device *vfd;
  1184. struct platform_device *pdev;
  1185. struct v4l2_device *v4l2_dev;
  1186. int ret = 0;
  1187. if (!fimc)
  1188. return -ENODEV;
  1189. pdev = fimc->pdev;
  1190. v4l2_dev = &fimc->m2m.v4l2_dev;
  1191. /* set name if it is empty */
  1192. if (!v4l2_dev->name[0])
  1193. snprintf(v4l2_dev->name, sizeof(v4l2_dev->name),
  1194. "%s.m2m", dev_name(&pdev->dev));
  1195. ret = v4l2_device_register(&pdev->dev, v4l2_dev);
  1196. if (ret)
  1197. goto err_m2m_r1;
  1198. vfd = video_device_alloc();
  1199. if (!vfd) {
  1200. v4l2_err(v4l2_dev, "Failed to allocate video device\n");
  1201. goto err_m2m_r1;
  1202. }
  1203. vfd->fops = &fimc_m2m_fops;
  1204. vfd->ioctl_ops = &fimc_m2m_ioctl_ops;
  1205. vfd->minor = -1;
  1206. vfd->release = video_device_release;
  1207. snprintf(vfd->name, sizeof(vfd->name), "%s:m2m", dev_name(&pdev->dev));
  1208. video_set_drvdata(vfd, fimc);
  1209. platform_set_drvdata(pdev, fimc);
  1210. fimc->m2m.vfd = vfd;
  1211. fimc->m2m.m2m_dev = v4l2_m2m_init(&m2m_ops);
  1212. if (IS_ERR(fimc->m2m.m2m_dev)) {
  1213. v4l2_err(v4l2_dev, "failed to initialize v4l2-m2m device\n");
  1214. ret = PTR_ERR(fimc->m2m.m2m_dev);
  1215. goto err_m2m_r2;
  1216. }
  1217. ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
  1218. if (ret) {
  1219. v4l2_err(v4l2_dev,
  1220. "%s(): failed to register video device\n", __func__);
  1221. goto err_m2m_r3;
  1222. }
  1223. v4l2_info(v4l2_dev,
  1224. "FIMC m2m driver registered as /dev/video%d\n", vfd->num);
  1225. return 0;
  1226. err_m2m_r3:
  1227. v4l2_m2m_release(fimc->m2m.m2m_dev);
  1228. err_m2m_r2:
  1229. video_device_release(fimc->m2m.vfd);
  1230. err_m2m_r1:
  1231. v4l2_device_unregister(v4l2_dev);
  1232. return ret;
  1233. }
  1234. static void fimc_unregister_m2m_device(struct fimc_dev *fimc)
  1235. {
  1236. if (fimc) {
  1237. v4l2_m2m_release(fimc->m2m.m2m_dev);
  1238. video_unregister_device(fimc->m2m.vfd);
  1239. v4l2_device_unregister(&fimc->m2m.v4l2_dev);
  1240. }
  1241. }
  1242. static void fimc_clk_release(struct fimc_dev *fimc)
  1243. {
  1244. int i;
  1245. for (i = 0; i < NUM_FIMC_CLOCKS; i++) {
  1246. if (fimc->clock[i]) {
  1247. clk_disable(fimc->clock[i]);
  1248. clk_put(fimc->clock[i]);
  1249. }
  1250. }
  1251. }
  1252. static int fimc_clk_get(struct fimc_dev *fimc)
  1253. {
  1254. int i;
  1255. for (i = 0; i < NUM_FIMC_CLOCKS; i++) {
  1256. fimc->clock[i] = clk_get(&fimc->pdev->dev, fimc_clock_name[i]);
  1257. if (IS_ERR(fimc->clock[i])) {
  1258. dev_err(&fimc->pdev->dev,
  1259. "failed to get fimc clock: %s\n",
  1260. fimc_clock_name[i]);
  1261. return -ENXIO;
  1262. }
  1263. clk_enable(fimc->clock[i]);
  1264. }
  1265. return 0;
  1266. }
  1267. static int fimc_probe(struct platform_device *pdev)
  1268. {
  1269. struct fimc_dev *fimc;
  1270. struct resource *res;
  1271. struct samsung_fimc_driverdata *drv_data;
  1272. int ret = 0;
  1273. dev_dbg(&pdev->dev, "%s():\n", __func__);
  1274. drv_data = (struct samsung_fimc_driverdata *)
  1275. platform_get_device_id(pdev)->driver_data;
  1276. if (pdev->id >= drv_data->num_entities) {
  1277. dev_err(&pdev->dev, "Invalid platform device id: %d\n",
  1278. pdev->id);
  1279. return -EINVAL;
  1280. }
  1281. fimc = kzalloc(sizeof(struct fimc_dev), GFP_KERNEL);
  1282. if (!fimc)
  1283. return -ENOMEM;
  1284. fimc->id = pdev->id;
  1285. fimc->variant = drv_data->variant[fimc->id];
  1286. fimc->pdev = pdev;
  1287. fimc->pdata = pdev->dev.platform_data;
  1288. fimc->state = ST_IDLE;
  1289. spin_lock_init(&fimc->irqlock);
  1290. init_waitqueue_head(&fimc->irq_queue);
  1291. spin_lock_init(&fimc->slock);
  1292. mutex_init(&fimc->lock);
  1293. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1294. if (!res) {
  1295. dev_err(&pdev->dev, "failed to find the registers\n");
  1296. ret = -ENOENT;
  1297. goto err_info;
  1298. }
  1299. fimc->regs_res = request_mem_region(res->start, resource_size(res),
  1300. dev_name(&pdev->dev));
  1301. if (!fimc->regs_res) {
  1302. dev_err(&pdev->dev, "failed to obtain register region\n");
  1303. ret = -ENOENT;
  1304. goto err_info;
  1305. }
  1306. fimc->regs = ioremap(res->start, resource_size(res));
  1307. if (!fimc->regs) {
  1308. dev_err(&pdev->dev, "failed to map registers\n");
  1309. ret = -ENXIO;
  1310. goto err_req_region;
  1311. }
  1312. ret = fimc_clk_get(fimc);
  1313. if (ret)
  1314. goto err_regs_unmap;
  1315. clk_set_rate(fimc->clock[0], drv_data->lclk_frequency);
  1316. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1317. if (!res) {
  1318. dev_err(&pdev->dev, "failed to get IRQ resource\n");
  1319. ret = -ENXIO;
  1320. goto err_clk;
  1321. }
  1322. fimc->irq = res->start;
  1323. fimc_hw_reset(fimc);
  1324. ret = request_irq(fimc->irq, fimc_isr, 0, pdev->name, fimc);
  1325. if (ret) {
  1326. dev_err(&pdev->dev, "failed to install irq (%d)\n", ret);
  1327. goto err_clk;
  1328. }
  1329. ret = fimc_register_m2m_device(fimc);
  1330. if (ret)
  1331. goto err_irq;
  1332. /* At least one camera sensor is required to register capture node */
  1333. if (fimc->pdata) {
  1334. int i;
  1335. for (i = 0; i < FIMC_MAX_CAMIF_CLIENTS; ++i)
  1336. if (fimc->pdata->isp_info[i])
  1337. break;
  1338. if (i < FIMC_MAX_CAMIF_CLIENTS) {
  1339. ret = fimc_register_capture_device(fimc);
  1340. if (ret)
  1341. goto err_m2m;
  1342. }
  1343. }
  1344. /*
  1345. * Exclude the additional output DMA address registers by masking
  1346. * them out on HW revisions that provide extended capabilites.
  1347. */
  1348. if (fimc->variant->out_buf_count > 4)
  1349. fimc_hw_set_dma_seq(fimc, 0xF);
  1350. dev_dbg(&pdev->dev, "%s(): fimc-%d registered successfully\n",
  1351. __func__, fimc->id);
  1352. return 0;
  1353. err_m2m:
  1354. fimc_unregister_m2m_device(fimc);
  1355. err_irq:
  1356. free_irq(fimc->irq, fimc);
  1357. err_clk:
  1358. fimc_clk_release(fimc);
  1359. err_regs_unmap:
  1360. iounmap(fimc->regs);
  1361. err_req_region:
  1362. release_resource(fimc->regs_res);
  1363. kfree(fimc->regs_res);
  1364. err_info:
  1365. kfree(fimc);
  1366. return ret;
  1367. }
  1368. static int __devexit fimc_remove(struct platform_device *pdev)
  1369. {
  1370. struct fimc_dev *fimc =
  1371. (struct fimc_dev *)platform_get_drvdata(pdev);
  1372. free_irq(fimc->irq, fimc);
  1373. fimc_hw_reset(fimc);
  1374. fimc_unregister_m2m_device(fimc);
  1375. fimc_unregister_capture_device(fimc);
  1376. fimc_clk_release(fimc);
  1377. iounmap(fimc->regs);
  1378. release_resource(fimc->regs_res);
  1379. kfree(fimc->regs_res);
  1380. kfree(fimc);
  1381. dev_info(&pdev->dev, "%s driver unloaded\n", pdev->name);
  1382. return 0;
  1383. }
  1384. /* Image pixel limits, similar across several FIMC HW revisions. */
  1385. static struct fimc_pix_limit s5p_pix_limit[3] = {
  1386. [0] = {
  1387. .scaler_en_w = 3264,
  1388. .scaler_dis_w = 8192,
  1389. .in_rot_en_h = 1920,
  1390. .in_rot_dis_w = 8192,
  1391. .out_rot_en_w = 1920,
  1392. .out_rot_dis_w = 4224,
  1393. },
  1394. [1] = {
  1395. .scaler_en_w = 4224,
  1396. .scaler_dis_w = 8192,
  1397. .in_rot_en_h = 1920,
  1398. .in_rot_dis_w = 8192,
  1399. .out_rot_en_w = 1920,
  1400. .out_rot_dis_w = 4224,
  1401. },
  1402. [2] = {
  1403. .scaler_en_w = 1920,
  1404. .scaler_dis_w = 8192,
  1405. .in_rot_en_h = 1280,
  1406. .in_rot_dis_w = 8192,
  1407. .out_rot_en_w = 1280,
  1408. .out_rot_dis_w = 1920,
  1409. },
  1410. };
  1411. static struct samsung_fimc_variant fimc0_variant_s5p = {
  1412. .has_inp_rot = 1,
  1413. .has_out_rot = 1,
  1414. .min_inp_pixsize = 16,
  1415. .min_out_pixsize = 16,
  1416. .hor_offs_align = 8,
  1417. .out_buf_count = 4,
  1418. .pix_limit = &s5p_pix_limit[0],
  1419. };
  1420. static struct samsung_fimc_variant fimc2_variant_s5p = {
  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 fimc0_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 = 8,
  1434. .out_buf_count = 4,
  1435. .pix_limit = &s5p_pix_limit[1],
  1436. };
  1437. static struct samsung_fimc_variant fimc1_variant_s5pv210 = {
  1438. .pix_hoff = 1,
  1439. .has_inp_rot = 1,
  1440. .has_out_rot = 1,
  1441. .min_inp_pixsize = 16,
  1442. .min_out_pixsize = 16,
  1443. .hor_offs_align = 1,
  1444. .out_buf_count = 4,
  1445. .pix_limit = &s5p_pix_limit[2],
  1446. };
  1447. static struct samsung_fimc_variant fimc2_variant_s5pv210 = {
  1448. .pix_hoff = 1,
  1449. .min_inp_pixsize = 16,
  1450. .min_out_pixsize = 16,
  1451. .hor_offs_align = 8,
  1452. .out_buf_count = 4,
  1453. .pix_limit = &s5p_pix_limit[2],
  1454. };
  1455. static struct samsung_fimc_variant fimc0_variant_s5pv310 = {
  1456. .pix_hoff = 1,
  1457. .has_inp_rot = 1,
  1458. .has_out_rot = 1,
  1459. .has_cistatus2 = 1,
  1460. .min_inp_pixsize = 16,
  1461. .min_out_pixsize = 16,
  1462. .hor_offs_align = 1,
  1463. .out_buf_count = 32,
  1464. .pix_limit = &s5p_pix_limit[1],
  1465. };
  1466. static struct samsung_fimc_variant fimc2_variant_s5pv310 = {
  1467. .pix_hoff = 1,
  1468. .has_cistatus2 = 1,
  1469. .min_inp_pixsize = 16,
  1470. .min_out_pixsize = 16,
  1471. .hor_offs_align = 1,
  1472. .out_buf_count = 32,
  1473. .pix_limit = &s5p_pix_limit[2],
  1474. };
  1475. /* S5PC100 */
  1476. static struct samsung_fimc_driverdata fimc_drvdata_s5p = {
  1477. .variant = {
  1478. [0] = &fimc0_variant_s5p,
  1479. [1] = &fimc0_variant_s5p,
  1480. [2] = &fimc2_variant_s5p,
  1481. },
  1482. .num_entities = 3,
  1483. .lclk_frequency = 133000000UL,
  1484. };
  1485. /* S5PV210, S5PC110 */
  1486. static struct samsung_fimc_driverdata fimc_drvdata_s5pv210 = {
  1487. .variant = {
  1488. [0] = &fimc0_variant_s5pv210,
  1489. [1] = &fimc1_variant_s5pv210,
  1490. [2] = &fimc2_variant_s5pv210,
  1491. },
  1492. .num_entities = 3,
  1493. .lclk_frequency = 166000000UL,
  1494. };
  1495. /* S5PV310, S5PC210 */
  1496. static struct samsung_fimc_driverdata fimc_drvdata_s5pv310 = {
  1497. .variant = {
  1498. [0] = &fimc0_variant_s5pv310,
  1499. [1] = &fimc0_variant_s5pv310,
  1500. [2] = &fimc0_variant_s5pv310,
  1501. [3] = &fimc2_variant_s5pv310,
  1502. },
  1503. .num_entities = 4,
  1504. .lclk_frequency = 166000000UL,
  1505. };
  1506. static struct platform_device_id fimc_driver_ids[] = {
  1507. {
  1508. .name = "s5p-fimc",
  1509. .driver_data = (unsigned long)&fimc_drvdata_s5p,
  1510. }, {
  1511. .name = "s5pv210-fimc",
  1512. .driver_data = (unsigned long)&fimc_drvdata_s5pv210,
  1513. }, {
  1514. .name = "s5pv310-fimc",
  1515. .driver_data = (unsigned long)&fimc_drvdata_s5pv310,
  1516. },
  1517. {},
  1518. };
  1519. MODULE_DEVICE_TABLE(platform, fimc_driver_ids);
  1520. static struct platform_driver fimc_driver = {
  1521. .probe = fimc_probe,
  1522. .remove = __devexit_p(fimc_remove),
  1523. .id_table = fimc_driver_ids,
  1524. .driver = {
  1525. .name = MODULE_NAME,
  1526. .owner = THIS_MODULE,
  1527. }
  1528. };
  1529. static int __init fimc_init(void)
  1530. {
  1531. int ret = platform_driver_register(&fimc_driver);
  1532. if (ret)
  1533. err("platform_driver_register failed: %d\n", ret);
  1534. return ret;
  1535. }
  1536. static void __exit fimc_exit(void)
  1537. {
  1538. platform_driver_unregister(&fimc_driver);
  1539. }
  1540. module_init(fimc_init);
  1541. module_exit(fimc_exit);
  1542. MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
  1543. MODULE_DESCRIPTION("S5P FIMC camera host interface/video postprocessor driver");
  1544. MODULE_LICENSE("GPL");