Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / media / platform / s5p-jpeg / jpeg-hw-exynos4.c
blob0828cfa783fedadd76661d4dd9bb4ddc1405d1ec
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2013 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com/
5 * Author: Jacek Anaszewski <j.anaszewski@samsung.com>
7 * Register interface file for JPEG driver on Exynos4x12.
8 */
9 #include <linux/io.h>
10 #include <linux/delay.h>
12 #include "jpeg-core.h"
13 #include "jpeg-hw-exynos4.h"
14 #include "jpeg-regs.h"
16 void exynos4_jpeg_sw_reset(void __iomem *base)
18 unsigned int reg;
20 reg = readl(base + EXYNOS4_JPEG_CNTL_REG);
21 writel(reg & ~(EXYNOS4_DEC_MODE | EXYNOS4_ENC_MODE),
22 base + EXYNOS4_JPEG_CNTL_REG);
24 reg = readl(base + EXYNOS4_JPEG_CNTL_REG);
25 writel(reg & ~EXYNOS4_SOFT_RESET_HI, base + EXYNOS4_JPEG_CNTL_REG);
27 udelay(100);
29 writel(reg | EXYNOS4_SOFT_RESET_HI, base + EXYNOS4_JPEG_CNTL_REG);
32 void exynos4_jpeg_set_enc_dec_mode(void __iomem *base, unsigned int mode)
34 unsigned int reg;
36 reg = readl(base + EXYNOS4_JPEG_CNTL_REG);
37 /* set exynos4_jpeg mod register */
38 if (mode == S5P_JPEG_DECODE) {
39 writel((reg & EXYNOS4_ENC_DEC_MODE_MASK) |
40 EXYNOS4_DEC_MODE,
41 base + EXYNOS4_JPEG_CNTL_REG);
42 } else if (mode == S5P_JPEG_ENCODE) {/* encode */
43 writel((reg & EXYNOS4_ENC_DEC_MODE_MASK) |
44 EXYNOS4_ENC_MODE,
45 base + EXYNOS4_JPEG_CNTL_REG);
46 } else { /* disable both */
47 writel(reg & EXYNOS4_ENC_DEC_MODE_MASK,
48 base + EXYNOS4_JPEG_CNTL_REG);
52 void __exynos4_jpeg_set_img_fmt(void __iomem *base, unsigned int img_fmt,
53 unsigned int version)
55 unsigned int reg;
56 unsigned int exynos4_swap_chroma_cbcr;
57 unsigned int exynos4_swap_chroma_crcb;
59 if (version == SJPEG_EXYNOS4) {
60 exynos4_swap_chroma_cbcr = EXYNOS4_SWAP_CHROMA_CBCR;
61 exynos4_swap_chroma_crcb = EXYNOS4_SWAP_CHROMA_CRCB;
62 } else {
63 exynos4_swap_chroma_cbcr = EXYNOS5433_SWAP_CHROMA_CBCR;
64 exynos4_swap_chroma_crcb = EXYNOS5433_SWAP_CHROMA_CRCB;
67 reg = readl(base + EXYNOS4_IMG_FMT_REG) &
68 EXYNOS4_ENC_IN_FMT_MASK; /* clear except enc format */
70 switch (img_fmt) {
71 case V4L2_PIX_FMT_GREY:
72 reg = reg | EXYNOS4_ENC_GRAY_IMG | EXYNOS4_GRAY_IMG_IP;
73 break;
74 case V4L2_PIX_FMT_RGB32:
75 reg = reg | EXYNOS4_ENC_RGB_IMG |
76 EXYNOS4_RGB_IP_RGB_32BIT_IMG;
77 break;
78 case V4L2_PIX_FMT_RGB565:
79 reg = reg | EXYNOS4_ENC_RGB_IMG |
80 EXYNOS4_RGB_IP_RGB_16BIT_IMG;
81 break;
82 case V4L2_PIX_FMT_NV24:
83 reg = reg | EXYNOS4_ENC_YUV_444_IMG |
84 EXYNOS4_YUV_444_IP_YUV_444_2P_IMG |
85 exynos4_swap_chroma_cbcr;
86 break;
87 case V4L2_PIX_FMT_NV42:
88 reg = reg | EXYNOS4_ENC_YUV_444_IMG |
89 EXYNOS4_YUV_444_IP_YUV_444_2P_IMG |
90 exynos4_swap_chroma_crcb;
91 break;
92 case V4L2_PIX_FMT_YUYV:
93 reg = reg | EXYNOS4_DEC_YUV_422_IMG |
94 EXYNOS4_YUV_422_IP_YUV_422_1P_IMG |
95 exynos4_swap_chroma_cbcr;
96 break;
98 case V4L2_PIX_FMT_YVYU:
99 reg = reg | EXYNOS4_DEC_YUV_422_IMG |
100 EXYNOS4_YUV_422_IP_YUV_422_1P_IMG |
101 exynos4_swap_chroma_crcb;
102 break;
103 case V4L2_PIX_FMT_NV16:
104 reg = reg | EXYNOS4_DEC_YUV_422_IMG |
105 EXYNOS4_YUV_422_IP_YUV_422_2P_IMG |
106 exynos4_swap_chroma_cbcr;
107 break;
108 case V4L2_PIX_FMT_NV61:
109 reg = reg | EXYNOS4_DEC_YUV_422_IMG |
110 EXYNOS4_YUV_422_IP_YUV_422_2P_IMG |
111 exynos4_swap_chroma_crcb;
112 break;
113 case V4L2_PIX_FMT_NV12:
114 reg = reg | EXYNOS4_DEC_YUV_420_IMG |
115 EXYNOS4_YUV_420_IP_YUV_420_2P_IMG |
116 exynos4_swap_chroma_cbcr;
117 break;
118 case V4L2_PIX_FMT_NV21:
119 reg = reg | EXYNOS4_DEC_YUV_420_IMG |
120 EXYNOS4_YUV_420_IP_YUV_420_2P_IMG |
121 exynos4_swap_chroma_crcb;
122 break;
123 case V4L2_PIX_FMT_YUV420:
124 reg = reg | EXYNOS4_DEC_YUV_420_IMG |
125 EXYNOS4_YUV_420_IP_YUV_420_3P_IMG |
126 exynos4_swap_chroma_cbcr;
127 break;
128 default:
129 break;
133 writel(reg, base + EXYNOS4_IMG_FMT_REG);
136 void __exynos4_jpeg_set_enc_out_fmt(void __iomem *base, unsigned int out_fmt,
137 unsigned int version)
139 unsigned int reg;
141 reg = readl(base + EXYNOS4_IMG_FMT_REG) &
142 ~(version == SJPEG_EXYNOS4 ? EXYNOS4_ENC_FMT_MASK :
143 EXYNOS5433_ENC_FMT_MASK); /* clear enc format */
145 switch (out_fmt) {
146 case V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY:
147 reg = reg | EXYNOS4_ENC_FMT_GRAY;
148 break;
150 case V4L2_JPEG_CHROMA_SUBSAMPLING_444:
151 reg = reg | EXYNOS4_ENC_FMT_YUV_444;
152 break;
154 case V4L2_JPEG_CHROMA_SUBSAMPLING_422:
155 reg = reg | EXYNOS4_ENC_FMT_YUV_422;
156 break;
158 case V4L2_JPEG_CHROMA_SUBSAMPLING_420:
159 reg = reg | EXYNOS4_ENC_FMT_YUV_420;
160 break;
162 default:
163 break;
166 writel(reg, base + EXYNOS4_IMG_FMT_REG);
169 void exynos4_jpeg_set_interrupt(void __iomem *base, unsigned int version)
171 unsigned int reg;
173 if (version == SJPEG_EXYNOS4) {
174 reg = readl(base + EXYNOS4_INT_EN_REG) & ~EXYNOS4_INT_EN_MASK;
175 writel(reg | EXYNOS4_INT_EN_ALL, base + EXYNOS4_INT_EN_REG);
176 } else {
177 reg = readl(base + EXYNOS4_INT_EN_REG) &
178 ~EXYNOS5433_INT_EN_MASK;
179 writel(reg | EXYNOS5433_INT_EN_ALL, base + EXYNOS4_INT_EN_REG);
183 unsigned int exynos4_jpeg_get_int_status(void __iomem *base)
185 return readl(base + EXYNOS4_INT_STATUS_REG);
188 unsigned int exynos4_jpeg_get_fifo_status(void __iomem *base)
190 return readl(base + EXYNOS4_FIFO_STATUS_REG);
193 void exynos4_jpeg_set_huf_table_enable(void __iomem *base, int value)
195 unsigned int reg;
197 reg = readl(base + EXYNOS4_JPEG_CNTL_REG) & ~EXYNOS4_HUF_TBL_EN;
199 if (value == 1)
200 writel(reg | EXYNOS4_HUF_TBL_EN,
201 base + EXYNOS4_JPEG_CNTL_REG);
202 else
203 writel(reg & ~EXYNOS4_HUF_TBL_EN,
204 base + EXYNOS4_JPEG_CNTL_REG);
207 void exynos4_jpeg_set_sys_int_enable(void __iomem *base, int value)
209 unsigned int reg;
211 reg = readl(base + EXYNOS4_JPEG_CNTL_REG) & ~(EXYNOS4_SYS_INT_EN);
213 if (value == 1)
214 writel(reg | EXYNOS4_SYS_INT_EN, base + EXYNOS4_JPEG_CNTL_REG);
215 else
216 writel(reg & ~EXYNOS4_SYS_INT_EN, base + EXYNOS4_JPEG_CNTL_REG);
219 void exynos4_jpeg_set_stream_buf_address(void __iomem *base,
220 unsigned int address)
222 writel(address, base + EXYNOS4_OUT_MEM_BASE_REG);
225 void exynos4_jpeg_set_stream_size(void __iomem *base,
226 unsigned int x_value, unsigned int y_value)
228 writel(0x0, base + EXYNOS4_JPEG_IMG_SIZE_REG); /* clear */
229 writel(EXYNOS4_X_SIZE(x_value) | EXYNOS4_Y_SIZE(y_value),
230 base + EXYNOS4_JPEG_IMG_SIZE_REG);
233 void exynos4_jpeg_set_frame_buf_address(void __iomem *base,
234 struct s5p_jpeg_addr *exynos4_jpeg_addr)
236 writel(exynos4_jpeg_addr->y, base + EXYNOS4_IMG_BA_PLANE_1_REG);
237 writel(exynos4_jpeg_addr->cb, base + EXYNOS4_IMG_BA_PLANE_2_REG);
238 writel(exynos4_jpeg_addr->cr, base + EXYNOS4_IMG_BA_PLANE_3_REG);
241 void exynos4_jpeg_set_encode_tbl_select(void __iomem *base,
242 enum exynos4_jpeg_img_quality_level level)
244 unsigned int reg;
246 reg = EXYNOS4_Q_TBL_COMP1_0 | EXYNOS4_Q_TBL_COMP2_1 |
247 EXYNOS4_Q_TBL_COMP3_1 |
248 EXYNOS4_HUFF_TBL_COMP1_AC_0_DC_1 |
249 EXYNOS4_HUFF_TBL_COMP2_AC_0_DC_0 |
250 EXYNOS4_HUFF_TBL_COMP3_AC_1_DC_1;
252 writel(reg, base + EXYNOS4_TBL_SEL_REG);
255 void exynos4_jpeg_set_dec_components(void __iomem *base, int n)
257 unsigned int reg;
259 reg = readl(base + EXYNOS4_TBL_SEL_REG);
261 reg |= EXYNOS4_NF(n);
262 writel(reg, base + EXYNOS4_TBL_SEL_REG);
265 void exynos4_jpeg_select_dec_q_tbl(void __iomem *base, char c, char x)
267 unsigned int reg;
269 reg = readl(base + EXYNOS4_TBL_SEL_REG);
271 reg |= EXYNOS4_Q_TBL_COMP(c, x);
272 writel(reg, base + EXYNOS4_TBL_SEL_REG);
275 void exynos4_jpeg_select_dec_h_tbl(void __iomem *base, char c, char x)
277 unsigned int reg;
279 reg = readl(base + EXYNOS4_TBL_SEL_REG);
281 reg |= EXYNOS4_HUFF_TBL_COMP(c, x);
282 writel(reg, base + EXYNOS4_TBL_SEL_REG);
285 void exynos4_jpeg_set_encode_hoff_cnt(void __iomem *base, unsigned int fmt)
287 if (fmt == V4L2_PIX_FMT_GREY)
288 writel(0xd2, base + EXYNOS4_HUFF_CNT_REG);
289 else
290 writel(0x1a2, base + EXYNOS4_HUFF_CNT_REG);
293 unsigned int exynos4_jpeg_get_stream_size(void __iomem *base)
295 return readl(base + EXYNOS4_BITSTREAM_SIZE_REG);
298 void exynos4_jpeg_set_dec_bitstream_size(void __iomem *base, unsigned int size)
300 writel(size, base + EXYNOS4_BITSTREAM_SIZE_REG);
303 void exynos4_jpeg_get_frame_size(void __iomem *base,
304 unsigned int *width, unsigned int *height)
306 *width = (readl(base + EXYNOS4_DECODE_XY_SIZE_REG) &
307 EXYNOS4_DECODED_SIZE_MASK);
308 *height = (readl(base + EXYNOS4_DECODE_XY_SIZE_REG) >> 16) &
309 EXYNOS4_DECODED_SIZE_MASK;
312 unsigned int exynos4_jpeg_get_frame_fmt(void __iomem *base)
314 return readl(base + EXYNOS4_DECODE_IMG_FMT_REG) &
315 EXYNOS4_JPEG_DECODED_IMG_FMT_MASK;
318 void exynos4_jpeg_set_timer_count(void __iomem *base, unsigned int size)
320 writel(size, base + EXYNOS4_INT_TIMER_COUNT_REG);