summaryrefslogtreecommitdiff
path: root/drivers/media/video/s5p-jpeg/jpeg-hw.h
blob: e10c744e9f2390852d4030b584f5c8dd32bced2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/* linux/drivers/media/video/s5p-jpeg/jpeg-hw.h
 *
 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
 *		http://www.samsung.com
 *
 * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#ifndef JPEG_HW_H_
#define JPEG_HW_H_

#include <linux/io.h>

#include "jpeg-hw.h"
#include "jpeg-regs.h"

#define S5P_JPEG_MIN_WIDTH		32
#define S5P_JPEG_MIN_HEIGHT		32
#define S5P_JPEG_MAX_WIDTH		8192
#define S5P_JPEG_MAX_HEIGHT		8192
#define S5P_JPEG_ENCODE			0
#define S5P_JPEG_DECODE			1
#define S5P_JPEG_RAW_IN_565		0
#define S5P_JPEG_RAW_IN_422		1
#define S5P_JPEG_SUBSAMPLING_422	0
#define S5P_JPEG_SUBSAMPLING_420	1
#define S5P_JPEG_RAW_OUT_422		0
#define S5P_JPEG_RAW_OUT_420		1

static inline void jpeg_reset(void __iomem *regs)
{
	unsigned long reg;

	writel(1, regs + S5P_JPG_SW_RESET);
	reg = readl(regs + S5P_JPG_SW_RESET);
	/* no other way but polling for when JPEG IP becomes operational */
	while (reg != 0) {
		cpu_relax();
		reg = readl(regs + S5P_JPG_SW_RESET);
	}
}

static inline void jpeg_poweron(void __iomem *regs)
{
	writel(S5P_POWER_ON, regs + S5P_JPGCLKCON);
}

static inline void jpeg_input_raw_mode(void __iomem *regs, unsigned long mode)
{
	unsigned long reg, m;

	m = S5P_MOD_SEL_565;
	if (mode == S5P_JPEG_RAW_IN_565)
		m = S5P_MOD_SEL_565;
	else if (mode == S5P_JPEG_RAW_IN_422)
		m = S5P_MOD_SEL_422;

	reg = readl(regs + S5P_JPGCMOD);
	reg &= ~S5P_MOD_SEL_MASK;
	reg |= m;
	writel(reg, regs + S5P_JPGCMOD);
}

static inline void jpeg_input_raw_y16(void __iomem *regs, bool y16)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPGCMOD);
	if (y16)
		reg |= S5P_MODE_Y16;
	else
		reg &= ~S5P_MODE_Y16_MASK;
	writel(reg, regs + S5P_JPGCMOD);
}

static inline void jpeg_proc_mode(void __iomem *regs, unsigned long mode)
{
	unsigned long reg, m;

	m = S5P_PROC_MODE_DECOMPR;
	if (mode == S5P_JPEG_ENCODE)
		m = S5P_PROC_MODE_COMPR;
	else
		m = S5P_PROC_MODE_DECOMPR;
	reg = readl(regs + S5P_JPGMOD);
	reg &= ~S5P_PROC_MODE_MASK;
	reg |= m;
	writel(reg, regs + S5P_JPGMOD);
}

static inline void jpeg_subsampling_mode(void __iomem *regs, unsigned long mode)
{
	unsigned long reg, m;

	m = S5P_SUBSAMPLING_MODE_422;
	if (mode == S5P_JPEG_SUBSAMPLING_422)
		m = S5P_SUBSAMPLING_MODE_422;
	else if (mode == S5P_JPEG_SUBSAMPLING_420)
		m = S5P_SUBSAMPLING_MODE_420;
	reg = readl(regs + S5P_JPGMOD);
	reg &= ~S5P_SUBSAMPLING_MODE_MASK;
	reg |= m;
	writel(reg, regs + S5P_JPGMOD);
}

static inline void jpeg_dri(void __iomem *regs, unsigned int dri)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPGDRI_U);
	reg &= ~0xff;
	reg |= (dri >> 8) & 0xff;
	writel(reg, regs + S5P_JPGDRI_U);

	reg = readl(regs + S5P_JPGDRI_L);
	reg &= ~0xff;
	reg |= dri & 0xff;
	writel(reg, regs + S5P_JPGDRI_L);
}

static inline void jpeg_qtbl(void __iomem *regs, unsigned int t, unsigned int n)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPG_QTBL);
	reg &= ~S5P_QT_NUMt_MASK(t);
	reg |= (n << S5P_QT_NUMt_SHIFT(t)) & S5P_QT_NUMt_MASK(t);
	writel(reg, regs + S5P_JPG_QTBL);
}

static inline void jpeg_htbl_ac(void __iomem *regs, unsigned int t)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPG_HTBL);
	reg &= ~S5P_HT_NUMt_AC_MASK(t);
	/* this driver uses table 0 for all color components */
	reg |= (0 << S5P_HT_NUMt_AC_SHIFT(t)) & S5P_HT_NUMt_AC_MASK(t);
	writel(reg, regs + S5P_JPG_HTBL);
}

static inline void jpeg_htbl_dc(void __iomem *regs, unsigned int t)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPG_HTBL);
	reg &= ~S5P_HT_NUMt_DC_MASK(t);
	/* this driver uses table 0 for all color components */
	reg |= (0 << S5P_HT_NUMt_DC_SHIFT(t)) & S5P_HT_NUMt_DC_MASK(t);
	writel(reg, regs + S5P_JPG_HTBL);
}

static inline void jpeg_y(void __iomem *regs, unsigned int y)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPGY_U);
	reg &= ~0xff;
	reg |= (y >> 8) & 0xff;
	writel(reg, regs + S5P_JPGY_U);

	reg = readl(regs + S5P_JPGY_L);
	reg &= ~0xff;
	reg |= y & 0xff;
	writel(reg, regs + S5P_JPGY_L);
}

static inline void jpeg_x(void __iomem *regs, unsigned int x)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPGX_U);
	reg &= ~0xff;
	reg |= (x >> 8) & 0xff;
	writel(reg, regs + S5P_JPGX_U);

	reg = readl(regs + S5P_JPGX_L);
	reg &= ~0xff;
	reg |= x & 0xff;
	writel(reg, regs + S5P_JPGX_L);
}

static inline void jpeg_rst_int_enable(void __iomem *regs, bool enable)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPGINTSE);
	reg &= ~S5P_RSTm_INT_EN_MASK;
	if (enable)
		reg |= S5P_RSTm_INT_EN;
	writel(reg, regs + S5P_JPGINTSE);
}

static inline void jpeg_data_num_int_enable(void __iomem *regs, bool enable)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPGINTSE);
	reg &= ~S5P_DATA_NUM_INT_EN_MASK;
	if (enable)
		reg |= S5P_DATA_NUM_INT_EN;
	writel(reg, regs + S5P_JPGINTSE);
}

static inline void jpeg_final_mcu_num_int_enable(void __iomem *regs, bool enbl)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPGINTSE);
	reg &= ~S5P_FINAL_MCU_NUM_INT_EN_MASK;
	if (enbl)
		reg |= S5P_FINAL_MCU_NUM_INT_EN;
	writel(reg, regs + S5P_JPGINTSE);
}

static inline void jpeg_timer_enable(void __iomem *regs, unsigned long val)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPG_TIMER_SE);
	reg |= S5P_TIMER_INT_EN;
	reg &= ~S5P_TIMER_INIT_MASK;
	reg |= val & S5P_TIMER_INIT_MASK;
	writel(reg, regs + S5P_JPG_TIMER_SE);
}

static inline void jpeg_timer_disable(void __iomem *regs)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPG_TIMER_SE);
	reg &= ~S5P_TIMER_INT_EN_MASK;
	writel(reg, regs + S5P_JPG_TIMER_SE);
}

static inline int jpeg_timer_stat(void __iomem *regs)
{
	return (int)((readl(regs + S5P_JPG_TIMER_ST) & S5P_TIMER_INT_STAT_MASK)
		     >> S5P_TIMER_INT_STAT_SHIFT);
}

static inline void jpeg_clear_timer_stat(void __iomem *regs)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPG_TIMER_SE);
	reg &= ~S5P_TIMER_INT_STAT_MASK;
	writel(reg, regs + S5P_JPG_TIMER_SE);
}

static inline void jpeg_enc_stream_int(void __iomem *regs, unsigned long size)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPG_ENC_STREAM_INTSE);
	reg &= ~S5P_ENC_STREAM_BOUND_MASK;
	reg |= S5P_ENC_STREAM_INT_EN;
	reg |= size & S5P_ENC_STREAM_BOUND_MASK;
	writel(reg, regs + S5P_JPG_ENC_STREAM_INTSE);
}

static inline int jpeg_enc_stream_stat(void __iomem *regs)
{
	return (int)(readl(regs + S5P_JPG_ENC_STREAM_INTST) &
		     S5P_ENC_STREAM_INT_STAT_MASK);
}

static inline void jpeg_clear_enc_stream_stat(void __iomem *regs)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPG_ENC_STREAM_INTSE);
	reg &= ~S5P_ENC_STREAM_INT_MASK;
	writel(reg, regs + S5P_JPG_ENC_STREAM_INTSE);
}

static inline void jpeg_outform_raw(void __iomem *regs, unsigned long format)
{
	unsigned long reg, f;

	f = S5P_DEC_OUT_FORMAT_422;
	if (format == S5P_JPEG_RAW_OUT_422)
		f = S5P_DEC_OUT_FORMAT_422;
	else if (format == S5P_JPEG_RAW_OUT_420)
		f = S5P_DEC_OUT_FORMAT_420;
	reg = readl(regs + S5P_JPG_OUTFORM);
	reg &= ~S5P_DEC_OUT_FORMAT_MASK;
	reg |= f;
	writel(reg, regs + S5P_JPG_OUTFORM);
}

static inline void jpeg_jpgadr(void __iomem *regs, unsigned long addr)
{
	writel(addr, regs + S5P_JPG_JPGADR);
}

static inline void jpeg_imgadr(void __iomem *regs, unsigned long addr)
{
	writel(addr, regs + S5P_JPG_IMGADR);
}

static inline void jpeg_coef(void __iomem *regs, unsigned int i,
			     unsigned int j, unsigned int coef)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPG_COEF(i));
	reg &= ~S5P_COEFn_MASK(j);
	reg |= (coef << S5P_COEFn_SHIFT(j)) & S5P_COEFn_MASK(j);
	writel(reg, regs + S5P_JPG_COEF(i));
}

static inline void jpeg_start(void __iomem *regs)
{
	writel(1, regs + S5P_JSTART);
}

static inline int jpeg_result_stat_ok(void __iomem *regs)
{
	return (int)((readl(regs + S5P_JPGINTST) & S5P_RESULT_STAT_MASK)
		     >> S5P_RESULT_STAT_SHIFT);
}

static inline int jpeg_stream_stat_ok(void __iomem *regs)
{
	return !(int)((readl(regs + S5P_JPGINTST) & S5P_STREAM_STAT_MASK)
		      >> S5P_STREAM_STAT_SHIFT);
}

static inline void jpeg_clear_int(void __iomem *regs)
{
	unsigned long reg;

	reg = readl(regs + S5P_JPGINTST);
	writel(S5P_INT_RELEASE, regs + S5P_JPGCOM);
	reg = readl(regs + S5P_JPGOPR);
}

static inline unsigned int jpeg_compressed_size(void __iomem *regs)
{
	unsigned long jpeg_size = 0;

	jpeg_size |= (readl(regs + S5P_JPGCNT_U) & 0xff) << 16;
	jpeg_size |= (readl(regs + S5P_JPGCNT_M) & 0xff) << 8;
	jpeg_size |= (readl(regs + S5P_JPGCNT_L) & 0xff);

	return (unsigned int)jpeg_size;
}

#endif /* JPEG_HW_H_ */