1 /* linux/drivers/media/video/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.
18 #include "jpeg-regs.h"
20 #define S5P_JPEG_MIN_WIDTH 32
21 #define S5P_JPEG_MIN_HEIGHT 32
22 #define S5P_JPEG_MAX_WIDTH 8192
23 #define S5P_JPEG_MAX_HEIGHT 8192
24 #define S5P_JPEG_ENCODE 0
25 #define S5P_JPEG_DECODE 1
26 #define S5P_JPEG_RAW_IN_565 0
27 #define S5P_JPEG_RAW_IN_422 1
28 #define S5P_JPEG_SUBSAMPLING_422 0
29 #define S5P_JPEG_SUBSAMPLING_420 1
30 #define S5P_JPEG_RAW_OUT_422 0
31 #define S5P_JPEG_RAW_OUT_420 1
33 static inline void jpeg_reset(void __iomem
*regs
)
37 writel(1, regs
+ S5P_JPG_SW_RESET
);
38 reg
= readl(regs
+ S5P_JPG_SW_RESET
);
39 /* no other way but polling for when JPEG IP becomes operational */
42 reg
= readl(regs
+ S5P_JPG_SW_RESET
);
46 static inline void jpeg_poweron(void __iomem
*regs
)
48 writel(S5P_POWER_ON
, regs
+ S5P_JPGCLKCON
);
51 static inline void jpeg_input_raw_mode(void __iomem
*regs
, unsigned long mode
)
56 if (mode
== S5P_JPEG_RAW_IN_565
)
58 else if (mode
== S5P_JPEG_RAW_IN_422
)
61 reg
= readl(regs
+ S5P_JPGCMOD
);
62 reg
&= ~S5P_MOD_SEL_MASK
;
64 writel(reg
, regs
+ S5P_JPGCMOD
);
67 static inline void jpeg_input_raw_y16(void __iomem
*regs
, bool y16
)
71 reg
= readl(regs
+ S5P_JPGCMOD
);
75 reg
&= ~S5P_MODE_Y16_MASK
;
76 writel(reg
, regs
+ S5P_JPGCMOD
);
79 static inline void jpeg_proc_mode(void __iomem
*regs
, unsigned long mode
)
83 m
= S5P_PROC_MODE_DECOMPR
;
84 if (mode
== S5P_JPEG_ENCODE
)
85 m
= S5P_PROC_MODE_COMPR
;
87 m
= S5P_PROC_MODE_DECOMPR
;
88 reg
= readl(regs
+ S5P_JPGMOD
);
89 reg
&= ~S5P_PROC_MODE_MASK
;
91 writel(reg
, regs
+ S5P_JPGMOD
);
94 static inline void jpeg_subsampling_mode(void __iomem
*regs
, unsigned long mode
)
98 m
= S5P_SUBSAMPLING_MODE_422
;
99 if (mode
== S5P_JPEG_SUBSAMPLING_422
)
100 m
= S5P_SUBSAMPLING_MODE_422
;
101 else if (mode
== S5P_JPEG_SUBSAMPLING_420
)
102 m
= S5P_SUBSAMPLING_MODE_420
;
103 reg
= readl(regs
+ S5P_JPGMOD
);
104 reg
&= ~S5P_SUBSAMPLING_MODE_MASK
;
106 writel(reg
, regs
+ S5P_JPGMOD
);
109 static inline void jpeg_dri(void __iomem
*regs
, unsigned int dri
)
113 reg
= readl(regs
+ S5P_JPGDRI_U
);
115 reg
|= (dri
>> 8) & 0xff;
116 writel(reg
, regs
+ S5P_JPGDRI_U
);
118 reg
= readl(regs
+ S5P_JPGDRI_L
);
121 writel(reg
, regs
+ S5P_JPGDRI_L
);
124 static inline void jpeg_qtbl(void __iomem
*regs
, unsigned int t
, unsigned int n
)
128 reg
= readl(regs
+ S5P_JPG_QTBL
);
129 reg
&= ~S5P_QT_NUMt_MASK(t
);
130 reg
|= (n
<< S5P_QT_NUMt_SHIFT(t
)) & S5P_QT_NUMt_MASK(t
);
131 writel(reg
, regs
+ S5P_JPG_QTBL
);
134 static inline void jpeg_htbl_ac(void __iomem
*regs
, unsigned int t
)
138 reg
= readl(regs
+ S5P_JPG_HTBL
);
139 reg
&= ~S5P_HT_NUMt_AC_MASK(t
);
140 /* this driver uses table 0 for all color components */
141 reg
|= (0 << S5P_HT_NUMt_AC_SHIFT(t
)) & S5P_HT_NUMt_AC_MASK(t
);
142 writel(reg
, regs
+ S5P_JPG_HTBL
);
145 static inline void jpeg_htbl_dc(void __iomem
*regs
, unsigned int t
)
149 reg
= readl(regs
+ S5P_JPG_HTBL
);
150 reg
&= ~S5P_HT_NUMt_DC_MASK(t
);
151 /* this driver uses table 0 for all color components */
152 reg
|= (0 << S5P_HT_NUMt_DC_SHIFT(t
)) & S5P_HT_NUMt_DC_MASK(t
);
153 writel(reg
, regs
+ S5P_JPG_HTBL
);
156 static inline void jpeg_y(void __iomem
*regs
, unsigned int y
)
160 reg
= readl(regs
+ S5P_JPGY_U
);
162 reg
|= (y
>> 8) & 0xff;
163 writel(reg
, regs
+ S5P_JPGY_U
);
165 reg
= readl(regs
+ S5P_JPGY_L
);
168 writel(reg
, regs
+ S5P_JPGY_L
);
171 static inline void jpeg_x(void __iomem
*regs
, unsigned int x
)
175 reg
= readl(regs
+ S5P_JPGX_U
);
177 reg
|= (x
>> 8) & 0xff;
178 writel(reg
, regs
+ S5P_JPGX_U
);
180 reg
= readl(regs
+ S5P_JPGX_L
);
183 writel(reg
, regs
+ S5P_JPGX_L
);
186 static inline void jpeg_rst_int_enable(void __iomem
*regs
, bool enable
)
190 reg
= readl(regs
+ S5P_JPGINTSE
);
191 reg
&= ~S5P_RSTm_INT_EN_MASK
;
193 reg
|= S5P_RSTm_INT_EN
;
194 writel(reg
, regs
+ S5P_JPGINTSE
);
197 static inline void jpeg_data_num_int_enable(void __iomem
*regs
, bool enable
)
201 reg
= readl(regs
+ S5P_JPGINTSE
);
202 reg
&= ~S5P_DATA_NUM_INT_EN_MASK
;
204 reg
|= S5P_DATA_NUM_INT_EN
;
205 writel(reg
, regs
+ S5P_JPGINTSE
);
208 static inline void jpeg_final_mcu_num_int_enable(void __iomem
*regs
, bool enbl
)
212 reg
= readl(regs
+ S5P_JPGINTSE
);
213 reg
&= ~S5P_FINAL_MCU_NUM_INT_EN_MASK
;
215 reg
|= S5P_FINAL_MCU_NUM_INT_EN
;
216 writel(reg
, regs
+ S5P_JPGINTSE
);
219 static inline void jpeg_timer_enable(void __iomem
*regs
, unsigned long val
)
223 reg
= readl(regs
+ S5P_JPG_TIMER_SE
);
224 reg
|= S5P_TIMER_INT_EN
;
225 reg
&= ~S5P_TIMER_INIT_MASK
;
226 reg
|= val
& S5P_TIMER_INIT_MASK
;
227 writel(reg
, regs
+ S5P_JPG_TIMER_SE
);
230 static inline void jpeg_timer_disable(void __iomem
*regs
)
234 reg
= readl(regs
+ S5P_JPG_TIMER_SE
);
235 reg
&= ~S5P_TIMER_INT_EN_MASK
;
236 writel(reg
, regs
+ S5P_JPG_TIMER_SE
);
239 static inline int jpeg_timer_stat(void __iomem
*regs
)
241 return (int)((readl(regs
+ S5P_JPG_TIMER_ST
) & S5P_TIMER_INT_STAT_MASK
)
242 >> S5P_TIMER_INT_STAT_SHIFT
);
245 static inline void jpeg_clear_timer_stat(void __iomem
*regs
)
249 reg
= readl(regs
+ S5P_JPG_TIMER_SE
);
250 reg
&= ~S5P_TIMER_INT_STAT_MASK
;
251 writel(reg
, regs
+ S5P_JPG_TIMER_SE
);
254 static inline void jpeg_enc_stream_int(void __iomem
*regs
, unsigned long size
)
258 reg
= readl(regs
+ S5P_JPG_ENC_STREAM_INTSE
);
259 reg
&= ~S5P_ENC_STREAM_BOUND_MASK
;
260 reg
|= S5P_ENC_STREAM_INT_EN
;
261 reg
|= size
& S5P_ENC_STREAM_BOUND_MASK
;
262 writel(reg
, regs
+ S5P_JPG_ENC_STREAM_INTSE
);
265 static inline int jpeg_enc_stream_stat(void __iomem
*regs
)
267 return (int)(readl(regs
+ S5P_JPG_ENC_STREAM_INTST
) &
268 S5P_ENC_STREAM_INT_STAT_MASK
);
271 static inline void jpeg_clear_enc_stream_stat(void __iomem
*regs
)
275 reg
= readl(regs
+ S5P_JPG_ENC_STREAM_INTSE
);
276 reg
&= ~S5P_ENC_STREAM_INT_MASK
;
277 writel(reg
, regs
+ S5P_JPG_ENC_STREAM_INTSE
);
280 static inline void jpeg_outform_raw(void __iomem
*regs
, unsigned long format
)
282 unsigned long reg
, f
;
284 f
= S5P_DEC_OUT_FORMAT_422
;
285 if (format
== S5P_JPEG_RAW_OUT_422
)
286 f
= S5P_DEC_OUT_FORMAT_422
;
287 else if (format
== S5P_JPEG_RAW_OUT_420
)
288 f
= S5P_DEC_OUT_FORMAT_420
;
289 reg
= readl(regs
+ S5P_JPG_OUTFORM
);
290 reg
&= ~S5P_DEC_OUT_FORMAT_MASK
;
292 writel(reg
, regs
+ S5P_JPG_OUTFORM
);
295 static inline void jpeg_jpgadr(void __iomem
*regs
, unsigned long addr
)
297 writel(addr
, regs
+ S5P_JPG_JPGADR
);
300 static inline void jpeg_imgadr(void __iomem
*regs
, unsigned long addr
)
302 writel(addr
, regs
+ S5P_JPG_IMGADR
);
305 static inline void jpeg_coef(void __iomem
*regs
, unsigned int i
,
306 unsigned int j
, unsigned int coef
)
310 reg
= readl(regs
+ S5P_JPG_COEF(i
));
311 reg
&= ~S5P_COEFn_MASK(j
);
312 reg
|= (coef
<< S5P_COEFn_SHIFT(j
)) & S5P_COEFn_MASK(j
);
313 writel(reg
, regs
+ S5P_JPG_COEF(i
));
316 static inline void jpeg_start(void __iomem
*regs
)
318 writel(1, regs
+ S5P_JSTART
);
321 static inline int jpeg_result_stat_ok(void __iomem
*regs
)
323 return (int)((readl(regs
+ S5P_JPGINTST
) & S5P_RESULT_STAT_MASK
)
324 >> S5P_RESULT_STAT_SHIFT
);
327 static inline int jpeg_stream_stat_ok(void __iomem
*regs
)
329 return !(int)((readl(regs
+ S5P_JPGINTST
) & S5P_STREAM_STAT_MASK
)
330 >> S5P_STREAM_STAT_SHIFT
);
333 static inline void jpeg_clear_int(void __iomem
*regs
)
337 reg
= readl(regs
+ S5P_JPGINTST
);
338 writel(S5P_INT_RELEASE
, regs
+ S5P_JPGCOM
);
339 reg
= readl(regs
+ S5P_JPGOPR
);
342 static inline unsigned int jpeg_compressed_size(void __iomem
*regs
)
344 unsigned long jpeg_size
= 0;
346 jpeg_size
|= (readl(regs
+ S5P_JPGCNT_U
) & 0xff) << 16;
347 jpeg_size
|= (readl(regs
+ S5P_JPGCNT_M
) & 0xff) << 8;
348 jpeg_size
|= (readl(regs
+ S5P_JPGCNT_L
) & 0xff);
350 return (unsigned int)jpeg_size
;
353 #endif /* JPEG_HW_H_ */