]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/staging/media/hantro/hantro_hw.h
Merge tag 'v5.3-rc4' into patchwork
[linux.git] / drivers / staging / media / hantro / hantro_hw.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Hantro VPU codec driver
4  *
5  * Copyright 2018 Google LLC.
6  *      Tomasz Figa <tfiga@chromium.org>
7  */
8
9 #ifndef HANTRO_HW_H_
10 #define HANTRO_HW_H_
11
12 #include <linux/interrupt.h>
13 #include <linux/v4l2-controls.h>
14 #include <media/mpeg2-ctrls.h>
15 #include <media/vp8-ctrls.h>
16 #include <media/videobuf2-core.h>
17
18 #define DEC_8190_ALIGN_MASK     0x07U
19
20 struct hantro_dev;
21 struct hantro_ctx;
22 struct hantro_buf;
23 struct hantro_variant;
24
25 /**
26  * struct hantro_aux_buf - auxiliary DMA buffer for hardware data
27  * @cpu:        CPU pointer to the buffer.
28  * @dma:        DMA address of the buffer.
29  * @size:       Size of the buffer.
30  */
31 struct hantro_aux_buf {
32         void *cpu;
33         dma_addr_t dma;
34         size_t size;
35 };
36
37 /**
38  * struct hantro_jpeg_enc_hw_ctx
39  * @bounce_buffer:      Bounce buffer
40  */
41 struct hantro_jpeg_enc_hw_ctx {
42         struct hantro_aux_buf bounce_buffer;
43 };
44
45 /**
46  * struct hantro_mpeg2_dec_hw_ctx
47  * @qtable:             Quantization table
48  */
49 struct hantro_mpeg2_dec_hw_ctx {
50         struct hantro_aux_buf qtable;
51 };
52
53 /**
54  * struct hantro_vp8d_hw_ctx
55  * @segment_map:        Segment map buffer.
56  * @prob_tbl:           Probability table buffer.
57  */
58 struct hantro_vp8_dec_hw_ctx {
59         struct hantro_aux_buf segment_map;
60         struct hantro_aux_buf prob_tbl;
61 };
62
63 /**
64  * struct hantro_codec_ops - codec mode specific operations
65  *
66  * @init:       If needed, can be used for initialization.
67  *              Optional and called from process context.
68  * @exit:       If needed, can be used to undo the .init phase.
69  *              Optional and called from process context.
70  * @run:        Start single {en,de)coding job. Called from atomic context
71  *              to indicate that a pair of buffers is ready and the hardware
72  *              should be programmed and started.
73  * @done:       Read back processing results and additional data from hardware.
74  * @reset:      Reset the hardware in case of a timeout.
75  */
76 struct hantro_codec_ops {
77         int (*init)(struct hantro_ctx *ctx);
78         void (*exit)(struct hantro_ctx *ctx);
79         void (*run)(struct hantro_ctx *ctx);
80         void (*done)(struct hantro_ctx *ctx, enum vb2_buffer_state);
81         void (*reset)(struct hantro_ctx *ctx);
82 };
83
84 /**
85  * enum hantro_enc_fmt - source format ID for hardware registers.
86  */
87 enum hantro_enc_fmt {
88         RK3288_VPU_ENC_FMT_YUV420P = 0,
89         RK3288_VPU_ENC_FMT_YUV420SP = 1,
90         RK3288_VPU_ENC_FMT_YUYV422 = 2,
91         RK3288_VPU_ENC_FMT_UYVY422 = 3,
92 };
93
94 extern const struct hantro_variant rk3399_vpu_variant;
95 extern const struct hantro_variant rk3328_vpu_variant;
96 extern const struct hantro_variant rk3288_vpu_variant;
97
98 extern const u32 hantro_vp8_dec_mc_filter[8][6];
99
100 void hantro_watchdog(struct work_struct *work);
101 void hantro_run(struct hantro_ctx *ctx);
102 void hantro_irq_done(struct hantro_dev *vpu, unsigned int bytesused,
103                      enum vb2_buffer_state result);
104 void hantro_prepare_run(struct hantro_ctx *ctx);
105 void hantro_finish_run(struct hantro_ctx *ctx);
106
107 void hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx);
108 void rk3399_vpu_jpeg_enc_run(struct hantro_ctx *ctx);
109 int hantro_jpeg_enc_init(struct hantro_ctx *ctx);
110 void hantro_jpeg_enc_exit(struct hantro_ctx *ctx);
111
112 void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx);
113 void rk3399_vpu_mpeg2_dec_run(struct hantro_ctx *ctx);
114 void hantro_mpeg2_dec_copy_qtable(u8 *qtable,
115         const struct v4l2_ctrl_mpeg2_quantization *ctrl);
116 int hantro_mpeg2_dec_init(struct hantro_ctx *ctx);
117 void hantro_mpeg2_dec_exit(struct hantro_ctx *ctx);
118
119 void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx);
120 void rk3399_vpu_vp8_dec_run(struct hantro_ctx *ctx);
121 int hantro_vp8_dec_init(struct hantro_ctx *ctx);
122 void hantro_vp8_dec_exit(struct hantro_ctx *ctx);
123 void hantro_vp8_prob_update(struct hantro_ctx *ctx,
124                             const struct v4l2_ctrl_vp8_frame_header *hdr);
125
126 #endif /* HANTRO_HW_H_ */