fimc-reg.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. /*
  2. * Register interface file for Samsung Camera Interface (FIMC) driver
  3. *
  4. * Copyright (c) 2010 Samsung Electronics
  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 version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/io.h>
  13. #include <linux/delay.h>
  14. #include <mach/map.h>
  15. #include <media/s3c_fimc.h>
  16. #include "fimc-core.h"
  17. void fimc_hw_reset(struct fimc_dev *dev)
  18. {
  19. u32 cfg;
  20. cfg = readl(dev->regs + S5P_CISRCFMT);
  21. cfg |= S5P_CISRCFMT_ITU601_8BIT;
  22. writel(cfg, dev->regs + S5P_CISRCFMT);
  23. /* Software reset. */
  24. cfg = readl(dev->regs + S5P_CIGCTRL);
  25. cfg |= (S5P_CIGCTRL_SWRST | S5P_CIGCTRL_IRQ_LEVEL);
  26. writel(cfg, dev->regs + S5P_CIGCTRL);
  27. udelay(1000);
  28. cfg = readl(dev->regs + S5P_CIGCTRL);
  29. cfg &= ~S5P_CIGCTRL_SWRST;
  30. writel(cfg, dev->regs + S5P_CIGCTRL);
  31. }
  32. static u32 fimc_hw_get_in_flip(u32 ctx_flip)
  33. {
  34. u32 flip = S5P_MSCTRL_FLIP_NORMAL;
  35. switch (ctx_flip) {
  36. case FLIP_X_AXIS:
  37. flip = S5P_MSCTRL_FLIP_X_MIRROR;
  38. break;
  39. case FLIP_Y_AXIS:
  40. flip = S5P_MSCTRL_FLIP_Y_MIRROR;
  41. break;
  42. case FLIP_XY_AXIS:
  43. flip = S5P_MSCTRL_FLIP_180;
  44. break;
  45. }
  46. return flip;
  47. }
  48. static u32 fimc_hw_get_target_flip(u32 ctx_flip)
  49. {
  50. u32 flip = S5P_CITRGFMT_FLIP_NORMAL;
  51. switch (ctx_flip) {
  52. case FLIP_X_AXIS:
  53. flip = S5P_CITRGFMT_FLIP_X_MIRROR;
  54. break;
  55. case FLIP_Y_AXIS:
  56. flip = S5P_CITRGFMT_FLIP_Y_MIRROR;
  57. break;
  58. case FLIP_XY_AXIS:
  59. flip = S5P_CITRGFMT_FLIP_180;
  60. break;
  61. case FLIP_NONE:
  62. break;
  63. }
  64. return flip;
  65. }
  66. void fimc_hw_set_rotation(struct fimc_ctx *ctx)
  67. {
  68. u32 cfg, flip;
  69. struct fimc_dev *dev = ctx->fimc_dev;
  70. cfg = readl(dev->regs + S5P_CITRGFMT);
  71. cfg &= ~(S5P_CITRGFMT_INROT90 | S5P_CITRGFMT_OUTROT90 |
  72. S5P_CITRGFMT_FLIP_180);
  73. flip = readl(dev->regs + S5P_MSCTRL);
  74. flip &= ~S5P_MSCTRL_FLIP_MASK;
  75. /*
  76. * The input and output rotator cannot work simultaneously.
  77. * Use the output rotator in output DMA mode or the input rotator
  78. * in direct fifo output mode.
  79. */
  80. if (ctx->rotation == 90 || ctx->rotation == 270) {
  81. if (ctx->out_path == FIMC_LCDFIFO) {
  82. cfg |= S5P_CITRGFMT_INROT90;
  83. if (ctx->rotation == 270)
  84. flip |= S5P_MSCTRL_FLIP_180;
  85. } else {
  86. cfg |= S5P_CITRGFMT_OUTROT90;
  87. if (ctx->rotation == 270)
  88. cfg |= S5P_CITRGFMT_FLIP_180;
  89. }
  90. } else if (ctx->rotation == 180) {
  91. if (ctx->out_path == FIMC_LCDFIFO)
  92. flip |= S5P_MSCTRL_FLIP_180;
  93. else
  94. cfg |= S5P_CITRGFMT_FLIP_180;
  95. }
  96. if (ctx->rotation == 180 || ctx->rotation == 270)
  97. writel(flip, dev->regs + S5P_MSCTRL);
  98. cfg |= fimc_hw_get_target_flip(ctx->flip);
  99. writel(cfg, dev->regs + S5P_CITRGFMT);
  100. }
  101. void fimc_hw_set_target_format(struct fimc_ctx *ctx)
  102. {
  103. u32 cfg;
  104. struct fimc_dev *dev = ctx->fimc_dev;
  105. struct fimc_frame *frame = &ctx->d_frame;
  106. dbg("w= %d, h= %d color: %d", frame->width,
  107. frame->height, frame->fmt->color);
  108. cfg = readl(dev->regs + S5P_CITRGFMT);
  109. cfg &= ~(S5P_CITRGFMT_FMT_MASK | S5P_CITRGFMT_HSIZE_MASK |
  110. S5P_CITRGFMT_VSIZE_MASK);
  111. switch (frame->fmt->color) {
  112. case S5P_FIMC_RGB565:
  113. case S5P_FIMC_RGB666:
  114. case S5P_FIMC_RGB888:
  115. cfg |= S5P_CITRGFMT_RGB;
  116. break;
  117. case S5P_FIMC_YCBCR420:
  118. cfg |= S5P_CITRGFMT_YCBCR420;
  119. break;
  120. case S5P_FIMC_YCBYCR422:
  121. case S5P_FIMC_YCRYCB422:
  122. case S5P_FIMC_CBYCRY422:
  123. case S5P_FIMC_CRYCBY422:
  124. if (frame->fmt->colplanes == 1)
  125. cfg |= S5P_CITRGFMT_YCBCR422_1P;
  126. else
  127. cfg |= S5P_CITRGFMT_YCBCR422;
  128. break;
  129. default:
  130. break;
  131. }
  132. if (ctx->rotation == 90 || ctx->rotation == 270) {
  133. cfg |= S5P_CITRGFMT_HSIZE(frame->height);
  134. cfg |= S5P_CITRGFMT_VSIZE(frame->width);
  135. } else {
  136. cfg |= S5P_CITRGFMT_HSIZE(frame->width);
  137. cfg |= S5P_CITRGFMT_VSIZE(frame->height);
  138. }
  139. writel(cfg, dev->regs + S5P_CITRGFMT);
  140. cfg = readl(dev->regs + S5P_CITAREA) & ~S5P_CITAREA_MASK;
  141. cfg |= (frame->width * frame->height);
  142. writel(cfg, dev->regs + S5P_CITAREA);
  143. }
  144. static void fimc_hw_set_out_dma_size(struct fimc_ctx *ctx)
  145. {
  146. struct fimc_dev *dev = ctx->fimc_dev;
  147. struct fimc_frame *frame = &ctx->d_frame;
  148. u32 cfg;
  149. cfg = S5P_ORIG_SIZE_HOR(frame->f_width);
  150. cfg |= S5P_ORIG_SIZE_VER(frame->f_height);
  151. writel(cfg, dev->regs + S5P_ORGOSIZE);
  152. /* Select color space conversion equation (HD/SD size).*/
  153. cfg = readl(dev->regs + S5P_CIGCTRL);
  154. if (frame->f_width >= 1280) /* HD */
  155. cfg |= S5P_CIGCTRL_CSC_ITU601_709;
  156. else /* SD */
  157. cfg &= ~S5P_CIGCTRL_CSC_ITU601_709;
  158. writel(cfg, dev->regs + S5P_CIGCTRL);
  159. }
  160. void fimc_hw_set_out_dma(struct fimc_ctx *ctx)
  161. {
  162. u32 cfg;
  163. struct fimc_dev *dev = ctx->fimc_dev;
  164. struct fimc_frame *frame = &ctx->d_frame;
  165. struct fimc_dma_offset *offset = &frame->dma_offset;
  166. /* Set the input dma offsets. */
  167. cfg = 0;
  168. cfg |= S5P_CIO_OFFS_HOR(offset->y_h);
  169. cfg |= S5P_CIO_OFFS_VER(offset->y_v);
  170. writel(cfg, dev->regs + S5P_CIOYOFF);
  171. cfg = 0;
  172. cfg |= S5P_CIO_OFFS_HOR(offset->cb_h);
  173. cfg |= S5P_CIO_OFFS_VER(offset->cb_v);
  174. writel(cfg, dev->regs + S5P_CIOCBOFF);
  175. cfg = 0;
  176. cfg |= S5P_CIO_OFFS_HOR(offset->cr_h);
  177. cfg |= S5P_CIO_OFFS_VER(offset->cr_v);
  178. writel(cfg, dev->regs + S5P_CIOCROFF);
  179. fimc_hw_set_out_dma_size(ctx);
  180. /* Configure chroma components order. */
  181. cfg = readl(dev->regs + S5P_CIOCTRL);
  182. cfg &= ~(S5P_CIOCTRL_ORDER2P_MASK | S5P_CIOCTRL_ORDER422_MASK |
  183. S5P_CIOCTRL_YCBCR_PLANE_MASK);
  184. if (frame->fmt->colplanes == 1)
  185. cfg |= ctx->out_order_1p;
  186. else if (frame->fmt->colplanes == 2)
  187. cfg |= ctx->out_order_2p | S5P_CIOCTRL_YCBCR_2PLANE;
  188. else if (frame->fmt->colplanes == 3)
  189. cfg |= S5P_CIOCTRL_YCBCR_3PLANE;
  190. writel(cfg, dev->regs + S5P_CIOCTRL);
  191. }
  192. static void fimc_hw_en_autoload(struct fimc_dev *dev, int enable)
  193. {
  194. u32 cfg = readl(dev->regs + S5P_ORGISIZE);
  195. if (enable)
  196. cfg |= S5P_CIREAL_ISIZE_AUTOLOAD_EN;
  197. else
  198. cfg &= ~S5P_CIREAL_ISIZE_AUTOLOAD_EN;
  199. writel(cfg, dev->regs + S5P_ORGISIZE);
  200. }
  201. void fimc_hw_en_lastirq(struct fimc_dev *dev, int enable)
  202. {
  203. u32 cfg = readl(dev->regs + S5P_CIOCTRL);
  204. if (enable)
  205. cfg |= S5P_CIOCTRL_LASTIRQ_ENABLE;
  206. else
  207. cfg &= ~S5P_CIOCTRL_LASTIRQ_ENABLE;
  208. writel(cfg, dev->regs + S5P_CIOCTRL);
  209. }
  210. static void fimc_hw_set_prescaler(struct fimc_ctx *ctx)
  211. {
  212. struct fimc_dev *dev = ctx->fimc_dev;
  213. struct fimc_scaler *sc = &ctx->scaler;
  214. u32 cfg, shfactor;
  215. shfactor = 10 - (sc->hfactor + sc->vfactor);
  216. cfg = S5P_CISCPRERATIO_SHFACTOR(shfactor);
  217. cfg |= S5P_CISCPRERATIO_HOR(sc->pre_hratio);
  218. cfg |= S5P_CISCPRERATIO_VER(sc->pre_vratio);
  219. writel(cfg, dev->regs + S5P_CISCPRERATIO);
  220. cfg = S5P_CISCPREDST_WIDTH(sc->pre_dst_width);
  221. cfg |= S5P_CISCPREDST_HEIGHT(sc->pre_dst_height);
  222. writel(cfg, dev->regs + S5P_CISCPREDST);
  223. }
  224. void fimc_hw_set_scaler(struct fimc_ctx *ctx)
  225. {
  226. struct fimc_dev *dev = ctx->fimc_dev;
  227. struct fimc_scaler *sc = &ctx->scaler;
  228. struct fimc_frame *src_frame = &ctx->s_frame;
  229. struct fimc_frame *dst_frame = &ctx->d_frame;
  230. u32 cfg = 0;
  231. fimc_hw_set_prescaler(ctx);
  232. if (!(ctx->flags & FIMC_COLOR_RANGE_NARROW))
  233. cfg |= (S5P_CISCCTRL_CSCR2Y_WIDE | S5P_CISCCTRL_CSCY2R_WIDE);
  234. if (!sc->enabled)
  235. cfg |= S5P_CISCCTRL_SCALERBYPASS;
  236. if (sc->scaleup_h)
  237. cfg |= S5P_CISCCTRL_SCALEUP_H;
  238. if (sc->scaleup_v)
  239. cfg |= S5P_CISCCTRL_SCALEUP_V;
  240. if (sc->copy_mode)
  241. cfg |= S5P_CISCCTRL_ONE2ONE;
  242. if (ctx->in_path == FIMC_DMA) {
  243. if (src_frame->fmt->color == S5P_FIMC_RGB565)
  244. cfg |= S5P_CISCCTRL_INRGB_FMT_RGB565;
  245. else if (src_frame->fmt->color == S5P_FIMC_RGB666)
  246. cfg |= S5P_CISCCTRL_INRGB_FMT_RGB666;
  247. else if (src_frame->fmt->color == S5P_FIMC_RGB888)
  248. cfg |= S5P_CISCCTRL_INRGB_FMT_RGB888;
  249. }
  250. if (ctx->out_path == FIMC_DMA) {
  251. if (dst_frame->fmt->color == S5P_FIMC_RGB565)
  252. cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB565;
  253. else if (dst_frame->fmt->color == S5P_FIMC_RGB666)
  254. cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB666;
  255. else if (dst_frame->fmt->color == S5P_FIMC_RGB888)
  256. cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888;
  257. } else {
  258. cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888;
  259. if (ctx->flags & FIMC_SCAN_MODE_INTERLACED)
  260. cfg |= S5P_CISCCTRL_INTERLACE;
  261. }
  262. dbg("main_hratio= 0x%X main_vratio= 0x%X",
  263. sc->main_hratio, sc->main_vratio);
  264. cfg |= S5P_CISCCTRL_SC_HORRATIO(sc->main_hratio);
  265. cfg |= S5P_CISCCTRL_SC_VERRATIO(sc->main_vratio);
  266. writel(cfg, dev->regs + S5P_CISCCTRL);
  267. }
  268. void fimc_hw_en_capture(struct fimc_ctx *ctx)
  269. {
  270. struct fimc_dev *dev = ctx->fimc_dev;
  271. u32 cfg = readl(dev->regs + S5P_CIIMGCPT);
  272. if (ctx->out_path == FIMC_DMA) {
  273. /* one shot mode */
  274. cfg |= S5P_CIIMGCPT_CPT_FREN_ENABLE | S5P_CIIMGCPT_IMGCPTEN;
  275. } else {
  276. /* Continous frame capture mode (freerun). */
  277. cfg &= ~(S5P_CIIMGCPT_CPT_FREN_ENABLE |
  278. S5P_CIIMGCPT_CPT_FRMOD_CNT);
  279. cfg |= S5P_CIIMGCPT_IMGCPTEN;
  280. }
  281. if (ctx->scaler.enabled)
  282. cfg |= S5P_CIIMGCPT_IMGCPTEN_SC;
  283. writel(cfg | S5P_CIIMGCPT_IMGCPTEN, dev->regs + S5P_CIIMGCPT);
  284. }
  285. void fimc_hw_set_effect(struct fimc_ctx *ctx)
  286. {
  287. struct fimc_dev *dev = ctx->fimc_dev;
  288. struct fimc_effect *effect = &ctx->effect;
  289. u32 cfg = (S5P_CIIMGEFF_IE_ENABLE | S5P_CIIMGEFF_IE_SC_AFTER);
  290. cfg |= effect->type;
  291. if (effect->type == S5P_FIMC_EFFECT_ARBITRARY) {
  292. cfg |= S5P_CIIMGEFF_PAT_CB(effect->pat_cb);
  293. cfg |= S5P_CIIMGEFF_PAT_CR(effect->pat_cr);
  294. }
  295. writel(cfg, dev->regs + S5P_CIIMGEFF);
  296. }
  297. static void fimc_hw_set_in_dma_size(struct fimc_ctx *ctx)
  298. {
  299. struct fimc_dev *dev = ctx->fimc_dev;
  300. struct fimc_frame *frame = &ctx->s_frame;
  301. u32 cfg_o = 0;
  302. u32 cfg_r = 0;
  303. if (FIMC_LCDFIFO == ctx->out_path)
  304. cfg_r |= S5P_CIREAL_ISIZE_AUTOLOAD_EN;
  305. cfg_o |= S5P_ORIG_SIZE_HOR(frame->f_width);
  306. cfg_o |= S5P_ORIG_SIZE_VER(frame->f_height);
  307. cfg_r |= S5P_CIREAL_ISIZE_WIDTH(frame->width);
  308. cfg_r |= S5P_CIREAL_ISIZE_HEIGHT(frame->height);
  309. writel(cfg_o, dev->regs + S5P_ORGISIZE);
  310. writel(cfg_r, dev->regs + S5P_CIREAL_ISIZE);
  311. }
  312. void fimc_hw_set_in_dma(struct fimc_ctx *ctx)
  313. {
  314. struct fimc_dev *dev = ctx->fimc_dev;
  315. struct fimc_frame *frame = &ctx->s_frame;
  316. struct fimc_dma_offset *offset = &frame->dma_offset;
  317. u32 cfg;
  318. /* Set the pixel offsets. */
  319. cfg = S5P_CIO_OFFS_HOR(offset->y_h);
  320. cfg |= S5P_CIO_OFFS_VER(offset->y_v);
  321. writel(cfg, dev->regs + S5P_CIIYOFF);
  322. cfg = S5P_CIO_OFFS_HOR(offset->cb_h);
  323. cfg |= S5P_CIO_OFFS_VER(offset->cb_v);
  324. writel(cfg, dev->regs + S5P_CIICBOFF);
  325. cfg = S5P_CIO_OFFS_HOR(offset->cr_h);
  326. cfg |= S5P_CIO_OFFS_VER(offset->cr_v);
  327. writel(cfg, dev->regs + S5P_CIICROFF);
  328. /* Input original and real size. */
  329. fimc_hw_set_in_dma_size(ctx);
  330. /* Use DMA autoload only in FIFO mode. */
  331. fimc_hw_en_autoload(dev, ctx->out_path == FIMC_LCDFIFO);
  332. /* Set the input DMA to process single frame only. */
  333. cfg = readl(dev->regs + S5P_MSCTRL);
  334. cfg &= ~(S5P_MSCTRL_FLIP_MASK
  335. | S5P_MSCTRL_INFORMAT_MASK
  336. | S5P_MSCTRL_IN_BURST_COUNT_MASK
  337. | S5P_MSCTRL_INPUT_MASK
  338. | S5P_MSCTRL_C_INT_IN_MASK
  339. | S5P_MSCTRL_2P_IN_ORDER_MASK);
  340. cfg |= (S5P_MSCTRL_FRAME_COUNT(1) | S5P_MSCTRL_INPUT_MEMORY);
  341. switch (frame->fmt->color) {
  342. case S5P_FIMC_RGB565:
  343. case S5P_FIMC_RGB666:
  344. case S5P_FIMC_RGB888:
  345. cfg |= S5P_MSCTRL_INFORMAT_RGB;
  346. break;
  347. case S5P_FIMC_YCBCR420:
  348. cfg |= S5P_MSCTRL_INFORMAT_YCBCR420;
  349. if (frame->fmt->colplanes == 2)
  350. cfg |= ctx->in_order_2p | S5P_MSCTRL_C_INT_IN_2PLANE;
  351. else
  352. cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
  353. break;
  354. case S5P_FIMC_YCBYCR422:
  355. case S5P_FIMC_YCRYCB422:
  356. case S5P_FIMC_CBYCRY422:
  357. case S5P_FIMC_CRYCBY422:
  358. if (frame->fmt->colplanes == 1) {
  359. cfg |= ctx->in_order_1p
  360. | S5P_MSCTRL_INFORMAT_YCBCR422_1P;
  361. } else {
  362. cfg |= S5P_MSCTRL_INFORMAT_YCBCR422;
  363. if (frame->fmt->colplanes == 2)
  364. cfg |= ctx->in_order_2p
  365. | S5P_MSCTRL_C_INT_IN_2PLANE;
  366. else
  367. cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
  368. }
  369. break;
  370. default:
  371. break;
  372. }
  373. /*
  374. * Input DMA flip mode (and rotation).
  375. * Do not allow simultaneous rotation and flipping.
  376. */
  377. if (!ctx->rotation && ctx->out_path == FIMC_LCDFIFO)
  378. cfg |= fimc_hw_get_in_flip(ctx->flip);
  379. writel(cfg, dev->regs + S5P_MSCTRL);
  380. /* Input/output DMA linear/tiled mode. */
  381. cfg = readl(dev->regs + S5P_CIDMAPARAM);
  382. cfg &= ~S5P_CIDMAPARAM_TILE_MASK;
  383. if (tiled_fmt(ctx->s_frame.fmt))
  384. cfg |= S5P_CIDMAPARAM_R_64X32;
  385. if (tiled_fmt(ctx->d_frame.fmt))
  386. cfg |= S5P_CIDMAPARAM_W_64X32;
  387. writel(cfg, dev->regs + S5P_CIDMAPARAM);
  388. }
  389. void fimc_hw_set_input_path(struct fimc_ctx *ctx)
  390. {
  391. struct fimc_dev *dev = ctx->fimc_dev;
  392. u32 cfg = readl(dev->regs + S5P_MSCTRL);
  393. cfg &= ~S5P_MSCTRL_INPUT_MASK;
  394. if (ctx->in_path == FIMC_DMA)
  395. cfg |= S5P_MSCTRL_INPUT_MEMORY;
  396. else
  397. cfg |= S5P_MSCTRL_INPUT_EXTCAM;
  398. writel(cfg, dev->regs + S5P_MSCTRL);
  399. }
  400. void fimc_hw_set_output_path(struct fimc_ctx *ctx)
  401. {
  402. struct fimc_dev *dev = ctx->fimc_dev;
  403. u32 cfg = readl(dev->regs + S5P_CISCCTRL);
  404. cfg &= ~S5P_CISCCTRL_LCDPATHEN_FIFO;
  405. if (ctx->out_path == FIMC_LCDFIFO)
  406. cfg |= S5P_CISCCTRL_LCDPATHEN_FIFO;
  407. writel(cfg, dev->regs + S5P_CISCCTRL);
  408. }
  409. void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *paddr)
  410. {
  411. u32 cfg = readl(dev->regs + S5P_CIREAL_ISIZE);
  412. cfg |= S5P_CIREAL_ISIZE_ADDR_CH_DIS;
  413. writel(cfg, dev->regs + S5P_CIREAL_ISIZE);
  414. writel(paddr->y, dev->regs + S5P_CIIYSA(0));
  415. writel(paddr->cb, dev->regs + S5P_CIICBSA(0));
  416. writel(paddr->cr, dev->regs + S5P_CIICRSA(0));
  417. cfg &= ~S5P_CIREAL_ISIZE_ADDR_CH_DIS;
  418. writel(cfg, dev->regs + S5P_CIREAL_ISIZE);
  419. }
  420. void fimc_hw_set_output_addr(struct fimc_dev *dev,
  421. struct fimc_addr *paddr, int index)
  422. {
  423. int i = (index == -1) ? 0 : index;
  424. do {
  425. writel(paddr->y, dev->regs + S5P_CIOYSA(i));
  426. writel(paddr->cb, dev->regs + S5P_CIOCBSA(i));
  427. writel(paddr->cr, dev->regs + S5P_CIOCRSA(i));
  428. dbg("dst_buf[%d]: 0x%X, cb: 0x%X, cr: 0x%X",
  429. i, paddr->y, paddr->cb, paddr->cr);
  430. } while (index == -1 && ++i < FIMC_MAX_OUT_BUFS);
  431. }
  432. int fimc_hw_set_camera_polarity(struct fimc_dev *fimc,
  433. struct s3c_fimc_isp_info *cam)
  434. {
  435. u32 cfg = readl(fimc->regs + S5P_CIGCTRL);
  436. cfg &= ~(S5P_CIGCTRL_INVPOLPCLK | S5P_CIGCTRL_INVPOLVSYNC |
  437. S5P_CIGCTRL_INVPOLHREF | S5P_CIGCTRL_INVPOLHSYNC);
  438. if (cam->flags & FIMC_CLK_INV_PCLK)
  439. cfg |= S5P_CIGCTRL_INVPOLPCLK;
  440. if (cam->flags & FIMC_CLK_INV_VSYNC)
  441. cfg |= S5P_CIGCTRL_INVPOLVSYNC;
  442. if (cam->flags & FIMC_CLK_INV_HREF)
  443. cfg |= S5P_CIGCTRL_INVPOLHREF;
  444. if (cam->flags & FIMC_CLK_INV_HSYNC)
  445. cfg |= S5P_CIGCTRL_INVPOLHSYNC;
  446. writel(cfg, fimc->regs + S5P_CIGCTRL);
  447. return 0;
  448. }
  449. int fimc_hw_set_camera_source(struct fimc_dev *fimc,
  450. struct s3c_fimc_isp_info *cam)
  451. {
  452. struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame;
  453. u32 cfg = 0;
  454. if (cam->bus_type == FIMC_ITU_601 || cam->bus_type == FIMC_ITU_656) {
  455. switch (fimc->vid_cap.fmt.code) {
  456. case V4L2_MBUS_FMT_YUYV8_2X8:
  457. cfg = S5P_CISRCFMT_ORDER422_YCBYCR;
  458. break;
  459. case V4L2_MBUS_FMT_YVYU8_2X8:
  460. cfg = S5P_CISRCFMT_ORDER422_YCRYCB;
  461. break;
  462. case V4L2_MBUS_FMT_VYUY8_2X8:
  463. cfg = S5P_CISRCFMT_ORDER422_CRYCBY;
  464. break;
  465. case V4L2_MBUS_FMT_UYVY8_2X8:
  466. cfg = S5P_CISRCFMT_ORDER422_CBYCRY;
  467. break;
  468. default:
  469. err("camera image format not supported: %d",
  470. fimc->vid_cap.fmt.code);
  471. return -EINVAL;
  472. }
  473. if (cam->bus_type == FIMC_ITU_601) {
  474. if (cam->bus_width == 8) {
  475. cfg |= S5P_CISRCFMT_ITU601_8BIT;
  476. } else if (cam->bus_width == 16) {
  477. cfg |= S5P_CISRCFMT_ITU601_16BIT;
  478. } else {
  479. err("invalid bus width: %d", cam->bus_width);
  480. return -EINVAL;
  481. }
  482. } /* else defaults to ITU-R BT.656 8-bit */
  483. }
  484. cfg |= S5P_CISRCFMT_HSIZE(f->o_width) | S5P_CISRCFMT_VSIZE(f->o_height);
  485. writel(cfg, fimc->regs + S5P_CISRCFMT);
  486. return 0;
  487. }
  488. int fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f)
  489. {
  490. u32 hoff2, voff2;
  491. u32 cfg = readl(fimc->regs + S5P_CIWDOFST);
  492. cfg &= ~(S5P_CIWDOFST_HOROFF_MASK | S5P_CIWDOFST_VEROFF_MASK);
  493. cfg |= S5P_CIWDOFST_OFF_EN |
  494. S5P_CIWDOFST_HOROFF(f->offs_h) |
  495. S5P_CIWDOFST_VEROFF(f->offs_v);
  496. writel(cfg, fimc->regs + S5P_CIWDOFST);
  497. /* See CIWDOFSTn register description in the datasheet for details. */
  498. hoff2 = f->o_width - f->width - f->offs_h;
  499. voff2 = f->o_height - f->height - f->offs_v;
  500. cfg = S5P_CIWDOFST2_HOROFF(hoff2) | S5P_CIWDOFST2_VEROFF(voff2);
  501. writel(cfg, fimc->regs + S5P_CIWDOFST2);
  502. return 0;
  503. }
  504. int fimc_hw_set_camera_type(struct fimc_dev *fimc,
  505. struct s3c_fimc_isp_info *cam)
  506. {
  507. u32 cfg, tmp;
  508. struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
  509. cfg = readl(fimc->regs + S5P_CIGCTRL);
  510. /* Select ITU B interface, disable Writeback path and test pattern. */
  511. cfg &= ~(S5P_CIGCTRL_TESTPAT_MASK | S5P_CIGCTRL_SELCAM_ITU_A |
  512. S5P_CIGCTRL_SELCAM_MIPI | S5P_CIGCTRL_CAMIF_SELWB |
  513. S5P_CIGCTRL_SELCAM_MIPI_A);
  514. if (cam->bus_type == FIMC_MIPI_CSI2) {
  515. cfg |= S5P_CIGCTRL_SELCAM_MIPI;
  516. if (cam->mux_id == 0)
  517. cfg |= S5P_CIGCTRL_SELCAM_MIPI_A;
  518. /* TODO: add remaining supported formats. */
  519. if (vid_cap->fmt.code == V4L2_MBUS_FMT_VYUY8_2X8) {
  520. tmp = S5P_CSIIMGFMT_YCBCR422_8BIT;
  521. } else {
  522. err("camera image format not supported: %d",
  523. vid_cap->fmt.code);
  524. return -EINVAL;
  525. }
  526. writel(tmp | (0x1 << 8), fimc->regs + S5P_CSIIMGFMT);
  527. } else if (cam->bus_type == FIMC_ITU_601 ||
  528. cam->bus_type == FIMC_ITU_656) {
  529. if (cam->mux_id == 0) /* ITU-A, ITU-B: 0, 1 */
  530. cfg |= S5P_CIGCTRL_SELCAM_ITU_A;
  531. } else if (cam->bus_type == FIMC_LCD_WB) {
  532. cfg |= S5P_CIGCTRL_CAMIF_SELWB;
  533. } else {
  534. err("invalid camera bus type selected\n");
  535. return -EINVAL;
  536. }
  537. writel(cfg, fimc->regs + S5P_CIGCTRL);
  538. return 0;
  539. }