jpeg-hw-s5p.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /* linux/drivers/media/platform/s5p-jpeg/jpeg-hw.h
  2. *
  3. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com
  5. *
  6. * Author: Andrzej Pietrasiewicz <andrzej.p@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/videodev2.h>
  14. #include "jpeg-core.h"
  15. #include "jpeg-regs.h"
  16. #include "jpeg-hw-s5p.h"
  17. void s5p_jpeg_reset(void __iomem *regs)
  18. {
  19. unsigned long reg;
  20. writel(1, regs + S5P_JPG_SW_RESET);
  21. reg = readl(regs + S5P_JPG_SW_RESET);
  22. /* no other way but polling for when JPEG IP becomes operational */
  23. while (reg != 0) {
  24. cpu_relax();
  25. reg = readl(regs + S5P_JPG_SW_RESET);
  26. }
  27. }
  28. void s5p_jpeg_poweron(void __iomem *regs)
  29. {
  30. writel(S5P_POWER_ON, regs + S5P_JPGCLKCON);
  31. }
  32. void s5p_jpeg_input_raw_mode(void __iomem *regs, unsigned long mode)
  33. {
  34. unsigned long reg, m;
  35. m = S5P_MOD_SEL_565;
  36. if (mode == S5P_JPEG_RAW_IN_565)
  37. m = S5P_MOD_SEL_565;
  38. else if (mode == S5P_JPEG_RAW_IN_422)
  39. m = S5P_MOD_SEL_422;
  40. reg = readl(regs + S5P_JPGCMOD);
  41. reg &= ~S5P_MOD_SEL_MASK;
  42. reg |= m;
  43. writel(reg, regs + S5P_JPGCMOD);
  44. }
  45. void s5p_jpeg_proc_mode(void __iomem *regs, unsigned long mode)
  46. {
  47. unsigned long reg, m;
  48. m = S5P_PROC_MODE_DECOMPR;
  49. if (mode == S5P_JPEG_ENCODE)
  50. m = S5P_PROC_MODE_COMPR;
  51. else
  52. m = S5P_PROC_MODE_DECOMPR;
  53. reg = readl(regs + S5P_JPGMOD);
  54. reg &= ~S5P_PROC_MODE_MASK;
  55. reg |= m;
  56. writel(reg, regs + S5P_JPGMOD);
  57. }
  58. void s5p_jpeg_subsampling_mode(void __iomem *regs, unsigned int mode)
  59. {
  60. unsigned long reg, m;
  61. if (mode == V4L2_JPEG_CHROMA_SUBSAMPLING_420)
  62. m = S5P_SUBSAMPLING_MODE_420;
  63. else
  64. m = S5P_SUBSAMPLING_MODE_422;
  65. reg = readl(regs + S5P_JPGMOD);
  66. reg &= ~S5P_SUBSAMPLING_MODE_MASK;
  67. reg |= m;
  68. writel(reg, regs + S5P_JPGMOD);
  69. }
  70. unsigned int s5p_jpeg_get_subsampling_mode(void __iomem *regs)
  71. {
  72. return readl(regs + S5P_JPGMOD) & S5P_SUBSAMPLING_MODE_MASK;
  73. }
  74. void s5p_jpeg_dri(void __iomem *regs, unsigned int dri)
  75. {
  76. unsigned long reg;
  77. reg = readl(regs + S5P_JPGDRI_U);
  78. reg &= ~0xff;
  79. reg |= (dri >> 8) & 0xff;
  80. writel(reg, regs + S5P_JPGDRI_U);
  81. reg = readl(regs + S5P_JPGDRI_L);
  82. reg &= ~0xff;
  83. reg |= dri & 0xff;
  84. writel(reg, regs + S5P_JPGDRI_L);
  85. }
  86. void s5p_jpeg_qtbl(void __iomem *regs, unsigned int t, unsigned int n)
  87. {
  88. unsigned long reg;
  89. reg = readl(regs + S5P_JPG_QTBL);
  90. reg &= ~S5P_QT_NUMt_MASK(t);
  91. reg |= (n << S5P_QT_NUMt_SHIFT(t)) & S5P_QT_NUMt_MASK(t);
  92. writel(reg, regs + S5P_JPG_QTBL);
  93. }
  94. void s5p_jpeg_htbl_ac(void __iomem *regs, unsigned int t)
  95. {
  96. unsigned long reg;
  97. reg = readl(regs + S5P_JPG_HTBL);
  98. reg &= ~S5P_HT_NUMt_AC_MASK(t);
  99. /* this driver uses table 0 for all color components */
  100. reg |= (0 << S5P_HT_NUMt_AC_SHIFT(t)) & S5P_HT_NUMt_AC_MASK(t);
  101. writel(reg, regs + S5P_JPG_HTBL);
  102. }
  103. void s5p_jpeg_htbl_dc(void __iomem *regs, unsigned int t)
  104. {
  105. unsigned long reg;
  106. reg = readl(regs + S5P_JPG_HTBL);
  107. reg &= ~S5P_HT_NUMt_DC_MASK(t);
  108. /* this driver uses table 0 for all color components */
  109. reg |= (0 << S5P_HT_NUMt_DC_SHIFT(t)) & S5P_HT_NUMt_DC_MASK(t);
  110. writel(reg, regs + S5P_JPG_HTBL);
  111. }
  112. void s5p_jpeg_y(void __iomem *regs, unsigned int y)
  113. {
  114. unsigned long reg;
  115. reg = readl(regs + S5P_JPGY_U);
  116. reg &= ~0xff;
  117. reg |= (y >> 8) & 0xff;
  118. writel(reg, regs + S5P_JPGY_U);
  119. reg = readl(regs + S5P_JPGY_L);
  120. reg &= ~0xff;
  121. reg |= y & 0xff;
  122. writel(reg, regs + S5P_JPGY_L);
  123. }
  124. void s5p_jpeg_x(void __iomem *regs, unsigned int x)
  125. {
  126. unsigned long reg;
  127. reg = readl(regs + S5P_JPGX_U);
  128. reg &= ~0xff;
  129. reg |= (x >> 8) & 0xff;
  130. writel(reg, regs + S5P_JPGX_U);
  131. reg = readl(regs + S5P_JPGX_L);
  132. reg &= ~0xff;
  133. reg |= x & 0xff;
  134. writel(reg, regs + S5P_JPGX_L);
  135. }
  136. void s5p_jpeg_rst_int_enable(void __iomem *regs, bool enable)
  137. {
  138. unsigned long reg;
  139. reg = readl(regs + S5P_JPGINTSE);
  140. reg &= ~S5P_RSTm_INT_EN_MASK;
  141. if (enable)
  142. reg |= S5P_RSTm_INT_EN;
  143. writel(reg, regs + S5P_JPGINTSE);
  144. }
  145. void s5p_jpeg_data_num_int_enable(void __iomem *regs, bool enable)
  146. {
  147. unsigned long reg;
  148. reg = readl(regs + S5P_JPGINTSE);
  149. reg &= ~S5P_DATA_NUM_INT_EN_MASK;
  150. if (enable)
  151. reg |= S5P_DATA_NUM_INT_EN;
  152. writel(reg, regs + S5P_JPGINTSE);
  153. }
  154. void s5p_jpeg_final_mcu_num_int_enable(void __iomem *regs, bool enbl)
  155. {
  156. unsigned long reg;
  157. reg = readl(regs + S5P_JPGINTSE);
  158. reg &= ~S5P_FINAL_MCU_NUM_INT_EN_MASK;
  159. if (enbl)
  160. reg |= S5P_FINAL_MCU_NUM_INT_EN;
  161. writel(reg, regs + S5P_JPGINTSE);
  162. }
  163. int s5p_jpeg_timer_stat(void __iomem *regs)
  164. {
  165. return (int)((readl(regs + S5P_JPG_TIMER_ST) & S5P_TIMER_INT_STAT_MASK)
  166. >> S5P_TIMER_INT_STAT_SHIFT);
  167. }
  168. void s5p_jpeg_clear_timer_stat(void __iomem *regs)
  169. {
  170. unsigned long reg;
  171. reg = readl(regs + S5P_JPG_TIMER_SE);
  172. reg &= ~S5P_TIMER_INT_STAT_MASK;
  173. writel(reg, regs + S5P_JPG_TIMER_SE);
  174. }
  175. void s5p_jpeg_enc_stream_int(void __iomem *regs, unsigned long size)
  176. {
  177. unsigned long reg;
  178. reg = readl(regs + S5P_JPG_ENC_STREAM_INTSE);
  179. reg &= ~S5P_ENC_STREAM_BOUND_MASK;
  180. reg |= S5P_ENC_STREAM_INT_EN;
  181. reg |= size & S5P_ENC_STREAM_BOUND_MASK;
  182. writel(reg, regs + S5P_JPG_ENC_STREAM_INTSE);
  183. }
  184. int s5p_jpeg_enc_stream_stat(void __iomem *regs)
  185. {
  186. return (int)(readl(regs + S5P_JPG_ENC_STREAM_INTST) &
  187. S5P_ENC_STREAM_INT_STAT_MASK);
  188. }
  189. void s5p_jpeg_clear_enc_stream_stat(void __iomem *regs)
  190. {
  191. unsigned long reg;
  192. reg = readl(regs + S5P_JPG_ENC_STREAM_INTSE);
  193. reg &= ~S5P_ENC_STREAM_INT_MASK;
  194. writel(reg, regs + S5P_JPG_ENC_STREAM_INTSE);
  195. }
  196. void s5p_jpeg_outform_raw(void __iomem *regs, unsigned long format)
  197. {
  198. unsigned long reg, f;
  199. f = S5P_DEC_OUT_FORMAT_422;
  200. if (format == S5P_JPEG_RAW_OUT_422)
  201. f = S5P_DEC_OUT_FORMAT_422;
  202. else if (format == S5P_JPEG_RAW_OUT_420)
  203. f = S5P_DEC_OUT_FORMAT_420;
  204. reg = readl(regs + S5P_JPG_OUTFORM);
  205. reg &= ~S5P_DEC_OUT_FORMAT_MASK;
  206. reg |= f;
  207. writel(reg, regs + S5P_JPG_OUTFORM);
  208. }
  209. void s5p_jpeg_jpgadr(void __iomem *regs, unsigned long addr)
  210. {
  211. writel(addr, regs + S5P_JPG_JPGADR);
  212. }
  213. void s5p_jpeg_imgadr(void __iomem *regs, unsigned long addr)
  214. {
  215. writel(addr, regs + S5P_JPG_IMGADR);
  216. }
  217. void s5p_jpeg_coef(void __iomem *regs, unsigned int i,
  218. unsigned int j, unsigned int coef)
  219. {
  220. unsigned long reg;
  221. reg = readl(regs + S5P_JPG_COEF(i));
  222. reg &= ~S5P_COEFn_MASK(j);
  223. reg |= (coef << S5P_COEFn_SHIFT(j)) & S5P_COEFn_MASK(j);
  224. writel(reg, regs + S5P_JPG_COEF(i));
  225. }
  226. void s5p_jpeg_start(void __iomem *regs)
  227. {
  228. writel(1, regs + S5P_JSTART);
  229. }
  230. int s5p_jpeg_result_stat_ok(void __iomem *regs)
  231. {
  232. return (int)((readl(regs + S5P_JPGINTST) & S5P_RESULT_STAT_MASK)
  233. >> S5P_RESULT_STAT_SHIFT);
  234. }
  235. int s5p_jpeg_stream_stat_ok(void __iomem *regs)
  236. {
  237. return !(int)((readl(regs + S5P_JPGINTST) & S5P_STREAM_STAT_MASK)
  238. >> S5P_STREAM_STAT_SHIFT);
  239. }
  240. void s5p_jpeg_clear_int(void __iomem *regs)
  241. {
  242. readl(regs + S5P_JPGINTST);
  243. writel(S5P_INT_RELEASE, regs + S5P_JPGCOM);
  244. readl(regs + S5P_JPGOPR);
  245. }
  246. unsigned int s5p_jpeg_compressed_size(void __iomem *regs)
  247. {
  248. unsigned long jpeg_size = 0;
  249. jpeg_size |= (readl(regs + S5P_JPGCNT_U) & 0xff) << 16;
  250. jpeg_size |= (readl(regs + S5P_JPGCNT_M) & 0xff) << 8;
  251. jpeg_size |= (readl(regs + S5P_JPGCNT_L) & 0xff);
  252. return (unsigned int)jpeg_size;
  253. }