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.
16 #include <linux/videodev2.h>
19 #include "jpeg-regs.h"
21 #define S5P_JPEG_MIN_WIDTH 32
22 #define S5P_JPEG_MIN_HEIGHT 32
23 #define S5P_JPEG_MAX_WIDTH 8192
24 #define S5P_JPEG_MAX_HEIGHT 8192
25 #define S5P_JPEG_ENCODE 0
26 #define S5P_JPEG_DECODE 1
27 #define S5P_JPEG_RAW_IN_565 0
28 #define S5P_JPEG_RAW_IN_422 1
29 #define S5P_JPEG_RAW_OUT_422 0
30 #define S5P_JPEG_RAW_OUT_420 1
32 static inline void jpeg_reset(void __iomem
*regs
)
36 writel(1, regs
+ S5P_JPG_SW_RESET
);
37 reg
= readl(regs
+ S5P_JPG_SW_RESET
);
38 /* no other way but polling for when JPEG IP becomes operational */
41 reg
= readl(regs
+ S5P_JPG_SW_RESET
);
45 static inline void jpeg_poweron(void __iomem
*regs
)
47 writel(S5P_POWER_ON
, regs
+ S5P_JPGCLKCON
);
50 static inline void jpeg_input_raw_mode(void __iomem
*regs
, unsigned long mode
)
55 if (mode
== S5P_JPEG_RAW_IN_565
)
57 else if (mode
== S5P_JPEG_RAW_IN_422
)
60 reg
= readl(regs
+ S5P_JPGCMOD
);
61 reg
&= ~S5P_MOD_SEL_MASK
;
63 writel(reg
, regs
+ S5P_JPGCMOD
);
66 static inline void jpeg_input_raw_y16(void __iomem
*regs
, bool y16
)
70 reg
= readl(regs
+ S5P_JPGCMOD
);
74 reg
&= ~S5P_MODE_Y16_MASK
;
75 writel(reg
, regs
+ S5P_JPGCMOD
);
78 static inline void jpeg_proc_mode(void __iomem
*regs
, unsigned long mode
)
82 m
= S5P_PROC_MODE_DECOMPR
;
83 if (mode
== S5P_JPEG_ENCODE
)
84 m
= S5P_PROC_MODE_COMPR
;
86 m
= S5P_PROC_MODE_DECOMPR
;
87 reg
= readl(regs
+ S5P_JPGMOD
);
88 reg
&= ~S5P_PROC_MODE_MASK
;
90 writel(reg
, regs
+ S5P_JPGMOD
);
93 static inline void jpeg_subsampling_mode(void __iomem
*regs
, unsigned int mode
)
97 if (mode
== V4L2_JPEG_CHROMA_SUBSAMPLING_420
)
98 m
= S5P_SUBSAMPLING_MODE_420
;
100 m
= S5P_SUBSAMPLING_MODE_422
;
102 reg
= readl(regs
+ S5P_JPGMOD
);
103 reg
&= ~S5P_SUBSAMPLING_MODE_MASK
;
105 writel(reg
, regs
+ S5P_JPGMOD
);
108 static inline unsigned int jpeg_get_subsampling_mode(void __iomem
*regs
)
110 return readl(regs
+ S5P_JPGMOD
) & S5P_SUBSAMPLING_MODE_MASK
;
113 static inline void jpeg_dri(void __iomem
*regs
, unsigned int dri
)
117 reg
= readl(regs
+ S5P_JPGDRI_U
);
119 reg
|= (dri
>> 8) & 0xff;
120 writel(reg
, regs
+ S5P_JPGDRI_U
);
122 reg
= readl(regs
+ S5P_JPGDRI_L
);
125 writel(reg
, regs
+ S5P_JPGDRI_L
);
128 static inline void jpeg_qtbl(void __iomem
*regs
, unsigned int t
, unsigned int n
)
132 reg
= readl(regs
+ S5P_JPG_QTBL
);
133 reg
&= ~S5P_QT_NUMt_MASK(t
);
134 reg
|= (n
<< S5P_QT_NUMt_SHIFT(t
)) & S5P_QT_NUMt_MASK(t
);
135 writel(reg
, regs
+ S5P_JPG_QTBL
);
138 static inline void jpeg_htbl_ac(void __iomem
*regs
, unsigned int t
)
142 reg
= readl(regs
+ S5P_JPG_HTBL
);
143 reg
&= ~S5P_HT_NUMt_AC_MASK(t
);
144 /* this driver uses table 0 for all color components */
145 reg
|= (0 << S5P_HT_NUMt_AC_SHIFT(t
)) & S5P_HT_NUMt_AC_MASK(t
);
146 writel(reg
, regs
+ S5P_JPG_HTBL
);
149 static inline void jpeg_htbl_dc(void __iomem
*regs
, unsigned int t
)
153 reg
= readl(regs
+ S5P_JPG_HTBL
);
154 reg
&= ~S5P_HT_NUMt_DC_MASK(t
);
155 /* this driver uses table 0 for all color components */
156 reg
|= (0 << S5P_HT_NUMt_DC_SHIFT(t
)) & S5P_HT_NUMt_DC_MASK(t
);
157 writel(reg
, regs
+ S5P_JPG_HTBL
);
160 static inline void jpeg_y(void __iomem
*regs
, unsigned int y
)
164 reg
= readl(regs
+ S5P_JPGY_U
);
166 reg
|= (y
>> 8) & 0xff;
167 writel(reg
, regs
+ S5P_JPGY_U
);
169 reg
= readl(regs
+ S5P_JPGY_L
);
172 writel(reg
, regs
+ S5P_JPGY_L
);
175 static inline void jpeg_x(void __iomem
*regs
, unsigned int x
)
179 reg
= readl(regs
+ S5P_JPGX_U
);
181 reg
|= (x
>> 8) & 0xff;
182 writel(reg
, regs
+ S5P_JPGX_U
);
184 reg
= readl(regs
+ S5P_JPGX_L
);
187 writel(reg
, regs
+ S5P_JPGX_L
);
190 static inline void jpeg_rst_int_enable(void __iomem
*regs
, bool enable
)
194 reg
= readl(regs
+ S5P_JPGINTSE
);
195 reg
&= ~S5P_RSTm_INT_EN_MASK
;
197 reg
|= S5P_RSTm_INT_EN
;
198 writel(reg
, regs
+ S5P_JPGINTSE
);
201 static inline void jpeg_data_num_int_enable(void __iomem
*regs
, bool enable
)
205 reg
= readl(regs
+ S5P_JPGINTSE
);
206 reg
&= ~S5P_DATA_NUM_INT_EN_MASK
;
208 reg
|= S5P_DATA_NUM_INT_EN
;
209 writel(reg
, regs
+ S5P_JPGINTSE
);
212 static inline void jpeg_final_mcu_num_int_enable(void __iomem
*regs
, bool enbl
)
216 reg
= readl(regs
+ S5P_JPGINTSE
);
217 reg
&= ~S5P_FINAL_MCU_NUM_INT_EN_MASK
;
219 reg
|= S5P_FINAL_MCU_NUM_INT_EN
;
220 writel(reg
, regs
+ S5P_JPGINTSE
);
223 static inline void jpeg_timer_enable(void __iomem
*regs
, unsigned long val
)
227 reg
= readl(regs
+ S5P_JPG_TIMER_SE
);
228 reg
|= S5P_TIMER_INT_EN
;
229 reg
&= ~S5P_TIMER_INIT_MASK
;
230 reg
|= val
& S5P_TIMER_INIT_MASK
;
231 writel(reg
, regs
+ S5P_JPG_TIMER_SE
);
234 static inline void jpeg_timer_disable(void __iomem
*regs
)
238 reg
= readl(regs
+ S5P_JPG_TIMER_SE
);
239 reg
&= ~S5P_TIMER_INT_EN_MASK
;
240 writel(reg
, regs
+ S5P_JPG_TIMER_SE
);
243 static inline int jpeg_timer_stat(void __iomem
*regs
)
245 return (int)((readl(regs
+ S5P_JPG_TIMER_ST
) & S5P_TIMER_INT_STAT_MASK
)
246 >> S5P_TIMER_INT_STAT_SHIFT
);
249 static inline void jpeg_clear_timer_stat(void __iomem
*regs
)
253 reg
= readl(regs
+ S5P_JPG_TIMER_SE
);
254 reg
&= ~S5P_TIMER_INT_STAT_MASK
;
255 writel(reg
, regs
+ S5P_JPG_TIMER_SE
);
258 static inline void jpeg_enc_stream_int(void __iomem
*regs
, unsigned long size
)
262 reg
= readl(regs
+ S5P_JPG_ENC_STREAM_INTSE
);
263 reg
&= ~S5P_ENC_STREAM_BOUND_MASK
;
264 reg
|= S5P_ENC_STREAM_INT_EN
;
265 reg
|= size
& S5P_ENC_STREAM_BOUND_MASK
;
266 writel(reg
, regs
+ S5P_JPG_ENC_STREAM_INTSE
);
269 static inline int jpeg_enc_stream_stat(void __iomem
*regs
)
271 return (int)(readl(regs
+ S5P_JPG_ENC_STREAM_INTST
) &
272 S5P_ENC_STREAM_INT_STAT_MASK
);
275 static inline void jpeg_clear_enc_stream_stat(void __iomem
*regs
)
279 reg
= readl(regs
+ S5P_JPG_ENC_STREAM_INTSE
);
280 reg
&= ~S5P_ENC_STREAM_INT_MASK
;
281 writel(reg
, regs
+ S5P_JPG_ENC_STREAM_INTSE
);
284 static inline void jpeg_outform_raw(void __iomem
*regs
, unsigned long format
)
286 unsigned long reg
, f
;
288 f
= S5P_DEC_OUT_FORMAT_422
;
289 if (format
== S5P_JPEG_RAW_OUT_422
)
290 f
= S5P_DEC_OUT_FORMAT_422
;
291 else if (format
== S5P_JPEG_RAW_OUT_420
)
292 f
= S5P_DEC_OUT_FORMAT_420
;
293 reg
= readl(regs
+ S5P_JPG_OUTFORM
);
294 reg
&= ~S5P_DEC_OUT_FORMAT_MASK
;
296 writel(reg
, regs
+ S5P_JPG_OUTFORM
);
299 static inline void jpeg_jpgadr(void __iomem
*regs
, unsigned long addr
)
301 writel(addr
, regs
+ S5P_JPG_JPGADR
);
304 static inline void jpeg_imgadr(void __iomem
*regs
, unsigned long addr
)
306 writel(addr
, regs
+ S5P_JPG_IMGADR
);
309 static inline void jpeg_coef(void __iomem
*regs
, unsigned int i
,
310 unsigned int j
, unsigned int coef
)
314 reg
= readl(regs
+ S5P_JPG_COEF(i
));
315 reg
&= ~S5P_COEFn_MASK(j
);
316 reg
|= (coef
<< S5P_COEFn_SHIFT(j
)) & S5P_COEFn_MASK(j
);
317 writel(reg
, regs
+ S5P_JPG_COEF(i
));
320 static inline void jpeg_start(void __iomem
*regs
)
322 writel(1, regs
+ S5P_JSTART
);
325 static inline int jpeg_result_stat_ok(void __iomem
*regs
)
327 return (int)((readl(regs
+ S5P_JPGINTST
) & S5P_RESULT_STAT_MASK
)
328 >> S5P_RESULT_STAT_SHIFT
);
331 static inline int jpeg_stream_stat_ok(void __iomem
*regs
)
333 return !(int)((readl(regs
+ S5P_JPGINTST
) & S5P_STREAM_STAT_MASK
)
334 >> S5P_STREAM_STAT_SHIFT
);
337 static inline void jpeg_clear_int(void __iomem
*regs
)
341 reg
= readl(regs
+ S5P_JPGINTST
);
342 writel(S5P_INT_RELEASE
, regs
+ S5P_JPGCOM
);
343 reg
= readl(regs
+ S5P_JPGOPR
);
346 static inline unsigned int jpeg_compressed_size(void __iomem
*regs
)
348 unsigned long jpeg_size
= 0;
350 jpeg_size
|= (readl(regs
+ S5P_JPGCNT_U
) & 0xff) << 16;
351 jpeg_size
|= (readl(regs
+ S5P_JPGCNT_M
) & 0xff) << 8;
352 jpeg_size
|= (readl(regs
+ S5P_JPGCNT_L
) & 0xff);
354 return (unsigned int)jpeg_size
;
357 #endif /* JPEG_HW_H_ */