1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Hantro VPU codec driver
5 * Copyright 2018 Google LLC.
6 * Tomasz Figa <tfiga@chromium.org>
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>
18 #define DEC_8190_ALIGN_MASK 0x07U
23 struct hantro_variant;
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.
31 struct hantro_aux_buf {
38 * struct hantro_jpeg_enc_hw_ctx
39 * @bounce_buffer: Bounce buffer
41 struct hantro_jpeg_enc_hw_ctx {
42 struct hantro_aux_buf bounce_buffer;
46 * struct hantro_mpeg2_dec_hw_ctx
47 * @qtable: Quantization table
49 struct hantro_mpeg2_dec_hw_ctx {
50 struct hantro_aux_buf qtable;
54 * struct hantro_vp8d_hw_ctx
55 * @segment_map: Segment map buffer.
56 * @prob_tbl: Probability table buffer.
58 struct hantro_vp8_dec_hw_ctx {
59 struct hantro_aux_buf segment_map;
60 struct hantro_aux_buf prob_tbl;
64 * struct hantro_codec_ops - codec mode specific operations
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.
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);
85 * enum hantro_enc_fmt - source format ID for hardware registers.
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,
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;
98 extern const u32 hantro_vp8_dec_mc_filter[8][6];
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);
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);
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);
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);
126 #endif /* HANTRO_HW_H_ */