This source file includes following definitions.
- hantro_vdev_to_func
- fh_to_ctx
- vepu_write_relaxed
- vepu_write
- vepu_read
- vdpu_write_relaxed
- vdpu_write
- vdpu_read
- hantro_reg_write
- hantro_get_src_buf
- hantro_get_dst_buf
1
2
3
4
5
6
7
8
9
10
11
12 #ifndef HANTRO_H_
13 #define HANTRO_H_
14
15 #include <linux/platform_device.h>
16 #include <linux/videodev2.h>
17 #include <linux/wait.h>
18 #include <linux/clk.h>
19
20 #include <media/v4l2-ctrls.h>
21 #include <media/v4l2-device.h>
22 #include <media/v4l2-ioctl.h>
23 #include <media/v4l2-mem2mem.h>
24 #include <media/videobuf2-core.h>
25 #include <media/videobuf2-dma-contig.h>
26
27 #include "hantro_hw.h"
28
29 #define VP8_MB_DIM 16
30 #define VP8_MB_WIDTH(w) DIV_ROUND_UP(w, VP8_MB_DIM)
31 #define VP8_MB_HEIGHT(h) DIV_ROUND_UP(h, VP8_MB_DIM)
32
33 #define H264_MB_DIM 16
34 #define H264_MB_WIDTH(w) DIV_ROUND_UP(w, H264_MB_DIM)
35 #define H264_MB_HEIGHT(h) DIV_ROUND_UP(h, H264_MB_DIM)
36
37 #define MPEG2_MB_DIM 16
38 #define MPEG2_MB_WIDTH(w) DIV_ROUND_UP(w, MPEG2_MB_DIM)
39 #define MPEG2_MB_HEIGHT(h) DIV_ROUND_UP(h, MPEG2_MB_DIM)
40
41 #define JPEG_MB_DIM 16
42 #define JPEG_MB_WIDTH(w) DIV_ROUND_UP(w, JPEG_MB_DIM)
43 #define JPEG_MB_HEIGHT(h) DIV_ROUND_UP(h, JPEG_MB_DIM)
44
45 struct hantro_ctx;
46 struct hantro_codec_ops;
47
48 #define HANTRO_JPEG_ENCODER BIT(0)
49 #define HANTRO_ENCODERS 0x0000ffff
50 #define HANTRO_MPEG2_DECODER BIT(16)
51 #define HANTRO_VP8_DECODER BIT(17)
52 #define HANTRO_H264_DECODER BIT(18)
53 #define HANTRO_DECODERS 0xffff0000
54
55
56
57
58
59
60
61 struct hantro_irq {
62 const char *name;
63 irqreturn_t (*handler)(int irq, void *priv);
64 };
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 struct hantro_variant {
87 unsigned int enc_offset;
88 unsigned int dec_offset;
89 const struct hantro_fmt *enc_fmts;
90 unsigned int num_enc_fmts;
91 const struct hantro_fmt *dec_fmts;
92 unsigned int num_dec_fmts;
93 unsigned int codec;
94 const struct hantro_codec_ops *codec_ops;
95 int (*init)(struct hantro_dev *vpu);
96 int (*runtime_resume)(struct hantro_dev *vpu);
97 const struct hantro_irq *irqs;
98 int num_irqs;
99 const char * const *clk_names;
100 int num_clocks;
101 const char * const *reg_names;
102 int num_regs;
103 };
104
105
106
107
108
109
110
111
112
113 enum hantro_codec_mode {
114 HANTRO_MODE_NONE = -1,
115 HANTRO_MODE_JPEG_ENC,
116 HANTRO_MODE_H264_DEC,
117 HANTRO_MODE_MPEG2_DEC,
118 HANTRO_MODE_VP8_DEC,
119 };
120
121
122
123
124
125
126 struct hantro_ctrl {
127 unsigned int codec;
128 struct v4l2_ctrl_config cfg;
129 };
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149 struct hantro_func {
150 unsigned int id;
151 struct video_device vdev;
152 struct media_pad source_pad;
153 struct media_entity sink;
154 struct media_pad sink_pad;
155 struct media_entity proc;
156 struct media_pad proc_pads[2];
157 struct media_intf_devnode *intf_devnode;
158 };
159
160 static inline struct hantro_func *
161 hantro_vdev_to_func(struct video_device *vdev)
162 {
163 return container_of(vdev, struct hantro_func, vdev);
164 }
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187 struct hantro_dev {
188 struct v4l2_device v4l2_dev;
189 struct v4l2_m2m_dev *m2m_dev;
190 struct media_device mdev;
191 struct hantro_func *encoder;
192 struct hantro_func *decoder;
193 struct platform_device *pdev;
194 struct device *dev;
195 struct clk_bulk_data *clocks;
196 void __iomem **reg_bases;
197 void __iomem *enc_base;
198 void __iomem *dec_base;
199 void __iomem *ctrl_base;
200
201 struct mutex vpu_mutex;
202 spinlock_t irqlock;
203 const struct hantro_variant *variant;
204 struct delayed_work watchdog_work;
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 struct hantro_ctx {
233 struct hantro_dev *dev;
234 struct v4l2_fh fh;
235
236 u32 sequence_cap;
237 u32 sequence_out;
238
239 const struct hantro_fmt *vpu_src_fmt;
240 struct v4l2_pix_format_mplane src_fmt;
241 const struct hantro_fmt *vpu_dst_fmt;
242 struct v4l2_pix_format_mplane dst_fmt;
243
244 struct v4l2_ctrl_handler ctrl_handler;
245 int jpeg_quality;
246
247 int (*buf_finish)(struct hantro_ctx *ctx,
248 struct vb2_buffer *buf,
249 unsigned int bytesused);
250
251 const struct hantro_codec_ops *codec_ops;
252
253
254 union {
255 struct hantro_h264_dec_hw_ctx h264_dec;
256 struct hantro_jpeg_enc_hw_ctx jpeg_enc;
257 struct hantro_mpeg2_dec_hw_ctx mpeg2_dec;
258 struct hantro_vp8_dec_hw_ctx vp8_dec;
259 };
260 };
261
262
263
264
265
266
267
268
269
270
271
272
273 struct hantro_fmt {
274 char *name;
275 u32 fourcc;
276 enum hantro_codec_mode codec_mode;
277 int header_size;
278 int max_depth;
279 enum hantro_enc_fmt enc_fmt;
280 struct v4l2_frmsize_stepwise frmsize;
281 };
282
283 struct hantro_reg {
284 u32 base;
285 u32 shift;
286 u32 mask;
287 };
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306 extern int hantro_debug;
307
308 #define vpu_debug(level, fmt, args...) \
309 do { \
310 if (hantro_debug & BIT(level)) \
311 pr_info("%s:%d: " fmt, \
312 __func__, __LINE__, ##args); \
313 } while (0)
314
315 #define vpu_err(fmt, args...) \
316 pr_err("%s:%d: " fmt, __func__, __LINE__, ##args)
317
318
319 static inline struct hantro_ctx *fh_to_ctx(struct v4l2_fh *fh)
320 {
321 return container_of(fh, struct hantro_ctx, fh);
322 }
323
324
325 static inline void vepu_write_relaxed(struct hantro_dev *vpu,
326 u32 val, u32 reg)
327 {
328 vpu_debug(6, "0x%04x = 0x%08x\n", reg / 4, val);
329 writel_relaxed(val, vpu->enc_base + reg);
330 }
331
332 static inline void vepu_write(struct hantro_dev *vpu, u32 val, u32 reg)
333 {
334 vpu_debug(6, "0x%04x = 0x%08x\n", reg / 4, val);
335 writel(val, vpu->enc_base + reg);
336 }
337
338 static inline u32 vepu_read(struct hantro_dev *vpu, u32 reg)
339 {
340 u32 val = readl(vpu->enc_base + reg);
341
342 vpu_debug(6, "0x%04x = 0x%08x\n", reg / 4, val);
343 return val;
344 }
345
346 static inline void vdpu_write_relaxed(struct hantro_dev *vpu,
347 u32 val, u32 reg)
348 {
349 vpu_debug(6, "0x%04x = 0x%08x\n", reg / 4, val);
350 writel_relaxed(val, vpu->dec_base + reg);
351 }
352
353 static inline void vdpu_write(struct hantro_dev *vpu, u32 val, u32 reg)
354 {
355 vpu_debug(6, "0x%04x = 0x%08x\n", reg / 4, val);
356 writel(val, vpu->dec_base + reg);
357 }
358
359 static inline u32 vdpu_read(struct hantro_dev *vpu, u32 reg)
360 {
361 u32 val = readl(vpu->dec_base + reg);
362
363 vpu_debug(6, "0x%04x = 0x%08x\n", reg / 4, val);
364 return val;
365 }
366
367 static inline void hantro_reg_write(struct hantro_dev *vpu,
368 const struct hantro_reg *reg,
369 u32 val)
370 {
371 u32 v;
372
373 v = vdpu_read(vpu, reg->base);
374 v &= ~(reg->mask << reg->shift);
375 v |= ((val & reg->mask) << reg->shift);
376 vdpu_write_relaxed(vpu, v, reg->base);
377 }
378
379 bool hantro_is_encoder_ctx(const struct hantro_ctx *ctx);
380
381 void *hantro_get_ctrl(struct hantro_ctx *ctx, u32 id);
382 dma_addr_t hantro_get_ref(struct vb2_queue *q, u64 ts);
383
384 static inline struct vb2_v4l2_buffer *
385 hantro_get_src_buf(struct hantro_ctx *ctx)
386 {
387 return v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
388 }
389
390 static inline struct vb2_v4l2_buffer *
391 hantro_get_dst_buf(struct hantro_ctx *ctx)
392 {
393 return v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
394 }
395
396 #endif