1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef __CODA_H__
16#define __CODA_H__
17
18#include <linux/debugfs.h>
19#include <linux/irqreturn.h>
20#include <linux/mutex.h>
21#include <linux/kfifo.h>
22#include <linux/videodev2.h>
23
24#include <media/v4l2-ctrls.h>
25#include <media/v4l2-device.h>
26#include <media/v4l2-fh.h>
27#include <media/videobuf2-v4l2.h>
28
29#include "coda_regs.h"
30
31#define CODA_MAX_FRAMEBUFFERS 17
32#define FMO_SLICE_SAVE_BUF_SIZE (32)
33
34enum {
35 V4L2_M2M_SRC = 0,
36 V4L2_M2M_DST = 1,
37};
38
39enum coda_inst_type {
40 CODA_INST_ENCODER,
41 CODA_INST_DECODER,
42};
43
44enum coda_product {
45 CODA_DX6 = 0xf001,
46 CODA_7541 = 0xf012,
47 CODA_960 = 0xf020,
48};
49
50struct coda_video_device;
51
52struct coda_devtype {
53 char *firmware[3];
54 enum coda_product product;
55 const struct coda_codec *codecs;
56 unsigned int num_codecs;
57 const struct coda_video_device **vdevs;
58 unsigned int num_vdevs;
59 size_t workbuf_size;
60 size_t tempbuf_size;
61 size_t iram_size;
62};
63
64struct coda_aux_buf {
65 void *vaddr;
66 dma_addr_t paddr;
67 u32 size;
68 struct debugfs_blob_wrapper blob;
69 struct dentry *dentry;
70};
71
72struct coda_dev {
73 struct v4l2_device v4l2_dev;
74 struct video_device vfd[5];
75 struct platform_device *plat_dev;
76 const struct coda_devtype *devtype;
77 int firmware;
78 struct vdoa_data *vdoa;
79
80 void __iomem *regs_base;
81 struct clk *clk_per;
82 struct clk *clk_ahb;
83 struct reset_control *rstc;
84
85 struct coda_aux_buf codebuf;
86 struct coda_aux_buf tempbuf;
87 struct coda_aux_buf workbuf;
88 struct gen_pool *iram_pool;
89 struct coda_aux_buf iram;
90
91 spinlock_t irqlock;
92 struct mutex dev_mutex;
93 struct mutex coda_mutex;
94 struct workqueue_struct *workqueue;
95 struct v4l2_m2m_dev *m2m_dev;
96 struct list_head instances;
97 unsigned long instance_mask;
98 struct dentry *debugfs_root;
99};
100
101struct coda_codec {
102 u32 mode;
103 u32 src_fourcc;
104 u32 dst_fourcc;
105 u32 max_w;
106 u32 max_h;
107};
108
109struct coda_huff_tab;
110
111struct coda_params {
112 u8 rot_mode;
113 u8 h264_intra_qp;
114 u8 h264_inter_qp;
115 u8 h264_min_qp;
116 u8 h264_max_qp;
117 u8 h264_deblk_enabled;
118 u8 h264_deblk_alpha;
119 u8 h264_deblk_beta;
120 u8 h264_profile_idc;
121 u8 h264_level_idc;
122 u8 mpeg4_intra_qp;
123 u8 mpeg4_inter_qp;
124 u8 gop_size;
125 int intra_refresh;
126 u8 jpeg_quality;
127 u8 jpeg_restart_interval;
128 u8 *jpeg_qmat_tab[3];
129 int codec_mode;
130 int codec_mode_aux;
131 enum v4l2_mpeg_video_multi_slice_mode slice_mode;
132 u32 framerate;
133 u16 bitrate;
134 u16 vbv_delay;
135 u32 vbv_size;
136 u32 slice_max_bits;
137 u32 slice_max_mb;
138};
139
140struct coda_buffer_meta {
141 struct list_head list;
142 u32 sequence;
143 struct v4l2_timecode timecode;
144 u64 timestamp;
145 u32 start;
146 u32 end;
147};
148
149
150struct coda_q_data {
151 unsigned int width;
152 unsigned int height;
153 unsigned int bytesperline;
154 unsigned int sizeimage;
155 unsigned int fourcc;
156 struct v4l2_rect rect;
157};
158
159struct coda_iram_info {
160 u32 axi_sram_use;
161 phys_addr_t buf_bit_use;
162 phys_addr_t buf_ip_ac_dc_use;
163 phys_addr_t buf_dbk_y_use;
164 phys_addr_t buf_dbk_c_use;
165 phys_addr_t buf_ovl_use;
166 phys_addr_t buf_btp_use;
167 phys_addr_t search_ram_paddr;
168 int search_ram_size;
169 int remaining;
170 phys_addr_t next_paddr;
171};
172
173#define GDI_LINEAR_FRAME_MAP 0
174#define GDI_TILED_FRAME_MB_RASTER_MAP 1
175
176struct coda_ctx;
177
178struct coda_context_ops {
179 int (*queue_init)(void *priv, struct vb2_queue *src_vq,
180 struct vb2_queue *dst_vq);
181 int (*reqbufs)(struct coda_ctx *ctx, struct v4l2_requestbuffers *rb);
182 int (*start_streaming)(struct coda_ctx *ctx);
183 int (*prepare_run)(struct coda_ctx *ctx);
184 void (*finish_run)(struct coda_ctx *ctx);
185 void (*seq_end_work)(struct work_struct *work);
186 void (*release)(struct coda_ctx *ctx);
187};
188
189struct coda_ctx {
190 struct coda_dev *dev;
191 struct mutex buffer_mutex;
192 struct list_head list;
193 struct work_struct pic_run_work;
194 struct work_struct seq_end_work;
195 struct completion completion;
196 const struct coda_video_device *cvd;
197 const struct coda_context_ops *ops;
198 int aborting;
199 int initialized;
200 int streamon_out;
201 int streamon_cap;
202 u32 qsequence;
203 u32 osequence;
204 u32 sequence_offset;
205 struct coda_q_data q_data[2];
206 enum coda_inst_type inst_type;
207 const struct coda_codec *codec;
208 enum v4l2_colorspace colorspace;
209 struct coda_params params;
210 struct v4l2_ctrl_handler ctrls;
211 struct v4l2_fh fh;
212 int gopcounter;
213 int runcounter;
214 char vpu_header[3][64];
215 int vpu_header_size[3];
216 struct kfifo bitstream_fifo;
217 struct mutex bitstream_mutex;
218 struct coda_aux_buf bitstream;
219 bool hold;
220 struct coda_aux_buf parabuf;
221 struct coda_aux_buf psbuf;
222 struct coda_aux_buf slicebuf;
223 struct coda_aux_buf internal_frames[CODA_MAX_FRAMEBUFFERS];
224 u32 frame_types[CODA_MAX_FRAMEBUFFERS];
225 struct coda_buffer_meta frame_metas[CODA_MAX_FRAMEBUFFERS];
226 u32 frame_errors[CODA_MAX_FRAMEBUFFERS];
227 struct list_head buffer_meta_list;
228 spinlock_t buffer_meta_lock;
229 int num_metas;
230 struct coda_aux_buf workbuf;
231 int num_internal_frames;
232 int idx;
233 int reg_idx;
234 struct coda_iram_info iram_info;
235 int tiled_map_type;
236 u32 bit_stream_param;
237 u32 frm_dis_flg;
238 u32 frame_mem_ctrl;
239 int display_idx;
240 struct dentry *debugfs_entry;
241 bool use_bit;
242 bool use_vdoa;
243 struct vdoa_ctx *vdoa;
244};
245
246extern int coda_debug;
247
248void coda_write(struct coda_dev *dev, u32 data, u32 reg);
249unsigned int coda_read(struct coda_dev *dev, u32 reg);
250void coda_write_base(struct coda_ctx *ctx, struct coda_q_data *q_data,
251 struct vb2_v4l2_buffer *buf, unsigned int reg_y);
252
253int coda_alloc_aux_buf(struct coda_dev *dev, struct coda_aux_buf *buf,
254 size_t size, const char *name, struct dentry *parent);
255void coda_free_aux_buf(struct coda_dev *dev, struct coda_aux_buf *buf);
256
257int coda_encoder_queue_init(void *priv, struct vb2_queue *src_vq,
258 struct vb2_queue *dst_vq);
259int coda_decoder_queue_init(void *priv, struct vb2_queue *src_vq,
260 struct vb2_queue *dst_vq);
261
262int coda_hw_reset(struct coda_ctx *ctx);
263
264void coda_fill_bitstream(struct coda_ctx *ctx, struct list_head *buffer_list);
265
266void coda_set_gdi_regs(struct coda_ctx *ctx);
267
268static inline struct coda_q_data *get_q_data(struct coda_ctx *ctx,
269 enum v4l2_buf_type type)
270{
271 switch (type) {
272 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
273 return &(ctx->q_data[V4L2_M2M_SRC]);
274 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
275 return &(ctx->q_data[V4L2_M2M_DST]);
276 default:
277 return NULL;
278 }
279}
280
281const char *coda_product_name(int product);
282
283int coda_check_firmware(struct coda_dev *dev);
284
285static inline unsigned int coda_get_bitstream_payload(struct coda_ctx *ctx)
286{
287 return kfifo_len(&ctx->bitstream_fifo);
288}
289
290void coda_bit_stream_end_flag(struct coda_ctx *ctx);
291
292void coda_m2m_buf_done(struct coda_ctx *ctx, struct vb2_v4l2_buffer *buf,
293 enum vb2_buffer_state state);
294
295int coda_h264_filler_nal(int size, char *p);
296int coda_h264_padding(int size, char *p);
297int coda_h264_profile(int profile_idc);
298int coda_h264_level(int level_idc);
299int coda_sps_parse_profile(struct coda_ctx *ctx, struct vb2_buffer *vb);
300
301bool coda_jpeg_check_buffer(struct coda_ctx *ctx, struct vb2_buffer *vb);
302int coda_jpeg_write_tables(struct coda_ctx *ctx);
303void coda_set_jpeg_compression_quality(struct coda_ctx *ctx, int quality);
304
305extern const struct coda_context_ops coda_bit_encode_ops;
306extern const struct coda_context_ops coda_bit_decode_ops;
307
308irqreturn_t coda_irq_handler(int irq, void *data);
309
310#endif
311