fimc-reg.c 18 KB

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