fimc-reg.c 18 KB

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