2 * Coda multi-standard codec IP
4 * Copyright (C) 2012 Vista Silicon S.L.
5 * Javier Martin, <javier.martin@vista-silicon.com>
7 * Copyright (C) 2012-2014 Philipp Zabel, Pengutronix
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
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>
24 #include <media/v4l2-ctrls.h>
25 #include <media/v4l2-device.h>
26 #include <media/v4l2-fh.h>
27 #include <media/videobuf2-v4l2.h>
29 #include "coda_regs.h"
31 #define CODA_MAX_FRAMEBUFFERS 17
32 #define FMO_SLICE_SAVE_BUF_SIZE (32)
50 struct coda_video_device;
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;
68 struct debugfs_blob_wrapper blob;
69 struct dentry *dentry;
73 struct v4l2_device v4l2_dev;
74 struct video_device vfd[5];
75 struct platform_device *plat_dev;
76 const struct coda_devtype *devtype;
78 struct vdoa_data *vdoa;
80 void __iomem *regs_base;
83 struct reset_control *rstc;
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;
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;
109 struct coda_huff_tab;
117 u8 h264_deblk_enabled;
127 u8 jpeg_restart_interval;
128 u8 *jpeg_qmat_tab[3];
131 enum v4l2_mpeg_video_multi_slice_mode slice_mode;
140 struct coda_buffer_meta {
141 struct list_head list;
143 struct v4l2_timecode timecode;
149 /* Per-queue, driver-specific private data */
153 unsigned int bytesperline;
154 unsigned int sizeimage;
156 struct v4l2_rect rect;
159 struct coda_iram_info {
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;
170 phys_addr_t next_paddr;
173 #define GDI_LINEAR_FRAME_MAP 0
174 #define GDI_TILED_FRAME_MB_RASTER_MAP 1
178 struct 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);
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;
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 enum v4l2_xfer_func xfer_func;
210 enum v4l2_ycbcr_encoding ycbcr_enc;
211 enum v4l2_quantization quantization;
212 struct coda_params params;
213 struct v4l2_ctrl_handler ctrls;
217 char vpu_header[3][64];
218 int vpu_header_size[3];
219 struct kfifo bitstream_fifo;
220 struct mutex bitstream_mutex;
221 struct coda_aux_buf bitstream;
223 struct coda_aux_buf parabuf;
224 struct coda_aux_buf psbuf;
225 struct coda_aux_buf slicebuf;
226 struct coda_aux_buf internal_frames[CODA_MAX_FRAMEBUFFERS];
227 u32 frame_types[CODA_MAX_FRAMEBUFFERS];
228 struct coda_buffer_meta frame_metas[CODA_MAX_FRAMEBUFFERS];
229 u32 frame_errors[CODA_MAX_FRAMEBUFFERS];
230 struct list_head buffer_meta_list;
231 spinlock_t buffer_meta_lock;
233 struct coda_aux_buf workbuf;
234 int num_internal_frames;
237 struct coda_iram_info iram_info;
239 u32 bit_stream_param;
243 struct dentry *debugfs_entry;
246 struct vdoa_ctx *vdoa;
249 extern int coda_debug;
251 void coda_write(struct coda_dev *dev, u32 data, u32 reg);
252 unsigned int coda_read(struct coda_dev *dev, u32 reg);
253 void coda_write_base(struct coda_ctx *ctx, struct coda_q_data *q_data,
254 struct vb2_v4l2_buffer *buf, unsigned int reg_y);
256 int coda_alloc_aux_buf(struct coda_dev *dev, struct coda_aux_buf *buf,
257 size_t size, const char *name, struct dentry *parent);
258 void coda_free_aux_buf(struct coda_dev *dev, struct coda_aux_buf *buf);
260 int coda_encoder_queue_init(void *priv, struct vb2_queue *src_vq,
261 struct vb2_queue *dst_vq);
262 int coda_decoder_queue_init(void *priv, struct vb2_queue *src_vq,
263 struct vb2_queue *dst_vq);
265 int coda_hw_reset(struct coda_ctx *ctx);
267 void coda_fill_bitstream(struct coda_ctx *ctx, struct list_head *buffer_list);
269 void coda_set_gdi_regs(struct coda_ctx *ctx);
271 static inline struct coda_q_data *get_q_data(struct coda_ctx *ctx,
272 enum v4l2_buf_type type)
275 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
276 return &(ctx->q_data[V4L2_M2M_SRC]);
277 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
278 return &(ctx->q_data[V4L2_M2M_DST]);
284 const char *coda_product_name(int product);
286 int coda_check_firmware(struct coda_dev *dev);
288 static inline unsigned int coda_get_bitstream_payload(struct coda_ctx *ctx)
290 return kfifo_len(&ctx->bitstream_fifo);
293 void coda_bit_stream_end_flag(struct coda_ctx *ctx);
295 void coda_m2m_buf_done(struct coda_ctx *ctx, struct vb2_v4l2_buffer *buf,
296 enum vb2_buffer_state state);
298 int coda_h264_filler_nal(int size, char *p);
299 int coda_h264_padding(int size, char *p);
300 int coda_h264_profile(int profile_idc);
301 int coda_h264_level(int level_idc);
302 int coda_sps_parse_profile(struct coda_ctx *ctx, struct vb2_buffer *vb);
304 bool coda_jpeg_check_buffer(struct coda_ctx *ctx, struct vb2_buffer *vb);
305 int coda_jpeg_write_tables(struct coda_ctx *ctx);
306 void coda_set_jpeg_compression_quality(struct coda_ctx *ctx, int quality);
308 extern const struct coda_context_ops coda_bit_encode_ops;
309 extern const struct coda_context_ops coda_bit_decode_ops;
311 irqreturn_t coda_irq_handler(int irq, void *data);
313 #endif /* __CODA_H__ */