1 /* linux/drivers/media/platform/exynos3250-jpeg/jpeg-hw.h
3 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
6 * Author: Jacek Anaszewski <j.anaszewski@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>
15 #include <linux/delay.h>
17 #include "jpeg-core.h"
18 #include "jpeg-regs.h"
19 #include "jpeg-hw-exynos3250.h"
21 void exynos3250_jpeg_reset(void __iomem
*regs
)
26 writel(1, regs
+ EXYNOS3250_SW_RESET
);
27 /* no other way but polling for when JPEG IP becomes operational */
28 while (reg
!= 0 && --count
> 0) {
31 reg
= readl(regs
+ EXYNOS3250_SW_RESET
);
37 while (reg
!= 1 && --count
> 0) {
38 writel(1, regs
+ EXYNOS3250_JPGDRI
);
41 reg
= readl(regs
+ EXYNOS3250_JPGDRI
);
44 writel(0, regs
+ EXYNOS3250_JPGDRI
);
47 void exynos3250_jpeg_poweron(void __iomem
*regs
)
49 writel(EXYNOS3250_POWER_ON
, regs
+ EXYNOS3250_JPGCLKCON
);
52 void exynos3250_jpeg_set_dma_num(void __iomem
*regs
)
54 writel(((EXYNOS3250_DMA_MO_COUNT
<< EXYNOS3250_WDMA_ISSUE_NUM_SHIFT
) &
55 EXYNOS3250_WDMA_ISSUE_NUM_MASK
) |
56 ((EXYNOS3250_DMA_MO_COUNT
<< EXYNOS3250_RDMA_ISSUE_NUM_SHIFT
) &
57 EXYNOS3250_RDMA_ISSUE_NUM_MASK
) |
58 ((EXYNOS3250_DMA_MO_COUNT
<< EXYNOS3250_ISSUE_GATHER_NUM_SHIFT
) &
59 EXYNOS3250_ISSUE_GATHER_NUM_MASK
),
60 regs
+ EXYNOS3250_DMA_ISSUE_NUM
);
63 void exynos3250_jpeg_clk_set(void __iomem
*base
)
67 reg
= readl(base
+ EXYNOS3250_JPGCMOD
) & ~EXYNOS3250_HALF_EN_MASK
;
69 writel(reg
| EXYNOS3250_HALF_EN
, base
+ EXYNOS3250_JPGCMOD
);
72 void exynos3250_jpeg_input_raw_fmt(void __iomem
*regs
, unsigned int fmt
)
76 reg
= readl(regs
+ EXYNOS3250_JPGCMOD
) &
77 EXYNOS3250_MODE_Y16_MASK
;
80 case V4L2_PIX_FMT_RGB32
:
81 reg
|= EXYNOS3250_MODE_SEL_ARGB8888
;
83 case V4L2_PIX_FMT_BGR32
:
84 reg
|= EXYNOS3250_MODE_SEL_ARGB8888
| EXYNOS3250_SRC_SWAP_RGB
;
86 case V4L2_PIX_FMT_RGB565
:
87 reg
|= EXYNOS3250_MODE_SEL_RGB565
;
89 case V4L2_PIX_FMT_RGB565X
:
90 reg
|= EXYNOS3250_MODE_SEL_RGB565
| EXYNOS3250_SRC_SWAP_RGB
;
92 case V4L2_PIX_FMT_YUYV
:
93 reg
|= EXYNOS3250_MODE_SEL_422_1P_LUM_CHR
;
95 case V4L2_PIX_FMT_YVYU
:
96 reg
|= EXYNOS3250_MODE_SEL_422_1P_LUM_CHR
|
97 EXYNOS3250_SRC_SWAP_UV
;
99 case V4L2_PIX_FMT_UYVY
:
100 reg
|= EXYNOS3250_MODE_SEL_422_1P_CHR_LUM
;
102 case V4L2_PIX_FMT_VYUY
:
103 reg
|= EXYNOS3250_MODE_SEL_422_1P_CHR_LUM
|
104 EXYNOS3250_SRC_SWAP_UV
;
106 case V4L2_PIX_FMT_NV12
:
107 reg
|= EXYNOS3250_MODE_SEL_420_2P
| EXYNOS3250_SRC_NV12
;
109 case V4L2_PIX_FMT_NV21
:
110 reg
|= EXYNOS3250_MODE_SEL_420_2P
| EXYNOS3250_SRC_NV21
;
112 case V4L2_PIX_FMT_YUV420
:
113 reg
|= EXYNOS3250_MODE_SEL_420_3P
;
120 writel(reg
, regs
+ EXYNOS3250_JPGCMOD
);
123 void exynos3250_jpeg_set_y16(void __iomem
*regs
, bool y16
)
127 reg
= readl(regs
+ EXYNOS3250_JPGCMOD
);
129 reg
|= EXYNOS3250_MODE_Y16
;
131 reg
&= ~EXYNOS3250_MODE_Y16_MASK
;
132 writel(reg
, regs
+ EXYNOS3250_JPGCMOD
);
135 void exynos3250_jpeg_proc_mode(void __iomem
*regs
, unsigned int mode
)
139 if (mode
== S5P_JPEG_ENCODE
)
140 m
= EXYNOS3250_PROC_MODE_COMPR
;
142 m
= EXYNOS3250_PROC_MODE_DECOMPR
;
143 reg
= readl(regs
+ EXYNOS3250_JPGMOD
);
144 reg
&= ~EXYNOS3250_PROC_MODE_MASK
;
146 writel(reg
, regs
+ EXYNOS3250_JPGMOD
);
149 void exynos3250_jpeg_subsampling_mode(void __iomem
*regs
, unsigned int mode
)
154 case V4L2_JPEG_CHROMA_SUBSAMPLING_444
:
155 m
= EXYNOS3250_SUBSAMPLING_MODE_444
;
157 case V4L2_JPEG_CHROMA_SUBSAMPLING_422
:
158 m
= EXYNOS3250_SUBSAMPLING_MODE_422
;
160 case V4L2_JPEG_CHROMA_SUBSAMPLING_420
:
161 m
= EXYNOS3250_SUBSAMPLING_MODE_420
;
165 reg
= readl(regs
+ EXYNOS3250_JPGMOD
);
166 reg
&= ~EXYNOS3250_SUBSAMPLING_MODE_MASK
;
168 writel(reg
, regs
+ EXYNOS3250_JPGMOD
);
171 unsigned int exynos3250_jpeg_get_subsampling_mode(void __iomem
*regs
)
173 return readl(regs
+ EXYNOS3250_JPGMOD
) &
174 EXYNOS3250_SUBSAMPLING_MODE_MASK
;
177 void exynos3250_jpeg_dri(void __iomem
*regs
, unsigned int dri
)
181 reg
= dri
& EXYNOS3250_JPGDRI_MASK
;
182 writel(reg
, regs
+ EXYNOS3250_JPGDRI
);
185 void exynos3250_jpeg_qtbl(void __iomem
*regs
, unsigned int t
, unsigned int n
)
189 reg
= readl(regs
+ EXYNOS3250_QHTBL
);
190 reg
&= ~EXYNOS3250_QT_NUM_MASK(t
);
191 reg
|= (n
<< EXYNOS3250_QT_NUM_SHIFT(t
)) &
192 EXYNOS3250_QT_NUM_MASK(t
);
193 writel(reg
, regs
+ EXYNOS3250_QHTBL
);
196 void exynos3250_jpeg_htbl_ac(void __iomem
*regs
, unsigned int t
)
200 reg
= readl(regs
+ EXYNOS3250_QHTBL
);
201 reg
&= ~EXYNOS3250_HT_NUM_AC_MASK(t
);
202 /* this driver uses table 0 for all color components */
203 reg
|= (0 << EXYNOS3250_HT_NUM_AC_SHIFT(t
)) &
204 EXYNOS3250_HT_NUM_AC_MASK(t
);
205 writel(reg
, regs
+ EXYNOS3250_QHTBL
);
208 void exynos3250_jpeg_htbl_dc(void __iomem
*regs
, unsigned int t
)
212 reg
= readl(regs
+ EXYNOS3250_QHTBL
);
213 reg
&= ~EXYNOS3250_HT_NUM_DC_MASK(t
);
214 /* this driver uses table 0 for all color components */
215 reg
|= (0 << EXYNOS3250_HT_NUM_DC_SHIFT(t
)) &
216 EXYNOS3250_HT_NUM_DC_MASK(t
);
217 writel(reg
, regs
+ EXYNOS3250_QHTBL
);
220 void exynos3250_jpeg_set_y(void __iomem
*regs
, unsigned int y
)
224 reg
= y
& EXYNOS3250_JPGY_MASK
;
225 writel(reg
, regs
+ EXYNOS3250_JPGY
);
228 void exynos3250_jpeg_set_x(void __iomem
*regs
, unsigned int x
)
232 reg
= x
& EXYNOS3250_JPGX_MASK
;
233 writel(reg
, regs
+ EXYNOS3250_JPGX
);
236 #if 0 /* Currently unused */
237 unsigned int exynos3250_jpeg_get_y(void __iomem
*regs
)
239 return readl(regs
+ EXYNOS3250_JPGY
);
242 unsigned int exynos3250_jpeg_get_x(void __iomem
*regs
)
244 return readl(regs
+ EXYNOS3250_JPGX
);
248 void exynos3250_jpeg_interrupts_enable(void __iomem
*regs
)
252 reg
= readl(regs
+ EXYNOS3250_JPGINTSE
);
253 reg
|= (EXYNOS3250_JPEG_DONE_EN
|
254 EXYNOS3250_WDMA_DONE_EN
|
255 EXYNOS3250_RDMA_DONE_EN
|
256 EXYNOS3250_ENC_STREAM_INT_EN
|
257 EXYNOS3250_CORE_DONE_EN
|
258 EXYNOS3250_ERR_INT_EN
|
259 EXYNOS3250_HEAD_INT_EN
);
260 writel(reg
, regs
+ EXYNOS3250_JPGINTSE
);
263 void exynos3250_jpeg_enc_stream_bound(void __iomem
*regs
, unsigned int size
)
267 reg
= size
& EXYNOS3250_ENC_STREAM_BOUND_MASK
;
268 writel(reg
, regs
+ EXYNOS3250_ENC_STREAM_BOUND
);
271 void exynos3250_jpeg_output_raw_fmt(void __iomem
*regs
, unsigned int fmt
)
276 case V4L2_PIX_FMT_RGB32
:
277 reg
= EXYNOS3250_OUT_FMT_ARGB8888
;
279 case V4L2_PIX_FMT_BGR32
:
280 reg
= EXYNOS3250_OUT_FMT_ARGB8888
| EXYNOS3250_OUT_SWAP_RGB
;
282 case V4L2_PIX_FMT_RGB565
:
283 reg
= EXYNOS3250_OUT_FMT_RGB565
;
285 case V4L2_PIX_FMT_RGB565X
:
286 reg
= EXYNOS3250_OUT_FMT_RGB565
| EXYNOS3250_OUT_SWAP_RGB
;
288 case V4L2_PIX_FMT_YUYV
:
289 reg
= EXYNOS3250_OUT_FMT_422_1P_LUM_CHR
;
291 case V4L2_PIX_FMT_YVYU
:
292 reg
= EXYNOS3250_OUT_FMT_422_1P_LUM_CHR
|
293 EXYNOS3250_OUT_SWAP_UV
;
295 case V4L2_PIX_FMT_UYVY
:
296 reg
= EXYNOS3250_OUT_FMT_422_1P_CHR_LUM
;
298 case V4L2_PIX_FMT_VYUY
:
299 reg
= EXYNOS3250_OUT_FMT_422_1P_CHR_LUM
|
300 EXYNOS3250_OUT_SWAP_UV
;
302 case V4L2_PIX_FMT_NV12
:
303 reg
= EXYNOS3250_OUT_FMT_420_2P
| EXYNOS3250_OUT_NV12
;
305 case V4L2_PIX_FMT_NV21
:
306 reg
= EXYNOS3250_OUT_FMT_420_2P
| EXYNOS3250_OUT_NV21
;
308 case V4L2_PIX_FMT_YUV420
:
309 reg
= EXYNOS3250_OUT_FMT_420_3P
;
316 writel(reg
, regs
+ EXYNOS3250_OUTFORM
);
319 void exynos3250_jpeg_jpgadr(void __iomem
*regs
, unsigned int addr
)
321 writel(addr
, regs
+ EXYNOS3250_JPG_JPGADR
);
324 void exynos3250_jpeg_imgadr(void __iomem
*regs
, struct s5p_jpeg_addr
*img_addr
)
326 writel(img_addr
->y
, regs
+ EXYNOS3250_LUMA_BASE
);
327 writel(img_addr
->cb
, regs
+ EXYNOS3250_CHROMA_BASE
);
328 writel(img_addr
->cr
, regs
+ EXYNOS3250_CHROMA_CR_BASE
);
331 void exynos3250_jpeg_stride(void __iomem
*regs
, unsigned int img_fmt
,
334 u32 reg_luma
= 0, reg_cr
= 0, reg_cb
= 0;
337 case V4L2_PIX_FMT_RGB32
:
338 reg_luma
= 4 * width
;
340 case V4L2_PIX_FMT_RGB565
:
341 case V4L2_PIX_FMT_RGB565X
:
342 case V4L2_PIX_FMT_YUYV
:
343 case V4L2_PIX_FMT_YVYU
:
344 case V4L2_PIX_FMT_UYVY
:
345 case V4L2_PIX_FMT_VYUY
:
346 reg_luma
= 2 * width
;
348 case V4L2_PIX_FMT_NV12
:
349 case V4L2_PIX_FMT_NV21
:
353 case V4L2_PIX_FMT_YUV420
:
355 reg_cb
= reg_cr
= reg_luma
/ 2;
361 writel(reg_luma
, regs
+ EXYNOS3250_LUMA_STRIDE
);
362 writel(reg_cb
, regs
+ EXYNOS3250_CHROMA_STRIDE
);
363 writel(reg_cr
, regs
+ EXYNOS3250_CHROMA_CR_STRIDE
);
366 void exynos3250_jpeg_offset(void __iomem
*regs
, unsigned int x_offset
,
367 unsigned int y_offset
)
371 reg
= (y_offset
<< EXYNOS3250_LUMA_YY_OFFSET_SHIFT
) &
372 EXYNOS3250_LUMA_YY_OFFSET_MASK
;
373 reg
|= (x_offset
<< EXYNOS3250_LUMA_YX_OFFSET_SHIFT
) &
374 EXYNOS3250_LUMA_YX_OFFSET_MASK
;
376 writel(reg
, regs
+ EXYNOS3250_LUMA_XY_OFFSET
);
378 reg
= (y_offset
<< EXYNOS3250_CHROMA_YY_OFFSET_SHIFT
) &
379 EXYNOS3250_CHROMA_YY_OFFSET_MASK
;
380 reg
|= (x_offset
<< EXYNOS3250_CHROMA_YX_OFFSET_SHIFT
) &
381 EXYNOS3250_CHROMA_YX_OFFSET_MASK
;
383 writel(reg
, regs
+ EXYNOS3250_CHROMA_XY_OFFSET
);
385 reg
= (y_offset
<< EXYNOS3250_CHROMA_CR_YY_OFFSET_SHIFT
) &
386 EXYNOS3250_CHROMA_CR_YY_OFFSET_MASK
;
387 reg
|= (x_offset
<< EXYNOS3250_CHROMA_CR_YX_OFFSET_SHIFT
) &
388 EXYNOS3250_CHROMA_CR_YX_OFFSET_MASK
;
390 writel(reg
, regs
+ EXYNOS3250_CHROMA_CR_XY_OFFSET
);
393 void exynos3250_jpeg_coef(void __iomem
*base
, unsigned int mode
)
395 if (mode
== S5P_JPEG_ENCODE
) {
396 writel(EXYNOS3250_JPEG_ENC_COEF1
,
397 base
+ EXYNOS3250_JPG_COEF(1));
398 writel(EXYNOS3250_JPEG_ENC_COEF2
,
399 base
+ EXYNOS3250_JPG_COEF(2));
400 writel(EXYNOS3250_JPEG_ENC_COEF3
,
401 base
+ EXYNOS3250_JPG_COEF(3));
403 writel(EXYNOS3250_JPEG_DEC_COEF1
,
404 base
+ EXYNOS3250_JPG_COEF(1));
405 writel(EXYNOS3250_JPEG_DEC_COEF2
,
406 base
+ EXYNOS3250_JPG_COEF(2));
407 writel(EXYNOS3250_JPEG_DEC_COEF3
,
408 base
+ EXYNOS3250_JPG_COEF(3));
412 void exynos3250_jpeg_start(void __iomem
*regs
)
414 writel(1, regs
+ EXYNOS3250_JSTART
);
417 void exynos3250_jpeg_rstart(void __iomem
*regs
)
419 writel(1, regs
+ EXYNOS3250_JRSTART
);
422 unsigned int exynos3250_jpeg_get_int_status(void __iomem
*regs
)
424 return readl(regs
+ EXYNOS3250_JPGINTST
);
427 void exynos3250_jpeg_clear_int_status(void __iomem
*regs
,
430 return writel(value
, regs
+ EXYNOS3250_JPGINTST
);
433 unsigned int exynos3250_jpeg_operating(void __iomem
*regs
)
435 return readl(regs
+ S5P_JPGOPR
) & EXYNOS3250_JPGOPR_MASK
;
438 unsigned int exynos3250_jpeg_compressed_size(void __iomem
*regs
)
440 return readl(regs
+ EXYNOS3250_JPGCNT
) & EXYNOS3250_JPGCNT_MASK
;
443 void exynos3250_jpeg_dec_stream_size(void __iomem
*regs
,
446 writel(size
& EXYNOS3250_DEC_STREAM_MASK
,
447 regs
+ EXYNOS3250_DEC_STREAM_SIZE
);
450 void exynos3250_jpeg_dec_scaling_ratio(void __iomem
*regs
,
456 sratio
= EXYNOS3250_DEC_SCALE_FACTOR_8_8
;
459 sratio
= EXYNOS3250_DEC_SCALE_FACTOR_4_8
;
462 sratio
= EXYNOS3250_DEC_SCALE_FACTOR_2_8
;
465 sratio
= EXYNOS3250_DEC_SCALE_FACTOR_1_8
;
469 writel(sratio
& EXYNOS3250_DEC_SCALE_FACTOR_MASK
,
470 regs
+ EXYNOS3250_DEC_SCALING_RATIO
);
473 void exynos3250_jpeg_set_timer(void __iomem
*regs
, unsigned int time_value
)
475 time_value
&= EXYNOS3250_TIMER_INIT_MASK
;
477 writel(EXYNOS3250_TIMER_INT_STAT
| time_value
,
478 regs
+ EXYNOS3250_TIMER_SE
);
481 unsigned int exynos3250_jpeg_get_timer_status(void __iomem
*regs
)
483 return readl(regs
+ EXYNOS3250_TIMER_ST
);
486 void exynos3250_jpeg_clear_timer_status(void __iomem
*regs
)
488 writel(EXYNOS3250_TIMER_INT_STAT
, regs
+ EXYNOS3250_TIMER_ST
);