gsc-regs.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /*
  2. * Copyright (c) 2011 - 2012 Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com
  4. *
  5. * Samsung EXYNOS5 SoC series G-Scaler driver
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published
  9. * by the Free Software Foundation, either version 2 of the License,
  10. * or (at your option) any later version.
  11. */
  12. #include <linux/io.h>
  13. #include <linux/delay.h>
  14. #include <mach/map.h>
  15. #include "gsc-core.h"
  16. void gsc_hw_set_sw_reset(struct gsc_dev *dev)
  17. {
  18. writel(GSC_SW_RESET_SRESET, dev->regs + GSC_SW_RESET);
  19. }
  20. int gsc_wait_reset(struct gsc_dev *dev)
  21. {
  22. unsigned long end = jiffies + msecs_to_jiffies(50);
  23. u32 cfg;
  24. while (time_before(jiffies, end)) {
  25. cfg = readl(dev->regs + GSC_SW_RESET);
  26. if (!cfg)
  27. return 0;
  28. usleep_range(10, 20);
  29. }
  30. return -EBUSY;
  31. }
  32. void gsc_hw_set_frm_done_irq_mask(struct gsc_dev *dev, bool mask)
  33. {
  34. u32 cfg;
  35. cfg = readl(dev->regs + GSC_IRQ);
  36. if (mask)
  37. cfg |= GSC_IRQ_FRMDONE_MASK;
  38. else
  39. cfg &= ~GSC_IRQ_FRMDONE_MASK;
  40. writel(cfg, dev->regs + GSC_IRQ);
  41. }
  42. void gsc_hw_set_gsc_irq_enable(struct gsc_dev *dev, bool mask)
  43. {
  44. u32 cfg;
  45. cfg = readl(dev->regs + GSC_IRQ);
  46. if (mask)
  47. cfg |= GSC_IRQ_ENABLE;
  48. else
  49. cfg &= ~GSC_IRQ_ENABLE;
  50. writel(cfg, dev->regs + GSC_IRQ);
  51. }
  52. void gsc_hw_set_input_buf_masking(struct gsc_dev *dev, u32 shift,
  53. bool enable)
  54. {
  55. u32 cfg = readl(dev->regs + GSC_IN_BASE_ADDR_Y_MASK);
  56. u32 mask = 1 << shift;
  57. cfg &= ~mask;
  58. cfg |= enable << shift;
  59. writel(cfg, dev->regs + GSC_IN_BASE_ADDR_Y_MASK);
  60. writel(cfg, dev->regs + GSC_IN_BASE_ADDR_CB_MASK);
  61. writel(cfg, dev->regs + GSC_IN_BASE_ADDR_CR_MASK);
  62. }
  63. void gsc_hw_set_output_buf_masking(struct gsc_dev *dev, u32 shift,
  64. bool enable)
  65. {
  66. u32 cfg = readl(dev->regs + GSC_OUT_BASE_ADDR_Y_MASK);
  67. u32 mask = 1 << shift;
  68. cfg &= ~mask;
  69. cfg |= enable << shift;
  70. writel(cfg, dev->regs + GSC_OUT_BASE_ADDR_Y_MASK);
  71. writel(cfg, dev->regs + GSC_OUT_BASE_ADDR_CB_MASK);
  72. writel(cfg, dev->regs + GSC_OUT_BASE_ADDR_CR_MASK);
  73. }
  74. void gsc_hw_set_input_addr(struct gsc_dev *dev, struct gsc_addr *addr,
  75. int index)
  76. {
  77. pr_debug("src_buf[%d]: 0x%X, cb: 0x%X, cr: 0x%X", index,
  78. addr->y, addr->cb, addr->cr);
  79. writel(addr->y, dev->regs + GSC_IN_BASE_ADDR_Y(index));
  80. writel(addr->cb, dev->regs + GSC_IN_BASE_ADDR_CB(index));
  81. writel(addr->cr, dev->regs + GSC_IN_BASE_ADDR_CR(index));
  82. }
  83. void gsc_hw_set_output_addr(struct gsc_dev *dev,
  84. struct gsc_addr *addr, int index)
  85. {
  86. pr_debug("dst_buf[%d]: 0x%X, cb: 0x%X, cr: 0x%X",
  87. index, addr->y, addr->cb, addr->cr);
  88. writel(addr->y, dev->regs + GSC_OUT_BASE_ADDR_Y(index));
  89. writel(addr->cb, dev->regs + GSC_OUT_BASE_ADDR_CB(index));
  90. writel(addr->cr, dev->regs + GSC_OUT_BASE_ADDR_CR(index));
  91. }
  92. void gsc_hw_set_input_path(struct gsc_ctx *ctx)
  93. {
  94. struct gsc_dev *dev = ctx->gsc_dev;
  95. u32 cfg = readl(dev->regs + GSC_IN_CON);
  96. cfg &= ~(GSC_IN_PATH_MASK | GSC_IN_LOCAL_SEL_MASK);
  97. if (ctx->in_path == GSC_DMA)
  98. cfg |= GSC_IN_PATH_MEMORY;
  99. writel(cfg, dev->regs + GSC_IN_CON);
  100. }
  101. void gsc_hw_set_in_size(struct gsc_ctx *ctx)
  102. {
  103. struct gsc_dev *dev = ctx->gsc_dev;
  104. struct gsc_frame *frame = &ctx->s_frame;
  105. u32 cfg;
  106. /* Set input pixel offset */
  107. cfg = GSC_SRCIMG_OFFSET_X(frame->crop.left);
  108. cfg |= GSC_SRCIMG_OFFSET_Y(frame->crop.top);
  109. writel(cfg, dev->regs + GSC_SRCIMG_OFFSET);
  110. /* Set input original size */
  111. cfg = GSC_SRCIMG_WIDTH(frame->f_width);
  112. cfg |= GSC_SRCIMG_HEIGHT(frame->f_height);
  113. writel(cfg, dev->regs + GSC_SRCIMG_SIZE);
  114. /* Set input cropped size */
  115. cfg = GSC_CROPPED_WIDTH(frame->crop.width);
  116. cfg |= GSC_CROPPED_HEIGHT(frame->crop.height);
  117. writel(cfg, dev->regs + GSC_CROPPED_SIZE);
  118. }
  119. void gsc_hw_set_in_image_rgb(struct gsc_ctx *ctx)
  120. {
  121. struct gsc_dev *dev = ctx->gsc_dev;
  122. struct gsc_frame *frame = &ctx->s_frame;
  123. u32 cfg;
  124. cfg = readl(dev->regs + GSC_IN_CON);
  125. if (frame->colorspace == V4L2_COLORSPACE_REC709)
  126. cfg |= GSC_IN_RGB_HD_WIDE;
  127. else
  128. cfg |= GSC_IN_RGB_SD_WIDE;
  129. if (frame->fmt->pixelformat == V4L2_PIX_FMT_RGB565X)
  130. cfg |= GSC_IN_RGB565;
  131. else if (frame->fmt->pixelformat == V4L2_PIX_FMT_RGB32)
  132. cfg |= GSC_IN_XRGB8888;
  133. writel(cfg, dev->regs + GSC_IN_CON);
  134. }
  135. void gsc_hw_set_in_image_format(struct gsc_ctx *ctx)
  136. {
  137. struct gsc_dev *dev = ctx->gsc_dev;
  138. struct gsc_frame *frame = &ctx->s_frame;
  139. u32 i, depth = 0;
  140. u32 cfg;
  141. cfg = readl(dev->regs + GSC_IN_CON);
  142. cfg &= ~(GSC_IN_RGB_TYPE_MASK | GSC_IN_YUV422_1P_ORDER_MASK |
  143. GSC_IN_CHROMA_ORDER_MASK | GSC_IN_FORMAT_MASK |
  144. GSC_IN_TILE_TYPE_MASK | GSC_IN_TILE_MODE);
  145. writel(cfg, dev->regs + GSC_IN_CON);
  146. if (is_rgb(frame->fmt->color)) {
  147. gsc_hw_set_in_image_rgb(ctx);
  148. return;
  149. }
  150. for (i = 0; i < frame->fmt->num_planes; i++)
  151. depth += frame->fmt->depth[i];
  152. switch (frame->fmt->num_comp) {
  153. case 1:
  154. cfg |= GSC_IN_YUV422_1P;
  155. if (frame->fmt->yorder == GSC_LSB_Y)
  156. cfg |= GSC_IN_YUV422_1P_ORDER_LSB_Y;
  157. else
  158. cfg |= GSC_IN_YUV422_1P_OEDER_LSB_C;
  159. if (frame->fmt->corder == GSC_CBCR)
  160. cfg |= GSC_IN_CHROMA_ORDER_CBCR;
  161. else
  162. cfg |= GSC_IN_CHROMA_ORDER_CRCB;
  163. break;
  164. case 2:
  165. if (depth == 12)
  166. cfg |= GSC_IN_YUV420_2P;
  167. else
  168. cfg |= GSC_IN_YUV422_2P;
  169. if (frame->fmt->corder == GSC_CBCR)
  170. cfg |= GSC_IN_CHROMA_ORDER_CBCR;
  171. else
  172. cfg |= GSC_IN_CHROMA_ORDER_CRCB;
  173. break;
  174. case 3:
  175. if (depth == 12)
  176. cfg |= GSC_IN_YUV420_3P;
  177. else
  178. cfg |= GSC_IN_YUV422_3P;
  179. break;
  180. }
  181. if (is_tiled(frame->fmt))
  182. cfg |= GSC_IN_TILE_C_16x8 | GSC_IN_TILE_MODE;
  183. writel(cfg, dev->regs + GSC_IN_CON);
  184. }
  185. void gsc_hw_set_output_path(struct gsc_ctx *ctx)
  186. {
  187. struct gsc_dev *dev = ctx->gsc_dev;
  188. u32 cfg = readl(dev->regs + GSC_OUT_CON);
  189. cfg &= ~GSC_OUT_PATH_MASK;
  190. if (ctx->out_path == GSC_DMA)
  191. cfg |= GSC_OUT_PATH_MEMORY;
  192. else
  193. cfg |= GSC_OUT_PATH_LOCAL;
  194. writel(cfg, dev->regs + GSC_OUT_CON);
  195. }
  196. void gsc_hw_set_out_size(struct gsc_ctx *ctx)
  197. {
  198. struct gsc_dev *dev = ctx->gsc_dev;
  199. struct gsc_frame *frame = &ctx->d_frame;
  200. u32 cfg;
  201. /* Set output original size */
  202. if (ctx->out_path == GSC_DMA) {
  203. cfg = GSC_DSTIMG_OFFSET_X(frame->crop.left);
  204. cfg |= GSC_DSTIMG_OFFSET_Y(frame->crop.top);
  205. writel(cfg, dev->regs + GSC_DSTIMG_OFFSET);
  206. cfg = GSC_DSTIMG_WIDTH(frame->f_width);
  207. cfg |= GSC_DSTIMG_HEIGHT(frame->f_height);
  208. writel(cfg, dev->regs + GSC_DSTIMG_SIZE);
  209. }
  210. /* Set output scaled size */
  211. if (ctx->gsc_ctrls.rotate->val == 90 ||
  212. ctx->gsc_ctrls.rotate->val == 270) {
  213. cfg = GSC_SCALED_WIDTH(frame->crop.height);
  214. cfg |= GSC_SCALED_HEIGHT(frame->crop.width);
  215. } else {
  216. cfg = GSC_SCALED_WIDTH(frame->crop.width);
  217. cfg |= GSC_SCALED_HEIGHT(frame->crop.height);
  218. }
  219. writel(cfg, dev->regs + GSC_SCALED_SIZE);
  220. }
  221. void gsc_hw_set_out_image_rgb(struct gsc_ctx *ctx)
  222. {
  223. struct gsc_dev *dev = ctx->gsc_dev;
  224. struct gsc_frame *frame = &ctx->d_frame;
  225. u32 cfg;
  226. cfg = readl(dev->regs + GSC_OUT_CON);
  227. if (frame->colorspace == V4L2_COLORSPACE_REC709)
  228. cfg |= GSC_OUT_RGB_HD_WIDE;
  229. else
  230. cfg |= GSC_OUT_RGB_SD_WIDE;
  231. if (frame->fmt->pixelformat == V4L2_PIX_FMT_RGB565X)
  232. cfg |= GSC_OUT_RGB565;
  233. else if (frame->fmt->pixelformat == V4L2_PIX_FMT_RGB32)
  234. cfg |= GSC_OUT_XRGB8888;
  235. writel(cfg, dev->regs + GSC_OUT_CON);
  236. }
  237. void gsc_hw_set_out_image_format(struct gsc_ctx *ctx)
  238. {
  239. struct gsc_dev *dev = ctx->gsc_dev;
  240. struct gsc_frame *frame = &ctx->d_frame;
  241. u32 i, depth = 0;
  242. u32 cfg;
  243. cfg = readl(dev->regs + GSC_OUT_CON);
  244. cfg &= ~(GSC_OUT_RGB_TYPE_MASK | GSC_OUT_YUV422_1P_ORDER_MASK |
  245. GSC_OUT_CHROMA_ORDER_MASK | GSC_OUT_FORMAT_MASK |
  246. GSC_OUT_TILE_TYPE_MASK | GSC_OUT_TILE_MODE);
  247. writel(cfg, dev->regs + GSC_OUT_CON);
  248. if (is_rgb(frame->fmt->color)) {
  249. gsc_hw_set_out_image_rgb(ctx);
  250. return;
  251. }
  252. if (ctx->out_path != GSC_DMA) {
  253. cfg |= GSC_OUT_YUV444;
  254. goto end_set;
  255. }
  256. for (i = 0; i < frame->fmt->num_planes; i++)
  257. depth += frame->fmt->depth[i];
  258. switch (frame->fmt->num_comp) {
  259. case 1:
  260. cfg |= GSC_OUT_YUV422_1P;
  261. if (frame->fmt->yorder == GSC_LSB_Y)
  262. cfg |= GSC_OUT_YUV422_1P_ORDER_LSB_Y;
  263. else
  264. cfg |= GSC_OUT_YUV422_1P_OEDER_LSB_C;
  265. if (frame->fmt->corder == GSC_CBCR)
  266. cfg |= GSC_OUT_CHROMA_ORDER_CBCR;
  267. else
  268. cfg |= GSC_OUT_CHROMA_ORDER_CRCB;
  269. break;
  270. case 2:
  271. if (depth == 12)
  272. cfg |= GSC_OUT_YUV420_2P;
  273. else
  274. cfg |= GSC_OUT_YUV422_2P;
  275. if (frame->fmt->corder == GSC_CBCR)
  276. cfg |= GSC_OUT_CHROMA_ORDER_CBCR;
  277. else
  278. cfg |= GSC_OUT_CHROMA_ORDER_CRCB;
  279. break;
  280. case 3:
  281. cfg |= GSC_OUT_YUV420_3P;
  282. break;
  283. }
  284. if (is_tiled(frame->fmt))
  285. cfg |= GSC_OUT_TILE_C_16x8 | GSC_OUT_TILE_MODE;
  286. end_set:
  287. writel(cfg, dev->regs + GSC_OUT_CON);
  288. }
  289. void gsc_hw_set_prescaler(struct gsc_ctx *ctx)
  290. {
  291. struct gsc_dev *dev = ctx->gsc_dev;
  292. struct gsc_scaler *sc = &ctx->scaler;
  293. u32 cfg;
  294. cfg = GSC_PRESC_SHFACTOR(sc->pre_shfactor);
  295. cfg |= GSC_PRESC_H_RATIO(sc->pre_hratio);
  296. cfg |= GSC_PRESC_V_RATIO(sc->pre_vratio);
  297. writel(cfg, dev->regs + GSC_PRE_SCALE_RATIO);
  298. }
  299. void gsc_hw_set_mainscaler(struct gsc_ctx *ctx)
  300. {
  301. struct gsc_dev *dev = ctx->gsc_dev;
  302. struct gsc_scaler *sc = &ctx->scaler;
  303. u32 cfg;
  304. cfg = GSC_MAIN_H_RATIO_VALUE(sc->main_hratio);
  305. writel(cfg, dev->regs + GSC_MAIN_H_RATIO);
  306. cfg = GSC_MAIN_V_RATIO_VALUE(sc->main_vratio);
  307. writel(cfg, dev->regs + GSC_MAIN_V_RATIO);
  308. }
  309. void gsc_hw_set_rotation(struct gsc_ctx *ctx)
  310. {
  311. struct gsc_dev *dev = ctx->gsc_dev;
  312. u32 cfg;
  313. cfg = readl(dev->regs + GSC_IN_CON);
  314. cfg &= ~GSC_IN_ROT_MASK;
  315. switch (ctx->gsc_ctrls.rotate->val) {
  316. case 270:
  317. cfg |= GSC_IN_ROT_270;
  318. break;
  319. case 180:
  320. cfg |= GSC_IN_ROT_180;
  321. break;
  322. case 90:
  323. if (ctx->gsc_ctrls.hflip->val)
  324. cfg |= GSC_IN_ROT_90_XFLIP;
  325. else if (ctx->gsc_ctrls.vflip->val)
  326. cfg |= GSC_IN_ROT_90_YFLIP;
  327. else
  328. cfg |= GSC_IN_ROT_90;
  329. break;
  330. case 0:
  331. if (ctx->gsc_ctrls.hflip->val)
  332. cfg |= GSC_IN_ROT_XFLIP;
  333. else if (ctx->gsc_ctrls.vflip->val)
  334. cfg |= GSC_IN_ROT_YFLIP;
  335. }
  336. writel(cfg, dev->regs + GSC_IN_CON);
  337. }
  338. void gsc_hw_set_global_alpha(struct gsc_ctx *ctx)
  339. {
  340. struct gsc_dev *dev = ctx->gsc_dev;
  341. struct gsc_frame *frame = &ctx->d_frame;
  342. u32 cfg;
  343. if (!is_rgb(frame->fmt->color)) {
  344. pr_debug("Not a RGB format");
  345. return;
  346. }
  347. cfg = readl(dev->regs + GSC_OUT_CON);
  348. cfg &= ~GSC_OUT_GLOBAL_ALPHA_MASK;
  349. cfg |= GSC_OUT_GLOBAL_ALPHA(ctx->gsc_ctrls.global_alpha->val);
  350. writel(cfg, dev->regs + GSC_OUT_CON);
  351. }
  352. void gsc_hw_set_sfr_update(struct gsc_ctx *ctx)
  353. {
  354. struct gsc_dev *dev = ctx->gsc_dev;
  355. u32 cfg;
  356. cfg = readl(dev->regs + GSC_ENABLE);
  357. cfg |= GSC_ENABLE_SFR_UPDATE;
  358. writel(cfg, dev->regs + GSC_ENABLE);
  359. }