gsc-regs.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. writel(cfg, dev->regs + GSC_IN_CON);
  182. }
  183. void gsc_hw_set_output_path(struct gsc_ctx *ctx)
  184. {
  185. struct gsc_dev *dev = ctx->gsc_dev;
  186. u32 cfg = readl(dev->regs + GSC_OUT_CON);
  187. cfg &= ~GSC_OUT_PATH_MASK;
  188. if (ctx->out_path == GSC_DMA)
  189. cfg |= GSC_OUT_PATH_MEMORY;
  190. else
  191. cfg |= GSC_OUT_PATH_LOCAL;
  192. writel(cfg, dev->regs + GSC_OUT_CON);
  193. }
  194. void gsc_hw_set_out_size(struct gsc_ctx *ctx)
  195. {
  196. struct gsc_dev *dev = ctx->gsc_dev;
  197. struct gsc_frame *frame = &ctx->d_frame;
  198. u32 cfg;
  199. /* Set output original size */
  200. if (ctx->out_path == GSC_DMA) {
  201. cfg = GSC_DSTIMG_OFFSET_X(frame->crop.left);
  202. cfg |= GSC_DSTIMG_OFFSET_Y(frame->crop.top);
  203. writel(cfg, dev->regs + GSC_DSTIMG_OFFSET);
  204. cfg = GSC_DSTIMG_WIDTH(frame->f_width);
  205. cfg |= GSC_DSTIMG_HEIGHT(frame->f_height);
  206. writel(cfg, dev->regs + GSC_DSTIMG_SIZE);
  207. }
  208. /* Set output scaled size */
  209. if (ctx->gsc_ctrls.rotate->val == 90 ||
  210. ctx->gsc_ctrls.rotate->val == 270) {
  211. cfg = GSC_SCALED_WIDTH(frame->crop.height);
  212. cfg |= GSC_SCALED_HEIGHT(frame->crop.width);
  213. } else {
  214. cfg = GSC_SCALED_WIDTH(frame->crop.width);
  215. cfg |= GSC_SCALED_HEIGHT(frame->crop.height);
  216. }
  217. writel(cfg, dev->regs + GSC_SCALED_SIZE);
  218. }
  219. void gsc_hw_set_out_image_rgb(struct gsc_ctx *ctx)
  220. {
  221. struct gsc_dev *dev = ctx->gsc_dev;
  222. struct gsc_frame *frame = &ctx->d_frame;
  223. u32 cfg;
  224. cfg = readl(dev->regs + GSC_OUT_CON);
  225. if (frame->colorspace == V4L2_COLORSPACE_REC709)
  226. cfg |= GSC_OUT_RGB_HD_WIDE;
  227. else
  228. cfg |= GSC_OUT_RGB_SD_WIDE;
  229. if (frame->fmt->pixelformat == V4L2_PIX_FMT_RGB565X)
  230. cfg |= GSC_OUT_RGB565;
  231. else if (frame->fmt->pixelformat == V4L2_PIX_FMT_RGB32)
  232. cfg |= GSC_OUT_XRGB8888;
  233. writel(cfg, dev->regs + GSC_OUT_CON);
  234. }
  235. void gsc_hw_set_out_image_format(struct gsc_ctx *ctx)
  236. {
  237. struct gsc_dev *dev = ctx->gsc_dev;
  238. struct gsc_frame *frame = &ctx->d_frame;
  239. u32 i, depth = 0;
  240. u32 cfg;
  241. cfg = readl(dev->regs + GSC_OUT_CON);
  242. cfg &= ~(GSC_OUT_RGB_TYPE_MASK | GSC_OUT_YUV422_1P_ORDER_MASK |
  243. GSC_OUT_CHROMA_ORDER_MASK | GSC_OUT_FORMAT_MASK |
  244. GSC_OUT_TILE_TYPE_MASK | GSC_OUT_TILE_MODE);
  245. writel(cfg, dev->regs + GSC_OUT_CON);
  246. if (is_rgb(frame->fmt->color)) {
  247. gsc_hw_set_out_image_rgb(ctx);
  248. return;
  249. }
  250. if (ctx->out_path != GSC_DMA) {
  251. cfg |= GSC_OUT_YUV444;
  252. goto end_set;
  253. }
  254. for (i = 0; i < frame->fmt->num_planes; i++)
  255. depth += frame->fmt->depth[i];
  256. switch (frame->fmt->num_comp) {
  257. case 1:
  258. cfg |= GSC_OUT_YUV422_1P;
  259. if (frame->fmt->yorder == GSC_LSB_Y)
  260. cfg |= GSC_OUT_YUV422_1P_ORDER_LSB_Y;
  261. else
  262. cfg |= GSC_OUT_YUV422_1P_OEDER_LSB_C;
  263. if (frame->fmt->corder == GSC_CBCR)
  264. cfg |= GSC_OUT_CHROMA_ORDER_CBCR;
  265. else
  266. cfg |= GSC_OUT_CHROMA_ORDER_CRCB;
  267. break;
  268. case 2:
  269. if (depth == 12)
  270. cfg |= GSC_OUT_YUV420_2P;
  271. else
  272. cfg |= GSC_OUT_YUV422_2P;
  273. if (frame->fmt->corder == GSC_CBCR)
  274. cfg |= GSC_OUT_CHROMA_ORDER_CBCR;
  275. else
  276. cfg |= GSC_OUT_CHROMA_ORDER_CRCB;
  277. break;
  278. case 3:
  279. cfg |= GSC_OUT_YUV420_3P;
  280. break;
  281. }
  282. end_set:
  283. writel(cfg, dev->regs + GSC_OUT_CON);
  284. }
  285. void gsc_hw_set_prescaler(struct gsc_ctx *ctx)
  286. {
  287. struct gsc_dev *dev = ctx->gsc_dev;
  288. struct gsc_scaler *sc = &ctx->scaler;
  289. u32 cfg;
  290. cfg = GSC_PRESC_SHFACTOR(sc->pre_shfactor);
  291. cfg |= GSC_PRESC_H_RATIO(sc->pre_hratio);
  292. cfg |= GSC_PRESC_V_RATIO(sc->pre_vratio);
  293. writel(cfg, dev->regs + GSC_PRE_SCALE_RATIO);
  294. }
  295. void gsc_hw_set_mainscaler(struct gsc_ctx *ctx)
  296. {
  297. struct gsc_dev *dev = ctx->gsc_dev;
  298. struct gsc_scaler *sc = &ctx->scaler;
  299. u32 cfg;
  300. cfg = GSC_MAIN_H_RATIO_VALUE(sc->main_hratio);
  301. writel(cfg, dev->regs + GSC_MAIN_H_RATIO);
  302. cfg = GSC_MAIN_V_RATIO_VALUE(sc->main_vratio);
  303. writel(cfg, dev->regs + GSC_MAIN_V_RATIO);
  304. }
  305. void gsc_hw_set_rotation(struct gsc_ctx *ctx)
  306. {
  307. struct gsc_dev *dev = ctx->gsc_dev;
  308. u32 cfg;
  309. cfg = readl(dev->regs + GSC_IN_CON);
  310. cfg &= ~GSC_IN_ROT_MASK;
  311. switch (ctx->gsc_ctrls.rotate->val) {
  312. case 270:
  313. cfg |= GSC_IN_ROT_270;
  314. break;
  315. case 180:
  316. cfg |= GSC_IN_ROT_180;
  317. break;
  318. case 90:
  319. if (ctx->gsc_ctrls.hflip->val)
  320. cfg |= GSC_IN_ROT_90_XFLIP;
  321. else if (ctx->gsc_ctrls.vflip->val)
  322. cfg |= GSC_IN_ROT_90_YFLIP;
  323. else
  324. cfg |= GSC_IN_ROT_90;
  325. break;
  326. case 0:
  327. if (ctx->gsc_ctrls.hflip->val)
  328. cfg |= GSC_IN_ROT_XFLIP;
  329. else if (ctx->gsc_ctrls.vflip->val)
  330. cfg |= GSC_IN_ROT_YFLIP;
  331. }
  332. writel(cfg, dev->regs + GSC_IN_CON);
  333. }
  334. void gsc_hw_set_global_alpha(struct gsc_ctx *ctx)
  335. {
  336. struct gsc_dev *dev = ctx->gsc_dev;
  337. struct gsc_frame *frame = &ctx->d_frame;
  338. u32 cfg;
  339. if (!is_rgb(frame->fmt->color)) {
  340. pr_debug("Not a RGB format");
  341. return;
  342. }
  343. cfg = readl(dev->regs + GSC_OUT_CON);
  344. cfg &= ~GSC_OUT_GLOBAL_ALPHA_MASK;
  345. cfg |= GSC_OUT_GLOBAL_ALPHA(ctx->gsc_ctrls.global_alpha->val);
  346. writel(cfg, dev->regs + GSC_OUT_CON);
  347. }
  348. void gsc_hw_set_sfr_update(struct gsc_ctx *ctx)
  349. {
  350. struct gsc_dev *dev = ctx->gsc_dev;
  351. u32 cfg;
  352. cfg = readl(dev->regs + GSC_ENABLE);
  353. cfg |= GSC_ENABLE_SFR_UPDATE;
  354. writel(cfg, dev->regs + GSC_ENABLE);
  355. }