1
2
3
4
5
6
7
8
9
10#ifndef JPEG_CORE_H_
11#define JPEG_CORE_H_
12
13#include <linux/interrupt.h>
14#include <media/v4l2-device.h>
15#include <media/v4l2-fh.h>
16#include <media/v4l2-ctrls.h>
17
18#define S5P_JPEG_M2M_NAME "s5p-jpeg"
19
20#define JPEG_MAX_CLOCKS 4
21
22
23#define S5P_JPEG_COMPR_QUAL_BEST 0
24#define S5P_JPEG_COMPR_QUAL_WORST 3
25
26
27#define S5P_JPEG_COEF11 0x4d
28#define S5P_JPEG_COEF12 0x97
29#define S5P_JPEG_COEF13 0x1e
30#define S5P_JPEG_COEF21 0x2c
31#define S5P_JPEG_COEF22 0x57
32#define S5P_JPEG_COEF23 0x83
33#define S5P_JPEG_COEF31 0x83
34#define S5P_JPEG_COEF32 0x6e
35#define S5P_JPEG_COEF33 0x13
36
37#define EXYNOS3250_IRQ_TIMEOUT 0x10000000
38
39
40#define TEM 0x01
41#define SOF0 0xc0
42#define DHT 0xc4
43#define RST 0xd0
44#define SOI 0xd8
45#define EOI 0xd9
46#define SOS 0xda
47#define DQT 0xdb
48#define DHP 0xde
49
50
51#define SJPEG_FMT_FLAG_ENC_CAPTURE (1 << 0)
52#define SJPEG_FMT_FLAG_ENC_OUTPUT (1 << 1)
53#define SJPEG_FMT_FLAG_DEC_CAPTURE (1 << 2)
54#define SJPEG_FMT_FLAG_DEC_OUTPUT (1 << 3)
55#define SJPEG_FMT_FLAG_S5P (1 << 4)
56#define SJPEG_FMT_FLAG_EXYNOS3250 (1 << 5)
57#define SJPEG_FMT_FLAG_EXYNOS4 (1 << 6)
58#define SJPEG_FMT_RGB (1 << 7)
59#define SJPEG_FMT_NON_RGB (1 << 8)
60
61#define S5P_JPEG_ENCODE 0
62#define S5P_JPEG_DECODE 1
63#define S5P_JPEG_DISABLE -1
64
65#define FMT_TYPE_OUTPUT 0
66#define FMT_TYPE_CAPTURE 1
67
68#define SJPEG_SUBSAMPLING_444 0x11
69#define SJPEG_SUBSAMPLING_422 0x21
70#define SJPEG_SUBSAMPLING_420 0x22
71
72#define S5P_JPEG_MAX_MARKER 4
73
74
75enum sjpeg_version {
76 SJPEG_S5P,
77 SJPEG_EXYNOS3250,
78 SJPEG_EXYNOS4,
79 SJPEG_EXYNOS5420,
80 SJPEG_EXYNOS5433,
81};
82
83enum exynos4_jpeg_result {
84 OK_ENC_OR_DEC,
85 ERR_PROT,
86 ERR_DEC_INVALID_FORMAT,
87 ERR_MULTI_SCAN,
88 ERR_FRAME,
89 ERR_UNKNOWN,
90};
91
92enum exynos4_jpeg_img_quality_level {
93 QUALITY_LEVEL_1 = 0,
94 QUALITY_LEVEL_2,
95 QUALITY_LEVEL_3,
96 QUALITY_LEVEL_4,
97};
98
99enum s5p_jpeg_ctx_state {
100 JPEGCTX_RUNNING = 0,
101 JPEGCTX_RESOLUTION_CHANGE,
102};
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121struct s5p_jpeg {
122 struct mutex lock;
123 spinlock_t slock;
124
125 struct v4l2_device v4l2_dev;
126 struct video_device *vfd_encoder;
127 struct video_device *vfd_decoder;
128 struct v4l2_m2m_dev *m2m_dev;
129
130 void __iomem *regs;
131 unsigned int irq;
132 enum exynos4_jpeg_result irq_ret;
133 struct clk *clocks[JPEG_MAX_CLOCKS];
134 struct device *dev;
135 struct s5p_jpeg_variant *variant;
136 u32 irq_status;
137};
138
139struct s5p_jpeg_variant {
140 unsigned int version;
141 unsigned int fmt_ver_flag;
142 unsigned int hw3250_compat:1;
143 unsigned int htbl_reinit:1;
144 unsigned int hw_ex4_compat:1;
145 struct v4l2_m2m_ops *m2m_ops;
146 irqreturn_t (*jpeg_irq)(int irq, void *priv);
147 const char *clk_names[JPEG_MAX_CLOCKS];
148 int num_clocks;
149};
150
151
152
153
154
155
156
157
158
159
160struct s5p_jpeg_fmt {
161 u32 fourcc;
162 int depth;
163 int colplanes;
164 int memplanes;
165 int h_align;
166 int v_align;
167 int subsampling;
168 u32 flags;
169};
170
171
172
173
174
175
176
177struct s5p_jpeg_marker {
178 u32 marker[S5P_JPEG_MAX_MARKER];
179 u32 len[S5P_JPEG_MAX_MARKER];
180 u32 n;
181};
182
183
184
185
186
187
188
189
190
191
192
193
194
195struct s5p_jpeg_q_data {
196 struct s5p_jpeg_fmt *fmt;
197 u32 w;
198 u32 h;
199 u32 sos;
200 struct s5p_jpeg_marker dht;
201 struct s5p_jpeg_marker dqt;
202 u32 sof;
203 u32 sof_len;
204 u32 size;
205};
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224struct s5p_jpeg_ctx {
225 struct s5p_jpeg *jpeg;
226 unsigned int mode;
227 unsigned short compr_quality;
228 unsigned short restart_interval;
229 unsigned short subsampling;
230 struct s5p_jpeg_q_data out_q;
231 struct s5p_jpeg_q_data cap_q;
232 unsigned int scale_factor;
233 struct v4l2_rect crop_rect;
234 struct v4l2_fh fh;
235 bool hdr_parsed;
236 bool crop_altered;
237 struct v4l2_ctrl_handler ctrl_handler;
238 enum s5p_jpeg_ctx_state state;
239};
240
241
242
243
244
245
246
247struct s5p_jpeg_buffer {
248 unsigned long size;
249 unsigned long curr;
250 unsigned long data;
251};
252
253
254
255
256
257
258
259struct s5p_jpeg_addr {
260 u32 y;
261 u32 cb;
262 u32 cr;
263};
264
265#endif
266