fimc-reg.c 17 KB

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