1 /* Copyright (c) 2013 Samsung Electronics Co., Ltd.
2 * http://www.samsung.com/
4 * Author: Jacek Anaszewski <j.anaszewski@samsung.com>
6 * Register interface file for JPEG driver on Exynos4x12.
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/delay.h>
15 #include "jpeg-core.h"
16 #include "jpeg-hw-exynos4.h"
17 #include "jpeg-regs.h"
19 void exynos4_jpeg_sw_reset(void __iomem
*base
)
23 reg
= readl(base
+ EXYNOS4_JPEG_CNTL_REG
);
24 writel(reg
& ~EXYNOS4_SOFT_RESET_HI
, base
+ EXYNOS4_JPEG_CNTL_REG
);
28 writel(reg
| EXYNOS4_SOFT_RESET_HI
, base
+ EXYNOS4_JPEG_CNTL_REG
);
31 void exynos4_jpeg_set_enc_dec_mode(void __iomem
*base
, unsigned int mode
)
35 reg
= readl(base
+ EXYNOS4_JPEG_CNTL_REG
);
36 /* set exynos4_jpeg mod register */
37 if (mode
== S5P_JPEG_DECODE
) {
38 writel((reg
& EXYNOS4_ENC_DEC_MODE_MASK
) |
40 base
+ EXYNOS4_JPEG_CNTL_REG
);
42 writel((reg
& EXYNOS4_ENC_DEC_MODE_MASK
) |
44 base
+ EXYNOS4_JPEG_CNTL_REG
);
48 void exynos4_jpeg_set_img_fmt(void __iomem
*base
, unsigned int img_fmt
)
52 reg
= readl(base
+ EXYNOS4_IMG_FMT_REG
) &
53 EXYNOS4_ENC_IN_FMT_MASK
; /* clear except enc format */
56 case V4L2_PIX_FMT_GREY
:
57 reg
= reg
| EXYNOS4_ENC_GRAY_IMG
| EXYNOS4_GRAY_IMG_IP
;
59 case V4L2_PIX_FMT_RGB32
:
60 reg
= reg
| EXYNOS4_ENC_RGB_IMG
|
61 EXYNOS4_RGB_IP_RGB_32BIT_IMG
;
63 case V4L2_PIX_FMT_RGB565
:
64 reg
= reg
| EXYNOS4_ENC_RGB_IMG
|
65 EXYNOS4_RGB_IP_RGB_16BIT_IMG
;
67 case V4L2_PIX_FMT_NV24
:
68 reg
= reg
| EXYNOS4_ENC_YUV_444_IMG
|
69 EXYNOS4_YUV_444_IP_YUV_444_2P_IMG
|
70 EXYNOS4_SWAP_CHROMA_CBCR
;
72 case V4L2_PIX_FMT_NV42
:
73 reg
= reg
| EXYNOS4_ENC_YUV_444_IMG
|
74 EXYNOS4_YUV_444_IP_YUV_444_2P_IMG
|
75 EXYNOS4_SWAP_CHROMA_CRCB
;
77 case V4L2_PIX_FMT_YUYV
:
78 reg
= reg
| EXYNOS4_DEC_YUV_422_IMG
|
79 EXYNOS4_YUV_422_IP_YUV_422_1P_IMG
|
80 EXYNOS4_SWAP_CHROMA_CBCR
;
83 case V4L2_PIX_FMT_YVYU
:
84 reg
= reg
| EXYNOS4_DEC_YUV_422_IMG
|
85 EXYNOS4_YUV_422_IP_YUV_422_1P_IMG
|
86 EXYNOS4_SWAP_CHROMA_CRCB
;
88 case V4L2_PIX_FMT_NV16
:
89 reg
= reg
| EXYNOS4_DEC_YUV_422_IMG
|
90 EXYNOS4_YUV_422_IP_YUV_422_2P_IMG
|
91 EXYNOS4_SWAP_CHROMA_CBCR
;
93 case V4L2_PIX_FMT_NV61
:
94 reg
= reg
| EXYNOS4_DEC_YUV_422_IMG
|
95 EXYNOS4_YUV_422_IP_YUV_422_2P_IMG
|
96 EXYNOS4_SWAP_CHROMA_CRCB
;
98 case V4L2_PIX_FMT_NV12
:
99 reg
= reg
| EXYNOS4_DEC_YUV_420_IMG
|
100 EXYNOS4_YUV_420_IP_YUV_420_2P_IMG
|
101 EXYNOS4_SWAP_CHROMA_CBCR
;
103 case V4L2_PIX_FMT_NV21
:
104 reg
= reg
| EXYNOS4_DEC_YUV_420_IMG
|
105 EXYNOS4_YUV_420_IP_YUV_420_2P_IMG
|
106 EXYNOS4_SWAP_CHROMA_CRCB
;
108 case V4L2_PIX_FMT_YUV420
:
109 reg
= reg
| EXYNOS4_DEC_YUV_420_IMG
|
110 EXYNOS4_YUV_420_IP_YUV_420_3P_IMG
|
111 EXYNOS4_SWAP_CHROMA_CBCR
;
118 writel(reg
, base
+ EXYNOS4_IMG_FMT_REG
);
121 void exynos4_jpeg_set_enc_out_fmt(void __iomem
*base
, unsigned int out_fmt
)
125 reg
= readl(base
+ EXYNOS4_IMG_FMT_REG
) &
126 ~EXYNOS4_ENC_FMT_MASK
; /* clear enc format */
129 case V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY
:
130 reg
= reg
| EXYNOS4_ENC_FMT_GRAY
;
133 case V4L2_JPEG_CHROMA_SUBSAMPLING_444
:
134 reg
= reg
| EXYNOS4_ENC_FMT_YUV_444
;
137 case V4L2_JPEG_CHROMA_SUBSAMPLING_422
:
138 reg
= reg
| EXYNOS4_ENC_FMT_YUV_422
;
141 case V4L2_JPEG_CHROMA_SUBSAMPLING_420
:
142 reg
= reg
| EXYNOS4_ENC_FMT_YUV_420
;
149 writel(reg
, base
+ EXYNOS4_IMG_FMT_REG
);
152 void exynos4_jpeg_set_interrupt(void __iomem
*base
)
156 reg
= readl(base
+ EXYNOS4_INT_EN_REG
) & ~EXYNOS4_INT_EN_MASK
;
157 writel(EXYNOS4_INT_EN_ALL
, base
+ EXYNOS4_INT_EN_REG
);
160 unsigned int exynos4_jpeg_get_int_status(void __iomem
*base
)
162 unsigned int int_status
;
164 int_status
= readl(base
+ EXYNOS4_INT_STATUS_REG
);
169 unsigned int exynos4_jpeg_get_fifo_status(void __iomem
*base
)
171 unsigned int fifo_status
;
173 fifo_status
= readl(base
+ EXYNOS4_FIFO_STATUS_REG
);
178 void exynos4_jpeg_set_huf_table_enable(void __iomem
*base
, int value
)
182 reg
= readl(base
+ EXYNOS4_JPEG_CNTL_REG
) & ~EXYNOS4_HUF_TBL_EN
;
185 writel(reg
| EXYNOS4_HUF_TBL_EN
,
186 base
+ EXYNOS4_JPEG_CNTL_REG
);
188 writel(reg
| ~EXYNOS4_HUF_TBL_EN
,
189 base
+ EXYNOS4_JPEG_CNTL_REG
);
192 void exynos4_jpeg_set_sys_int_enable(void __iomem
*base
, int value
)
196 reg
= readl(base
+ EXYNOS4_JPEG_CNTL_REG
) & ~(EXYNOS4_SYS_INT_EN
);
199 writel(EXYNOS4_SYS_INT_EN
, base
+ EXYNOS4_JPEG_CNTL_REG
);
201 writel(~EXYNOS4_SYS_INT_EN
, base
+ EXYNOS4_JPEG_CNTL_REG
);
204 void exynos4_jpeg_set_stream_buf_address(void __iomem
*base
,
205 unsigned int address
)
207 writel(address
, base
+ EXYNOS4_OUT_MEM_BASE_REG
);
210 void exynos4_jpeg_set_stream_size(void __iomem
*base
,
211 unsigned int x_value
, unsigned int y_value
)
213 writel(0x0, base
+ EXYNOS4_JPEG_IMG_SIZE_REG
); /* clear */
214 writel(EXYNOS4_X_SIZE(x_value
) | EXYNOS4_Y_SIZE(y_value
),
215 base
+ EXYNOS4_JPEG_IMG_SIZE_REG
);
218 void exynos4_jpeg_set_frame_buf_address(void __iomem
*base
,
219 struct s5p_jpeg_addr
*exynos4_jpeg_addr
)
221 writel(exynos4_jpeg_addr
->y
, base
+ EXYNOS4_IMG_BA_PLANE_1_REG
);
222 writel(exynos4_jpeg_addr
->cb
, base
+ EXYNOS4_IMG_BA_PLANE_2_REG
);
223 writel(exynos4_jpeg_addr
->cr
, base
+ EXYNOS4_IMG_BA_PLANE_3_REG
);
226 void exynos4_jpeg_set_encode_tbl_select(void __iomem
*base
,
227 enum exynos4_jpeg_img_quality_level level
)
231 reg
= EXYNOS4_Q_TBL_COMP1_0
| EXYNOS4_Q_TBL_COMP2_1
|
232 EXYNOS4_Q_TBL_COMP3_1
|
233 EXYNOS4_HUFF_TBL_COMP1_AC_0_DC_1
|
234 EXYNOS4_HUFF_TBL_COMP2_AC_0_DC_0
|
235 EXYNOS4_HUFF_TBL_COMP3_AC_1_DC_1
;
237 writel(reg
, base
+ EXYNOS4_TBL_SEL_REG
);
240 void exynos4_jpeg_set_encode_hoff_cnt(void __iomem
*base
, unsigned int fmt
)
242 if (fmt
== V4L2_PIX_FMT_GREY
)
243 writel(0xd2, base
+ EXYNOS4_HUFF_CNT_REG
);
245 writel(0x1a2, base
+ EXYNOS4_HUFF_CNT_REG
);
248 unsigned int exynos4_jpeg_get_stream_size(void __iomem
*base
)
252 size
= readl(base
+ EXYNOS4_BITSTREAM_SIZE_REG
);
256 void exynos4_jpeg_set_dec_bitstream_size(void __iomem
*base
, unsigned int size
)
258 writel(size
, base
+ EXYNOS4_BITSTREAM_SIZE_REG
);
261 void exynos4_jpeg_get_frame_size(void __iomem
*base
,
262 unsigned int *width
, unsigned int *height
)
264 *width
= (readl(base
+ EXYNOS4_DECODE_XY_SIZE_REG
) &
265 EXYNOS4_DECODED_SIZE_MASK
);
266 *height
= (readl(base
+ EXYNOS4_DECODE_XY_SIZE_REG
) >> 16) &
267 EXYNOS4_DECODED_SIZE_MASK
;
270 unsigned int exynos4_jpeg_get_frame_fmt(void __iomem
*base
)
272 return readl(base
+ EXYNOS4_DECODE_IMG_FMT_REG
) &
273 EXYNOS4_JPEG_DECODED_IMG_FMT_MASK
;
276 void exynos4_jpeg_set_timer_count(void __iomem
*base
, unsigned int size
)
278 writel(size
, base
+ EXYNOS4_INT_TIMER_COUNT_REG
);