1 /* linux/drivers/media/platform/s5p-jpeg/jpeg-hw.h
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
6 * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
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.
14 #include <linux/videodev2.h>
16 #include "jpeg-core.h"
17 #include "jpeg-regs.h"
18 #include "jpeg-hw-s5p.h"
20 void s5p_jpeg_reset(void __iomem
*regs
)
24 writel(1, regs
+ S5P_JPG_SW_RESET
);
25 reg
= readl(regs
+ S5P_JPG_SW_RESET
);
26 /* no other way but polling for when JPEG IP becomes operational */
29 reg
= readl(regs
+ S5P_JPG_SW_RESET
);
33 void s5p_jpeg_poweron(void __iomem
*regs
)
35 writel(S5P_POWER_ON
, regs
+ S5P_JPGCLKCON
);
38 void s5p_jpeg_input_raw_mode(void __iomem
*regs
, unsigned long mode
)
43 if (mode
== S5P_JPEG_RAW_IN_565
)
45 else if (mode
== S5P_JPEG_RAW_IN_422
)
48 reg
= readl(regs
+ S5P_JPGCMOD
);
49 reg
&= ~S5P_MOD_SEL_MASK
;
51 writel(reg
, regs
+ S5P_JPGCMOD
);
54 void s5p_jpeg_input_raw_y16(void __iomem
*regs
, bool y16
)
58 reg
= readl(regs
+ S5P_JPGCMOD
);
62 reg
&= ~S5P_MODE_Y16_MASK
;
63 writel(reg
, regs
+ S5P_JPGCMOD
);
66 void s5p_jpeg_proc_mode(void __iomem
*regs
, unsigned long mode
)
70 m
= S5P_PROC_MODE_DECOMPR
;
71 if (mode
== S5P_JPEG_ENCODE
)
72 m
= S5P_PROC_MODE_COMPR
;
74 m
= S5P_PROC_MODE_DECOMPR
;
75 reg
= readl(regs
+ S5P_JPGMOD
);
76 reg
&= ~S5P_PROC_MODE_MASK
;
78 writel(reg
, regs
+ S5P_JPGMOD
);
81 void s5p_jpeg_subsampling_mode(void __iomem
*regs
, unsigned int mode
)
85 if (mode
== V4L2_JPEG_CHROMA_SUBSAMPLING_420
)
86 m
= S5P_SUBSAMPLING_MODE_420
;
88 m
= S5P_SUBSAMPLING_MODE_422
;
90 reg
= readl(regs
+ S5P_JPGMOD
);
91 reg
&= ~S5P_SUBSAMPLING_MODE_MASK
;
93 writel(reg
, regs
+ S5P_JPGMOD
);
96 unsigned int s5p_jpeg_get_subsampling_mode(void __iomem
*regs
)
98 return readl(regs
+ S5P_JPGMOD
) & S5P_SUBSAMPLING_MODE_MASK
;
101 void s5p_jpeg_dri(void __iomem
*regs
, unsigned int dri
)
105 reg
= readl(regs
+ S5P_JPGDRI_U
);
107 reg
|= (dri
>> 8) & 0xff;
108 writel(reg
, regs
+ S5P_JPGDRI_U
);
110 reg
= readl(regs
+ S5P_JPGDRI_L
);
113 writel(reg
, regs
+ S5P_JPGDRI_L
);
116 void s5p_jpeg_qtbl(void __iomem
*regs
, unsigned int t
, unsigned int n
)
120 reg
= readl(regs
+ S5P_JPG_QTBL
);
121 reg
&= ~S5P_QT_NUMt_MASK(t
);
122 reg
|= (n
<< S5P_QT_NUMt_SHIFT(t
)) & S5P_QT_NUMt_MASK(t
);
123 writel(reg
, regs
+ S5P_JPG_QTBL
);
126 void s5p_jpeg_htbl_ac(void __iomem
*regs
, unsigned int t
)
130 reg
= readl(regs
+ S5P_JPG_HTBL
);
131 reg
&= ~S5P_HT_NUMt_AC_MASK(t
);
132 /* this driver uses table 0 for all color components */
133 reg
|= (0 << S5P_HT_NUMt_AC_SHIFT(t
)) & S5P_HT_NUMt_AC_MASK(t
);
134 writel(reg
, regs
+ S5P_JPG_HTBL
);
137 void s5p_jpeg_htbl_dc(void __iomem
*regs
, unsigned int t
)
141 reg
= readl(regs
+ S5P_JPG_HTBL
);
142 reg
&= ~S5P_HT_NUMt_DC_MASK(t
);
143 /* this driver uses table 0 for all color components */
144 reg
|= (0 << S5P_HT_NUMt_DC_SHIFT(t
)) & S5P_HT_NUMt_DC_MASK(t
);
145 writel(reg
, regs
+ S5P_JPG_HTBL
);
148 void s5p_jpeg_y(void __iomem
*regs
, unsigned int y
)
152 reg
= readl(regs
+ S5P_JPGY_U
);
154 reg
|= (y
>> 8) & 0xff;
155 writel(reg
, regs
+ S5P_JPGY_U
);
157 reg
= readl(regs
+ S5P_JPGY_L
);
160 writel(reg
, regs
+ S5P_JPGY_L
);
163 void s5p_jpeg_x(void __iomem
*regs
, unsigned int x
)
167 reg
= readl(regs
+ S5P_JPGX_U
);
169 reg
|= (x
>> 8) & 0xff;
170 writel(reg
, regs
+ S5P_JPGX_U
);
172 reg
= readl(regs
+ S5P_JPGX_L
);
175 writel(reg
, regs
+ S5P_JPGX_L
);
178 void s5p_jpeg_rst_int_enable(void __iomem
*regs
, bool enable
)
182 reg
= readl(regs
+ S5P_JPGINTSE
);
183 reg
&= ~S5P_RSTm_INT_EN_MASK
;
185 reg
|= S5P_RSTm_INT_EN
;
186 writel(reg
, regs
+ S5P_JPGINTSE
);
189 void s5p_jpeg_data_num_int_enable(void __iomem
*regs
, bool enable
)
193 reg
= readl(regs
+ S5P_JPGINTSE
);
194 reg
&= ~S5P_DATA_NUM_INT_EN_MASK
;
196 reg
|= S5P_DATA_NUM_INT_EN
;
197 writel(reg
, regs
+ S5P_JPGINTSE
);
200 void s5p_jpeg_final_mcu_num_int_enable(void __iomem
*regs
, bool enbl
)
204 reg
= readl(regs
+ S5P_JPGINTSE
);
205 reg
&= ~S5P_FINAL_MCU_NUM_INT_EN_MASK
;
207 reg
|= S5P_FINAL_MCU_NUM_INT_EN
;
208 writel(reg
, regs
+ S5P_JPGINTSE
);
211 void s5p_jpeg_timer_enable(void __iomem
*regs
, unsigned long val
)
215 reg
= readl(regs
+ S5P_JPG_TIMER_SE
);
216 reg
|= S5P_TIMER_INT_EN
;
217 reg
&= ~S5P_TIMER_INIT_MASK
;
218 reg
|= val
& S5P_TIMER_INIT_MASK
;
219 writel(reg
, regs
+ S5P_JPG_TIMER_SE
);
222 void s5p_jpeg_timer_disable(void __iomem
*regs
)
226 reg
= readl(regs
+ S5P_JPG_TIMER_SE
);
227 reg
&= ~S5P_TIMER_INT_EN_MASK
;
228 writel(reg
, regs
+ S5P_JPG_TIMER_SE
);
231 int s5p_jpeg_timer_stat(void __iomem
*regs
)
233 return (int)((readl(regs
+ S5P_JPG_TIMER_ST
) & S5P_TIMER_INT_STAT_MASK
)
234 >> S5P_TIMER_INT_STAT_SHIFT
);
237 void s5p_jpeg_clear_timer_stat(void __iomem
*regs
)
241 reg
= readl(regs
+ S5P_JPG_TIMER_SE
);
242 reg
&= ~S5P_TIMER_INT_STAT_MASK
;
243 writel(reg
, regs
+ S5P_JPG_TIMER_SE
);
246 void s5p_jpeg_enc_stream_int(void __iomem
*regs
, unsigned long size
)
250 reg
= readl(regs
+ S5P_JPG_ENC_STREAM_INTSE
);
251 reg
&= ~S5P_ENC_STREAM_BOUND_MASK
;
252 reg
|= S5P_ENC_STREAM_INT_EN
;
253 reg
|= size
& S5P_ENC_STREAM_BOUND_MASK
;
254 writel(reg
, regs
+ S5P_JPG_ENC_STREAM_INTSE
);
257 int s5p_jpeg_enc_stream_stat(void __iomem
*regs
)
259 return (int)(readl(regs
+ S5P_JPG_ENC_STREAM_INTST
) &
260 S5P_ENC_STREAM_INT_STAT_MASK
);
263 void s5p_jpeg_clear_enc_stream_stat(void __iomem
*regs
)
267 reg
= readl(regs
+ S5P_JPG_ENC_STREAM_INTSE
);
268 reg
&= ~S5P_ENC_STREAM_INT_MASK
;
269 writel(reg
, regs
+ S5P_JPG_ENC_STREAM_INTSE
);
272 void s5p_jpeg_outform_raw(void __iomem
*regs
, unsigned long format
)
274 unsigned long reg
, f
;
276 f
= S5P_DEC_OUT_FORMAT_422
;
277 if (format
== S5P_JPEG_RAW_OUT_422
)
278 f
= S5P_DEC_OUT_FORMAT_422
;
279 else if (format
== S5P_JPEG_RAW_OUT_420
)
280 f
= S5P_DEC_OUT_FORMAT_420
;
281 reg
= readl(regs
+ S5P_JPG_OUTFORM
);
282 reg
&= ~S5P_DEC_OUT_FORMAT_MASK
;
284 writel(reg
, regs
+ S5P_JPG_OUTFORM
);
287 void s5p_jpeg_jpgadr(void __iomem
*regs
, unsigned long addr
)
289 writel(addr
, regs
+ S5P_JPG_JPGADR
);
292 void s5p_jpeg_imgadr(void __iomem
*regs
, unsigned long addr
)
294 writel(addr
, regs
+ S5P_JPG_IMGADR
);
297 void s5p_jpeg_coef(void __iomem
*regs
, unsigned int i
,
298 unsigned int j
, unsigned int coef
)
302 reg
= readl(regs
+ S5P_JPG_COEF(i
));
303 reg
&= ~S5P_COEFn_MASK(j
);
304 reg
|= (coef
<< S5P_COEFn_SHIFT(j
)) & S5P_COEFn_MASK(j
);
305 writel(reg
, regs
+ S5P_JPG_COEF(i
));
308 void s5p_jpeg_start(void __iomem
*regs
)
310 writel(1, regs
+ S5P_JSTART
);
313 int s5p_jpeg_result_stat_ok(void __iomem
*regs
)
315 return (int)((readl(regs
+ S5P_JPGINTST
) & S5P_RESULT_STAT_MASK
)
316 >> S5P_RESULT_STAT_SHIFT
);
319 int s5p_jpeg_stream_stat_ok(void __iomem
*regs
)
321 return !(int)((readl(regs
+ S5P_JPGINTST
) & S5P_STREAM_STAT_MASK
)
322 >> S5P_STREAM_STAT_SHIFT
);
325 void s5p_jpeg_clear_int(void __iomem
*regs
)
329 reg
= readl(regs
+ S5P_JPGINTST
);
330 writel(S5P_INT_RELEASE
, regs
+ S5P_JPGCOM
);
331 reg
= readl(regs
+ S5P_JPGOPR
);
334 unsigned int s5p_jpeg_compressed_size(void __iomem
*regs
)
336 unsigned long jpeg_size
= 0;
338 jpeg_size
|= (readl(regs
+ S5P_JPGCNT_U
) & 0xff) << 16;
339 jpeg_size
|= (readl(regs
+ S5P_JPGCNT_M
) & 0xff) << 8;
340 jpeg_size
|= (readl(regs
+ S5P_JPGCNT_L
) & 0xff);
342 return (unsigned int)jpeg_size
;