x86, cpufeature: If we disable CLFLUSH, we should disable CLFLUSHOPT
[linux/fpc-iii.git] / drivers / media / platform / s5p-jpeg / jpeg-hw-s5p.c
blob52407d7907267e520b81bcc540420f1f2ff34544
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.
13 #include <linux/io.h>
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)
22 unsigned long reg;
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 */
27 while (reg != 0) {
28 cpu_relax();
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)
40 unsigned long reg, m;
42 m = S5P_MOD_SEL_565;
43 if (mode == S5P_JPEG_RAW_IN_565)
44 m = S5P_MOD_SEL_565;
45 else if (mode == S5P_JPEG_RAW_IN_422)
46 m = S5P_MOD_SEL_422;
48 reg = readl(regs + S5P_JPGCMOD);
49 reg &= ~S5P_MOD_SEL_MASK;
50 reg |= m;
51 writel(reg, regs + S5P_JPGCMOD);
54 void s5p_jpeg_input_raw_y16(void __iomem *regs, bool y16)
56 unsigned long reg;
58 reg = readl(regs + S5P_JPGCMOD);
59 if (y16)
60 reg |= S5P_MODE_Y16;
61 else
62 reg &= ~S5P_MODE_Y16_MASK;
63 writel(reg, regs + S5P_JPGCMOD);
66 void s5p_jpeg_proc_mode(void __iomem *regs, unsigned long mode)
68 unsigned long reg, m;
70 m = S5P_PROC_MODE_DECOMPR;
71 if (mode == S5P_JPEG_ENCODE)
72 m = S5P_PROC_MODE_COMPR;
73 else
74 m = S5P_PROC_MODE_DECOMPR;
75 reg = readl(regs + S5P_JPGMOD);
76 reg &= ~S5P_PROC_MODE_MASK;
77 reg |= m;
78 writel(reg, regs + S5P_JPGMOD);
81 void s5p_jpeg_subsampling_mode(void __iomem *regs, unsigned int mode)
83 unsigned long reg, m;
85 if (mode == V4L2_JPEG_CHROMA_SUBSAMPLING_420)
86 m = S5P_SUBSAMPLING_MODE_420;
87 else
88 m = S5P_SUBSAMPLING_MODE_422;
90 reg = readl(regs + S5P_JPGMOD);
91 reg &= ~S5P_SUBSAMPLING_MODE_MASK;
92 reg |= m;
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)
103 unsigned long reg;
105 reg = readl(regs + S5P_JPGDRI_U);
106 reg &= ~0xff;
107 reg |= (dri >> 8) & 0xff;
108 writel(reg, regs + S5P_JPGDRI_U);
110 reg = readl(regs + S5P_JPGDRI_L);
111 reg &= ~0xff;
112 reg |= dri & 0xff;
113 writel(reg, regs + S5P_JPGDRI_L);
116 void s5p_jpeg_qtbl(void __iomem *regs, unsigned int t, unsigned int n)
118 unsigned long reg;
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)
128 unsigned long reg;
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)
139 unsigned long reg;
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)
150 unsigned long reg;
152 reg = readl(regs + S5P_JPGY_U);
153 reg &= ~0xff;
154 reg |= (y >> 8) & 0xff;
155 writel(reg, regs + S5P_JPGY_U);
157 reg = readl(regs + S5P_JPGY_L);
158 reg &= ~0xff;
159 reg |= y & 0xff;
160 writel(reg, regs + S5P_JPGY_L);
163 void s5p_jpeg_x(void __iomem *regs, unsigned int x)
165 unsigned long reg;
167 reg = readl(regs + S5P_JPGX_U);
168 reg &= ~0xff;
169 reg |= (x >> 8) & 0xff;
170 writel(reg, regs + S5P_JPGX_U);
172 reg = readl(regs + S5P_JPGX_L);
173 reg &= ~0xff;
174 reg |= x & 0xff;
175 writel(reg, regs + S5P_JPGX_L);
178 void s5p_jpeg_rst_int_enable(void __iomem *regs, bool enable)
180 unsigned long reg;
182 reg = readl(regs + S5P_JPGINTSE);
183 reg &= ~S5P_RSTm_INT_EN_MASK;
184 if (enable)
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)
191 unsigned long reg;
193 reg = readl(regs + S5P_JPGINTSE);
194 reg &= ~S5P_DATA_NUM_INT_EN_MASK;
195 if (enable)
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)
202 unsigned long reg;
204 reg = readl(regs + S5P_JPGINTSE);
205 reg &= ~S5P_FINAL_MCU_NUM_INT_EN_MASK;
206 if (enbl)
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)
213 unsigned long reg;
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)
224 unsigned long reg;
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)
239 unsigned long reg;
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)
248 unsigned long reg;
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)
265 unsigned long reg;
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;
283 reg |= f;
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)
300 unsigned long reg;
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)
327 unsigned long reg;
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;