fimc-reg.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  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_RGB444...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. struct fimc_fmt *fmt = frame->fmt;
  146. /* Set the input dma offsets. */
  147. cfg = 0;
  148. cfg |= S5P_CIO_OFFS_HOR(offset->y_h);
  149. cfg |= S5P_CIO_OFFS_VER(offset->y_v);
  150. writel(cfg, dev->regs + S5P_CIOYOFF);
  151. cfg = 0;
  152. cfg |= S5P_CIO_OFFS_HOR(offset->cb_h);
  153. cfg |= S5P_CIO_OFFS_VER(offset->cb_v);
  154. writel(cfg, dev->regs + S5P_CIOCBOFF);
  155. cfg = 0;
  156. cfg |= S5P_CIO_OFFS_HOR(offset->cr_h);
  157. cfg |= S5P_CIO_OFFS_VER(offset->cr_v);
  158. writel(cfg, dev->regs + S5P_CIOCROFF);
  159. fimc_hw_set_out_dma_size(ctx);
  160. /* Configure chroma components order. */
  161. cfg = readl(dev->regs + S5P_CIOCTRL);
  162. cfg &= ~(S5P_CIOCTRL_ORDER2P_MASK | S5P_CIOCTRL_ORDER422_MASK |
  163. S5P_CIOCTRL_YCBCR_PLANE_MASK | S5P_CIOCTRL_RGB16FMT_MASK);
  164. if (fmt->colplanes == 1)
  165. cfg |= ctx->out_order_1p;
  166. else if (fmt->colplanes == 2)
  167. cfg |= ctx->out_order_2p | S5P_CIOCTRL_YCBCR_2PLANE;
  168. else if (fmt->colplanes == 3)
  169. cfg |= S5P_CIOCTRL_YCBCR_3PLANE;
  170. if (fmt->color == S5P_FIMC_RGB565)
  171. cfg |= S5P_CIOCTRL_RGB565;
  172. else if (fmt->color == S5P_FIMC_RGB555)
  173. cfg |= S5P_CIOCTRL_ARGB1555;
  174. else if (fmt->color == S5P_FIMC_RGB444)
  175. cfg |= S5P_CIOCTRL_ARGB4444;
  176. writel(cfg, dev->regs + S5P_CIOCTRL);
  177. }
  178. static void fimc_hw_en_autoload(struct fimc_dev *dev, int enable)
  179. {
  180. u32 cfg = readl(dev->regs + S5P_ORGISIZE);
  181. if (enable)
  182. cfg |= S5P_CIREAL_ISIZE_AUTOLOAD_EN;
  183. else
  184. cfg &= ~S5P_CIREAL_ISIZE_AUTOLOAD_EN;
  185. writel(cfg, dev->regs + S5P_ORGISIZE);
  186. }
  187. void fimc_hw_en_lastirq(struct fimc_dev *dev, int enable)
  188. {
  189. u32 cfg = readl(dev->regs + S5P_CIOCTRL);
  190. if (enable)
  191. cfg |= S5P_CIOCTRL_LASTIRQ_ENABLE;
  192. else
  193. cfg &= ~S5P_CIOCTRL_LASTIRQ_ENABLE;
  194. writel(cfg, dev->regs + S5P_CIOCTRL);
  195. }
  196. void fimc_hw_set_prescaler(struct fimc_ctx *ctx)
  197. {
  198. struct fimc_dev *dev = ctx->fimc_dev;
  199. struct fimc_scaler *sc = &ctx->scaler;
  200. u32 cfg, shfactor;
  201. shfactor = 10 - (sc->hfactor + sc->vfactor);
  202. cfg = S5P_CISCPRERATIO_SHFACTOR(shfactor);
  203. cfg |= S5P_CISCPRERATIO_HOR(sc->pre_hratio);
  204. cfg |= S5P_CISCPRERATIO_VER(sc->pre_vratio);
  205. writel(cfg, dev->regs + S5P_CISCPRERATIO);
  206. cfg = S5P_CISCPREDST_WIDTH(sc->pre_dst_width);
  207. cfg |= S5P_CISCPREDST_HEIGHT(sc->pre_dst_height);
  208. writel(cfg, dev->regs + S5P_CISCPREDST);
  209. }
  210. static void fimc_hw_set_scaler(struct fimc_ctx *ctx)
  211. {
  212. struct fimc_dev *dev = ctx->fimc_dev;
  213. struct fimc_scaler *sc = &ctx->scaler;
  214. struct fimc_frame *src_frame = &ctx->s_frame;
  215. struct fimc_frame *dst_frame = &ctx->d_frame;
  216. u32 cfg = readl(dev->regs + S5P_CISCCTRL);
  217. cfg &= ~(S5P_CISCCTRL_CSCR2Y_WIDE | S5P_CISCCTRL_CSCY2R_WIDE |
  218. S5P_CISCCTRL_SCALEUP_H | S5P_CISCCTRL_SCALEUP_V |
  219. S5P_CISCCTRL_SCALERBYPASS | S5P_CISCCTRL_ONE2ONE |
  220. S5P_CISCCTRL_INRGB_FMT_MASK | S5P_CISCCTRL_OUTRGB_FMT_MASK |
  221. S5P_CISCCTRL_INTERLACE | S5P_CISCCTRL_RGB_EXT);
  222. if (!(ctx->flags & FIMC_COLOR_RANGE_NARROW))
  223. cfg |= (S5P_CISCCTRL_CSCR2Y_WIDE | S5P_CISCCTRL_CSCY2R_WIDE);
  224. if (!sc->enabled)
  225. cfg |= S5P_CISCCTRL_SCALERBYPASS;
  226. if (sc->scaleup_h)
  227. cfg |= S5P_CISCCTRL_SCALEUP_H;
  228. if (sc->scaleup_v)
  229. cfg |= S5P_CISCCTRL_SCALEUP_V;
  230. if (sc->copy_mode)
  231. cfg |= S5P_CISCCTRL_ONE2ONE;
  232. if (ctx->in_path == FIMC_DMA) {
  233. switch (src_frame->fmt->color) {
  234. case S5P_FIMC_RGB565:
  235. cfg |= S5P_CISCCTRL_INRGB_FMT_RGB565;
  236. break;
  237. case S5P_FIMC_RGB666:
  238. cfg |= S5P_CISCCTRL_INRGB_FMT_RGB666;
  239. break;
  240. case S5P_FIMC_RGB888:
  241. cfg |= S5P_CISCCTRL_INRGB_FMT_RGB888;
  242. break;
  243. }
  244. }
  245. if (ctx->out_path == FIMC_DMA) {
  246. u32 color = dst_frame->fmt->color;
  247. if (color >= S5P_FIMC_RGB444 && color <= S5P_FIMC_RGB565)
  248. cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB565;
  249. else if (color == S5P_FIMC_RGB666)
  250. cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB666;
  251. else if (color == S5P_FIMC_RGB888)
  252. cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888;
  253. } else {
  254. cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888;
  255. if (ctx->flags & FIMC_SCAN_MODE_INTERLACED)
  256. cfg |= S5P_CISCCTRL_INTERLACE;
  257. }
  258. writel(cfg, dev->regs + S5P_CISCCTRL);
  259. }
  260. void fimc_hw_set_mainscaler(struct fimc_ctx *ctx)
  261. {
  262. struct fimc_dev *dev = ctx->fimc_dev;
  263. struct samsung_fimc_variant *variant = dev->variant;
  264. struct fimc_scaler *sc = &ctx->scaler;
  265. u32 cfg;
  266. dbg("main_hratio= 0x%X main_vratio= 0x%X",
  267. sc->main_hratio, sc->main_vratio);
  268. fimc_hw_set_scaler(ctx);
  269. cfg = readl(dev->regs + S5P_CISCCTRL);
  270. cfg &= ~(S5P_CISCCTRL_MHRATIO_MASK | S5P_CISCCTRL_MVRATIO_MASK);
  271. if (variant->has_mainscaler_ext) {
  272. cfg |= S5P_CISCCTRL_MHRATIO_EXT(sc->main_hratio);
  273. cfg |= S5P_CISCCTRL_MVRATIO_EXT(sc->main_vratio);
  274. writel(cfg, dev->regs + S5P_CISCCTRL);
  275. cfg = readl(dev->regs + S5P_CIEXTEN);
  276. cfg &= ~(S5P_CIEXTEN_MVRATIO_EXT_MASK |
  277. S5P_CIEXTEN_MHRATIO_EXT_MASK);
  278. cfg |= S5P_CIEXTEN_MHRATIO_EXT(sc->main_hratio);
  279. cfg |= S5P_CIEXTEN_MVRATIO_EXT(sc->main_vratio);
  280. writel(cfg, dev->regs + S5P_CIEXTEN);
  281. } else {
  282. cfg |= S5P_CISCCTRL_MHRATIO(sc->main_hratio);
  283. cfg |= S5P_CISCCTRL_MVRATIO(sc->main_vratio);
  284. writel(cfg, dev->regs + S5P_CISCCTRL);
  285. }
  286. }
  287. void fimc_hw_en_capture(struct fimc_ctx *ctx)
  288. {
  289. struct fimc_dev *dev = ctx->fimc_dev;
  290. u32 cfg = readl(dev->regs + S5P_CIIMGCPT);
  291. if (ctx->out_path == FIMC_DMA) {
  292. /* one shot mode */
  293. cfg |= S5P_CIIMGCPT_CPT_FREN_ENABLE | S5P_CIIMGCPT_IMGCPTEN;
  294. } else {
  295. /* Continuous frame capture mode (freerun). */
  296. cfg &= ~(S5P_CIIMGCPT_CPT_FREN_ENABLE |
  297. S5P_CIIMGCPT_CPT_FRMOD_CNT);
  298. cfg |= S5P_CIIMGCPT_IMGCPTEN;
  299. }
  300. if (ctx->scaler.enabled)
  301. cfg |= S5P_CIIMGCPT_IMGCPTEN_SC;
  302. writel(cfg | S5P_CIIMGCPT_IMGCPTEN, dev->regs + S5P_CIIMGCPT);
  303. }
  304. void fimc_hw_set_effect(struct fimc_ctx *ctx, bool active)
  305. {
  306. struct fimc_dev *dev = ctx->fimc_dev;
  307. struct fimc_effect *effect = &ctx->effect;
  308. u32 cfg = 0;
  309. if (active) {
  310. cfg |= S5P_CIIMGEFF_IE_SC_AFTER | S5P_CIIMGEFF_IE_ENABLE;
  311. cfg |= effect->type;
  312. if (effect->type == S5P_FIMC_EFFECT_ARBITRARY) {
  313. cfg |= S5P_CIIMGEFF_PAT_CB(effect->pat_cb);
  314. cfg |= S5P_CIIMGEFF_PAT_CR(effect->pat_cr);
  315. }
  316. }
  317. writel(cfg, dev->regs + S5P_CIIMGEFF);
  318. }
  319. void fimc_hw_set_rgb_alpha(struct fimc_ctx *ctx)
  320. {
  321. struct fimc_dev *dev = ctx->fimc_dev;
  322. struct fimc_frame *frame = &ctx->d_frame;
  323. u32 cfg;
  324. if (!(frame->fmt->flags & FMT_HAS_ALPHA))
  325. return;
  326. cfg = readl(dev->regs + S5P_CIOCTRL);
  327. cfg &= ~S5P_CIOCTRL_ALPHA_OUT_MASK;
  328. cfg |= (frame->alpha << 4);
  329. writel(cfg, dev->regs + S5P_CIOCTRL);
  330. }
  331. static void fimc_hw_set_in_dma_size(struct fimc_ctx *ctx)
  332. {
  333. struct fimc_dev *dev = ctx->fimc_dev;
  334. struct fimc_frame *frame = &ctx->s_frame;
  335. u32 cfg_o = 0;
  336. u32 cfg_r = 0;
  337. if (FIMC_LCDFIFO == ctx->out_path)
  338. cfg_r |= S5P_CIREAL_ISIZE_AUTOLOAD_EN;
  339. cfg_o |= S5P_ORIG_SIZE_HOR(frame->f_width);
  340. cfg_o |= S5P_ORIG_SIZE_VER(frame->f_height);
  341. cfg_r |= S5P_CIREAL_ISIZE_WIDTH(frame->width);
  342. cfg_r |= S5P_CIREAL_ISIZE_HEIGHT(frame->height);
  343. writel(cfg_o, dev->regs + S5P_ORGISIZE);
  344. writel(cfg_r, dev->regs + S5P_CIREAL_ISIZE);
  345. }
  346. void fimc_hw_set_in_dma(struct fimc_ctx *ctx)
  347. {
  348. struct fimc_dev *dev = ctx->fimc_dev;
  349. struct fimc_frame *frame = &ctx->s_frame;
  350. struct fimc_dma_offset *offset = &frame->dma_offset;
  351. u32 cfg;
  352. /* Set the pixel offsets. */
  353. cfg = S5P_CIO_OFFS_HOR(offset->y_h);
  354. cfg |= S5P_CIO_OFFS_VER(offset->y_v);
  355. writel(cfg, dev->regs + S5P_CIIYOFF);
  356. cfg = S5P_CIO_OFFS_HOR(offset->cb_h);
  357. cfg |= S5P_CIO_OFFS_VER(offset->cb_v);
  358. writel(cfg, dev->regs + S5P_CIICBOFF);
  359. cfg = S5P_CIO_OFFS_HOR(offset->cr_h);
  360. cfg |= S5P_CIO_OFFS_VER(offset->cr_v);
  361. writel(cfg, dev->regs + S5P_CIICROFF);
  362. /* Input original and real size. */
  363. fimc_hw_set_in_dma_size(ctx);
  364. /* Use DMA autoload only in FIFO mode. */
  365. fimc_hw_en_autoload(dev, ctx->out_path == FIMC_LCDFIFO);
  366. /* Set the input DMA to process single frame only. */
  367. cfg = readl(dev->regs + S5P_MSCTRL);
  368. cfg &= ~(S5P_MSCTRL_INFORMAT_MASK
  369. | S5P_MSCTRL_IN_BURST_COUNT_MASK
  370. | S5P_MSCTRL_INPUT_MASK
  371. | S5P_MSCTRL_C_INT_IN_MASK
  372. | S5P_MSCTRL_2P_IN_ORDER_MASK);
  373. cfg |= (S5P_MSCTRL_IN_BURST_COUNT(4)
  374. | S5P_MSCTRL_INPUT_MEMORY
  375. | S5P_MSCTRL_FIFO_CTRL_FULL);
  376. switch (frame->fmt->color) {
  377. case S5P_FIMC_RGB565...S5P_FIMC_RGB888:
  378. cfg |= S5P_MSCTRL_INFORMAT_RGB;
  379. break;
  380. case S5P_FIMC_YCBCR420:
  381. cfg |= S5P_MSCTRL_INFORMAT_YCBCR420;
  382. if (frame->fmt->colplanes == 2)
  383. cfg |= ctx->in_order_2p | S5P_MSCTRL_C_INT_IN_2PLANE;
  384. else
  385. cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
  386. break;
  387. case S5P_FIMC_YCBYCR422...S5P_FIMC_CRYCBY422:
  388. if (frame->fmt->colplanes == 1) {
  389. cfg |= ctx->in_order_1p
  390. | S5P_MSCTRL_INFORMAT_YCBCR422_1P;
  391. } else {
  392. cfg |= S5P_MSCTRL_INFORMAT_YCBCR422;
  393. if (frame->fmt->colplanes == 2)
  394. cfg |= ctx->in_order_2p
  395. | S5P_MSCTRL_C_INT_IN_2PLANE;
  396. else
  397. cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
  398. }
  399. break;
  400. default:
  401. break;
  402. }
  403. writel(cfg, dev->regs + S5P_MSCTRL);
  404. /* Input/output DMA linear/tiled mode. */
  405. cfg = readl(dev->regs + S5P_CIDMAPARAM);
  406. cfg &= ~S5P_CIDMAPARAM_TILE_MASK;
  407. if (tiled_fmt(ctx->s_frame.fmt))
  408. cfg |= S5P_CIDMAPARAM_R_64X32;
  409. if (tiled_fmt(ctx->d_frame.fmt))
  410. cfg |= S5P_CIDMAPARAM_W_64X32;
  411. writel(cfg, dev->regs + S5P_CIDMAPARAM);
  412. }
  413. void fimc_hw_set_input_path(struct fimc_ctx *ctx)
  414. {
  415. struct fimc_dev *dev = ctx->fimc_dev;
  416. u32 cfg = readl(dev->regs + S5P_MSCTRL);
  417. cfg &= ~S5P_MSCTRL_INPUT_MASK;
  418. if (ctx->in_path == FIMC_DMA)
  419. cfg |= S5P_MSCTRL_INPUT_MEMORY;
  420. else
  421. cfg |= S5P_MSCTRL_INPUT_EXTCAM;
  422. writel(cfg, dev->regs + S5P_MSCTRL);
  423. }
  424. void fimc_hw_set_output_path(struct fimc_ctx *ctx)
  425. {
  426. struct fimc_dev *dev = ctx->fimc_dev;
  427. u32 cfg = readl(dev->regs + S5P_CISCCTRL);
  428. cfg &= ~S5P_CISCCTRL_LCDPATHEN_FIFO;
  429. if (ctx->out_path == FIMC_LCDFIFO)
  430. cfg |= S5P_CISCCTRL_LCDPATHEN_FIFO;
  431. writel(cfg, dev->regs + S5P_CISCCTRL);
  432. }
  433. void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *paddr)
  434. {
  435. u32 cfg = readl(dev->regs + S5P_CIREAL_ISIZE);
  436. cfg |= S5P_CIREAL_ISIZE_ADDR_CH_DIS;
  437. writel(cfg, dev->regs + S5P_CIREAL_ISIZE);
  438. writel(paddr->y, dev->regs + S5P_CIIYSA(0));
  439. writel(paddr->cb, dev->regs + S5P_CIICBSA(0));
  440. writel(paddr->cr, dev->regs + S5P_CIICRSA(0));
  441. cfg &= ~S5P_CIREAL_ISIZE_ADDR_CH_DIS;
  442. writel(cfg, dev->regs + S5P_CIREAL_ISIZE);
  443. }
  444. void fimc_hw_set_output_addr(struct fimc_dev *dev,
  445. struct fimc_addr *paddr, int index)
  446. {
  447. int i = (index == -1) ? 0 : index;
  448. do {
  449. writel(paddr->y, dev->regs + S5P_CIOYSA(i));
  450. writel(paddr->cb, dev->regs + S5P_CIOCBSA(i));
  451. writel(paddr->cr, dev->regs + S5P_CIOCRSA(i));
  452. dbg("dst_buf[%d]: 0x%X, cb: 0x%X, cr: 0x%X",
  453. i, paddr->y, paddr->cb, paddr->cr);
  454. } while (index == -1 && ++i < FIMC_MAX_OUT_BUFS);
  455. }
  456. int fimc_hw_set_camera_polarity(struct fimc_dev *fimc,
  457. struct s5p_fimc_isp_info *cam)
  458. {
  459. u32 cfg = readl(fimc->regs + S5P_CIGCTRL);
  460. cfg &= ~(S5P_CIGCTRL_INVPOLPCLK | S5P_CIGCTRL_INVPOLVSYNC |
  461. S5P_CIGCTRL_INVPOLHREF | S5P_CIGCTRL_INVPOLHSYNC |
  462. S5P_CIGCTRL_INVPOLFIELD);
  463. if (cam->flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
  464. cfg |= S5P_CIGCTRL_INVPOLPCLK;
  465. if (cam->flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
  466. cfg |= S5P_CIGCTRL_INVPOLVSYNC;
  467. if (cam->flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
  468. cfg |= S5P_CIGCTRL_INVPOLHREF;
  469. if (cam->flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
  470. cfg |= S5P_CIGCTRL_INVPOLHSYNC;
  471. if (cam->flags & V4L2_MBUS_FIELD_EVEN_LOW)
  472. cfg |= S5P_CIGCTRL_INVPOLFIELD;
  473. writel(cfg, fimc->regs + S5P_CIGCTRL);
  474. return 0;
  475. }
  476. int fimc_hw_set_camera_source(struct fimc_dev *fimc,
  477. struct s5p_fimc_isp_info *cam)
  478. {
  479. struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame;
  480. u32 cfg = 0;
  481. u32 bus_width;
  482. int i;
  483. static const struct {
  484. u32 pixelcode;
  485. u32 cisrcfmt;
  486. u16 bus_width;
  487. } pix_desc[] = {
  488. { V4L2_MBUS_FMT_YUYV8_2X8, S5P_CISRCFMT_ORDER422_YCBYCR, 8 },
  489. { V4L2_MBUS_FMT_YVYU8_2X8, S5P_CISRCFMT_ORDER422_YCRYCB, 8 },
  490. { V4L2_MBUS_FMT_VYUY8_2X8, S5P_CISRCFMT_ORDER422_CRYCBY, 8 },
  491. { V4L2_MBUS_FMT_UYVY8_2X8, S5P_CISRCFMT_ORDER422_CBYCRY, 8 },
  492. /* TODO: Add pixel codes for 16-bit bus width */
  493. };
  494. if (cam->bus_type == FIMC_ITU_601 || cam->bus_type == FIMC_ITU_656) {
  495. for (i = 0; i < ARRAY_SIZE(pix_desc); i++) {
  496. if (fimc->vid_cap.mf.code == pix_desc[i].pixelcode) {
  497. cfg = pix_desc[i].cisrcfmt;
  498. bus_width = pix_desc[i].bus_width;
  499. break;
  500. }
  501. }
  502. if (i == ARRAY_SIZE(pix_desc)) {
  503. v4l2_err(fimc->vid_cap.vfd,
  504. "Camera color format not supported: %d\n",
  505. fimc->vid_cap.mf.code);
  506. return -EINVAL;
  507. }
  508. if (cam->bus_type == FIMC_ITU_601) {
  509. if (bus_width == 8)
  510. cfg |= S5P_CISRCFMT_ITU601_8BIT;
  511. else if (bus_width == 16)
  512. cfg |= S5P_CISRCFMT_ITU601_16BIT;
  513. } /* else defaults to ITU-R BT.656 8-bit */
  514. } else if (cam->bus_type == FIMC_MIPI_CSI2) {
  515. if (fimc_fmt_is_jpeg(f->fmt->color))
  516. cfg |= S5P_CISRCFMT_ITU601_8BIT;
  517. }
  518. cfg |= S5P_CISRCFMT_HSIZE(f->o_width) | S5P_CISRCFMT_VSIZE(f->o_height);
  519. writel(cfg, fimc->regs + S5P_CISRCFMT);
  520. return 0;
  521. }
  522. int fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f)
  523. {
  524. u32 hoff2, voff2;
  525. u32 cfg = readl(fimc->regs + S5P_CIWDOFST);
  526. cfg &= ~(S5P_CIWDOFST_HOROFF_MASK | S5P_CIWDOFST_VEROFF_MASK);
  527. cfg |= S5P_CIWDOFST_OFF_EN |
  528. S5P_CIWDOFST_HOROFF(f->offs_h) |
  529. S5P_CIWDOFST_VEROFF(f->offs_v);
  530. writel(cfg, fimc->regs + S5P_CIWDOFST);
  531. /* See CIWDOFSTn register description in the datasheet for details. */
  532. hoff2 = f->o_width - f->width - f->offs_h;
  533. voff2 = f->o_height - f->height - f->offs_v;
  534. cfg = S5P_CIWDOFST2_HOROFF(hoff2) | S5P_CIWDOFST2_VEROFF(voff2);
  535. writel(cfg, fimc->regs + S5P_CIWDOFST2);
  536. return 0;
  537. }
  538. int fimc_hw_set_camera_type(struct fimc_dev *fimc,
  539. struct s5p_fimc_isp_info *cam)
  540. {
  541. u32 cfg, tmp;
  542. struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
  543. cfg = readl(fimc->regs + S5P_CIGCTRL);
  544. /* Select ITU B interface, disable Writeback path and test pattern. */
  545. cfg &= ~(S5P_CIGCTRL_TESTPAT_MASK | S5P_CIGCTRL_SELCAM_ITU_A |
  546. S5P_CIGCTRL_SELCAM_MIPI | S5P_CIGCTRL_CAMIF_SELWB |
  547. S5P_CIGCTRL_SELCAM_MIPI_A | S5P_CIGCTRL_CAM_JPEG);
  548. if (cam->bus_type == FIMC_MIPI_CSI2) {
  549. cfg |= S5P_CIGCTRL_SELCAM_MIPI;
  550. if (cam->mux_id == 0)
  551. cfg |= S5P_CIGCTRL_SELCAM_MIPI_A;
  552. /* TODO: add remaining supported formats. */
  553. switch (vid_cap->mf.code) {
  554. case V4L2_MBUS_FMT_VYUY8_2X8:
  555. tmp = S5P_CSIIMGFMT_YCBCR422_8BIT;
  556. break;
  557. case V4L2_MBUS_FMT_JPEG_1X8:
  558. tmp = S5P_CSIIMGFMT_USER(1);
  559. cfg |= S5P_CIGCTRL_CAM_JPEG;
  560. break;
  561. default:
  562. v4l2_err(fimc->vid_cap.vfd,
  563. "Not supported camera pixel format: %d",
  564. vid_cap->mf.code);
  565. return -EINVAL;
  566. }
  567. tmp |= (cam->csi_data_align == 32) << 8;
  568. writel(tmp, fimc->regs + S5P_CSIIMGFMT);
  569. } else if (cam->bus_type == FIMC_ITU_601 ||
  570. cam->bus_type == FIMC_ITU_656) {
  571. if (cam->mux_id == 0) /* ITU-A, ITU-B: 0, 1 */
  572. cfg |= S5P_CIGCTRL_SELCAM_ITU_A;
  573. } else if (cam->bus_type == FIMC_LCD_WB) {
  574. cfg |= S5P_CIGCTRL_CAMIF_SELWB;
  575. } else {
  576. err("invalid camera bus type selected\n");
  577. return -EINVAL;
  578. }
  579. writel(cfg, fimc->regs + S5P_CIGCTRL);
  580. return 0;
  581. }