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_proc_mode(void __iomem
*regs
, unsigned long mode
)
58 m
= S5P_PROC_MODE_DECOMPR
;
59 if (mode
== S5P_JPEG_ENCODE
)
60 m
= S5P_PROC_MODE_COMPR
;
62 m
= S5P_PROC_MODE_DECOMPR
;
63 reg
= readl(regs
+ S5P_JPGMOD
);
64 reg
&= ~S5P_PROC_MODE_MASK
;
66 writel(reg
, regs
+ S5P_JPGMOD
);
69 void s5p_jpeg_subsampling_mode(void __iomem
*regs
, unsigned int mode
)
73 if (mode
== V4L2_JPEG_CHROMA_SUBSAMPLING_420
)
74 m
= S5P_SUBSAMPLING_MODE_420
;
76 m
= S5P_SUBSAMPLING_MODE_422
;
78 reg
= readl(regs
+ S5P_JPGMOD
);
79 reg
&= ~S5P_SUBSAMPLING_MODE_MASK
;
81 writel(reg
, regs
+ S5P_JPGMOD
);
84 unsigned int s5p_jpeg_get_subsampling_mode(void __iomem
*regs
)
86 return readl(regs
+ S5P_JPGMOD
) & S5P_SUBSAMPLING_MODE_MASK
;
89 void s5p_jpeg_dri(void __iomem
*regs
, unsigned int dri
)
93 reg
= readl(regs
+ S5P_JPGDRI_U
);
95 reg
|= (dri
>> 8) & 0xff;
96 writel(reg
, regs
+ S5P_JPGDRI_U
);
98 reg
= readl(regs
+ S5P_JPGDRI_L
);
101 writel(reg
, regs
+ S5P_JPGDRI_L
);
104 void s5p_jpeg_qtbl(void __iomem
*regs
, unsigned int t
, unsigned int n
)
108 reg
= readl(regs
+ S5P_JPG_QTBL
);
109 reg
&= ~S5P_QT_NUMt_MASK(t
);
110 reg
|= (n
<< S5P_QT_NUMt_SHIFT(t
)) & S5P_QT_NUMt_MASK(t
);
111 writel(reg
, regs
+ S5P_JPG_QTBL
);
114 void s5p_jpeg_htbl_ac(void __iomem
*regs
, unsigned int t
)
118 reg
= readl(regs
+ S5P_JPG_HTBL
);
119 reg
&= ~S5P_HT_NUMt_AC_MASK(t
);
120 /* this driver uses table 0 for all color components */
121 reg
|= (0 << S5P_HT_NUMt_AC_SHIFT(t
)) & S5P_HT_NUMt_AC_MASK(t
);
122 writel(reg
, regs
+ S5P_JPG_HTBL
);
125 void s5p_jpeg_htbl_dc(void __iomem
*regs
, unsigned int t
)
129 reg
= readl(regs
+ S5P_JPG_HTBL
);
130 reg
&= ~S5P_HT_NUMt_DC_MASK(t
);
131 /* this driver uses table 0 for all color components */
132 reg
|= (0 << S5P_HT_NUMt_DC_SHIFT(t
)) & S5P_HT_NUMt_DC_MASK(t
);
133 writel(reg
, regs
+ S5P_JPG_HTBL
);
136 void s5p_jpeg_y(void __iomem
*regs
, unsigned int y
)
140 reg
= readl(regs
+ S5P_JPGY_U
);
142 reg
|= (y
>> 8) & 0xff;
143 writel(reg
, regs
+ S5P_JPGY_U
);
145 reg
= readl(regs
+ S5P_JPGY_L
);
148 writel(reg
, regs
+ S5P_JPGY_L
);
151 void s5p_jpeg_x(void __iomem
*regs
, unsigned int x
)
155 reg
= readl(regs
+ S5P_JPGX_U
);
157 reg
|= (x
>> 8) & 0xff;
158 writel(reg
, regs
+ S5P_JPGX_U
);
160 reg
= readl(regs
+ S5P_JPGX_L
);
163 writel(reg
, regs
+ S5P_JPGX_L
);
166 void s5p_jpeg_rst_int_enable(void __iomem
*regs
, bool enable
)
170 reg
= readl(regs
+ S5P_JPGINTSE
);
171 reg
&= ~S5P_RSTm_INT_EN_MASK
;
173 reg
|= S5P_RSTm_INT_EN
;
174 writel(reg
, regs
+ S5P_JPGINTSE
);
177 void s5p_jpeg_data_num_int_enable(void __iomem
*regs
, bool enable
)
181 reg
= readl(regs
+ S5P_JPGINTSE
);
182 reg
&= ~S5P_DATA_NUM_INT_EN_MASK
;
184 reg
|= S5P_DATA_NUM_INT_EN
;
185 writel(reg
, regs
+ S5P_JPGINTSE
);
188 void s5p_jpeg_final_mcu_num_int_enable(void __iomem
*regs
, bool enbl
)
192 reg
= readl(regs
+ S5P_JPGINTSE
);
193 reg
&= ~S5P_FINAL_MCU_NUM_INT_EN_MASK
;
195 reg
|= S5P_FINAL_MCU_NUM_INT_EN
;
196 writel(reg
, regs
+ S5P_JPGINTSE
);
199 int s5p_jpeg_timer_stat(void __iomem
*regs
)
201 return (int)((readl(regs
+ S5P_JPG_TIMER_ST
) & S5P_TIMER_INT_STAT_MASK
)
202 >> S5P_TIMER_INT_STAT_SHIFT
);
205 void s5p_jpeg_clear_timer_stat(void __iomem
*regs
)
209 reg
= readl(regs
+ S5P_JPG_TIMER_SE
);
210 reg
&= ~S5P_TIMER_INT_STAT_MASK
;
211 writel(reg
, regs
+ S5P_JPG_TIMER_SE
);
214 void s5p_jpeg_enc_stream_int(void __iomem
*regs
, unsigned long size
)
218 reg
= readl(regs
+ S5P_JPG_ENC_STREAM_INTSE
);
219 reg
&= ~S5P_ENC_STREAM_BOUND_MASK
;
220 reg
|= S5P_ENC_STREAM_INT_EN
;
221 reg
|= size
& S5P_ENC_STREAM_BOUND_MASK
;
222 writel(reg
, regs
+ S5P_JPG_ENC_STREAM_INTSE
);
225 int s5p_jpeg_enc_stream_stat(void __iomem
*regs
)
227 return (int)(readl(regs
+ S5P_JPG_ENC_STREAM_INTST
) &
228 S5P_ENC_STREAM_INT_STAT_MASK
);
231 void s5p_jpeg_clear_enc_stream_stat(void __iomem
*regs
)
235 reg
= readl(regs
+ S5P_JPG_ENC_STREAM_INTSE
);
236 reg
&= ~S5P_ENC_STREAM_INT_MASK
;
237 writel(reg
, regs
+ S5P_JPG_ENC_STREAM_INTSE
);
240 void s5p_jpeg_outform_raw(void __iomem
*regs
, unsigned long format
)
242 unsigned long reg
, f
;
244 f
= S5P_DEC_OUT_FORMAT_422
;
245 if (format
== S5P_JPEG_RAW_OUT_422
)
246 f
= S5P_DEC_OUT_FORMAT_422
;
247 else if (format
== S5P_JPEG_RAW_OUT_420
)
248 f
= S5P_DEC_OUT_FORMAT_420
;
249 reg
= readl(regs
+ S5P_JPG_OUTFORM
);
250 reg
&= ~S5P_DEC_OUT_FORMAT_MASK
;
252 writel(reg
, regs
+ S5P_JPG_OUTFORM
);
255 void s5p_jpeg_jpgadr(void __iomem
*regs
, unsigned long addr
)
257 writel(addr
, regs
+ S5P_JPG_JPGADR
);
260 void s5p_jpeg_imgadr(void __iomem
*regs
, unsigned long addr
)
262 writel(addr
, regs
+ S5P_JPG_IMGADR
);
265 void s5p_jpeg_coef(void __iomem
*regs
, unsigned int i
,
266 unsigned int j
, unsigned int coef
)
270 reg
= readl(regs
+ S5P_JPG_COEF(i
));
271 reg
&= ~S5P_COEFn_MASK(j
);
272 reg
|= (coef
<< S5P_COEFn_SHIFT(j
)) & S5P_COEFn_MASK(j
);
273 writel(reg
, regs
+ S5P_JPG_COEF(i
));
276 void s5p_jpeg_start(void __iomem
*regs
)
278 writel(1, regs
+ S5P_JSTART
);
281 int s5p_jpeg_result_stat_ok(void __iomem
*regs
)
283 return (int)((readl(regs
+ S5P_JPGINTST
) & S5P_RESULT_STAT_MASK
)
284 >> S5P_RESULT_STAT_SHIFT
);
287 int s5p_jpeg_stream_stat_ok(void __iomem
*regs
)
289 return !(int)((readl(regs
+ S5P_JPGINTST
) & S5P_STREAM_STAT_MASK
)
290 >> S5P_STREAM_STAT_SHIFT
);
293 void s5p_jpeg_clear_int(void __iomem
*regs
)
295 readl(regs
+ S5P_JPGINTST
);
296 writel(S5P_INT_RELEASE
, regs
+ S5P_JPGCOM
);
297 readl(regs
+ S5P_JPGOPR
);
300 unsigned int s5p_jpeg_compressed_size(void __iomem
*regs
)
302 unsigned long jpeg_size
= 0;
304 jpeg_size
|= (readl(regs
+ S5P_JPGCNT_U
) & 0xff) << 16;
305 jpeg_size
|= (readl(regs
+ S5P_JPGCNT_M
) & 0xff) << 8;
306 jpeg_size
|= (readl(regs
+ S5P_JPGCNT_L
) & 0xff);
308 return (unsigned int)jpeg_size
;