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