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.
15 #include <linux/debugfs.h>
16 #include <linux/irqreturn.h>
17 #include <linux/mutex.h>
18 #include <linux/kfifo.h>
19 #include <linux/videodev2.h>
21 #include <media/v4l2-ctrls.h>
22 #include <media/v4l2-device.h>
23 #include <media/v4l2-fh.h>
24 #include <media/videobuf2-core.h>
26 #include "coda_regs.h"
28 #define CODA_MAX_FRAMEBUFFERS 8
29 #define FMO_SLICE_SAVE_BUF_SIZE (32)
47 struct coda_video_device;
51 enum coda_product product;
52 const struct coda_codec *codecs;
53 unsigned int num_codecs;
54 const struct coda_video_device **vdevs;
55 unsigned int num_vdevs;
65 struct debugfs_blob_wrapper blob;
66 struct dentry *dentry;
70 struct v4l2_device v4l2_dev;
71 struct video_device vfd[5];
72 struct platform_device *plat_dev;
73 const struct coda_devtype *devtype;
75 void __iomem *regs_base;
78 struct reset_control *rstc;
80 struct coda_aux_buf codebuf;
81 struct coda_aux_buf tempbuf;
82 struct coda_aux_buf workbuf;
83 struct gen_pool *iram_pool;
84 struct coda_aux_buf iram;
87 struct mutex dev_mutex;
88 struct mutex coda_mutex;
89 struct workqueue_struct *workqueue;
90 struct v4l2_m2m_dev *m2m_dev;
91 struct vb2_alloc_ctx *alloc_ctx;
92 struct list_head instances;
93 unsigned long instance_mask;
94 struct dentry *debugfs_root;
105 struct coda_huff_tab;
113 u8 h264_deblk_enabled;
121 u8 jpeg_restart_interval;
122 u8 *jpeg_qmat_tab[3];
125 enum v4l2_mpeg_video_multi_slice_mode slice_mode;
132 struct coda_buffer_meta {
133 struct list_head list;
135 struct v4l2_timecode timecode;
136 struct timeval timestamp;
141 /* Per-queue, driver-specific private data */
145 unsigned int bytesperline;
146 unsigned int sizeimage;
148 struct v4l2_rect rect;
151 struct coda_iram_info {
153 phys_addr_t buf_bit_use;
154 phys_addr_t buf_ip_ac_dc_use;
155 phys_addr_t buf_dbk_y_use;
156 phys_addr_t buf_dbk_c_use;
157 phys_addr_t buf_ovl_use;
158 phys_addr_t buf_btp_use;
159 phys_addr_t search_ram_paddr;
162 phys_addr_t next_paddr;
165 struct gdi_tiled_map {
172 #define GDI_LINEAR_FRAME_MAP 0
177 struct coda_context_ops {
178 int (*queue_init)(void *priv, struct vb2_queue *src_vq,
179 struct vb2_queue *dst_vq);
180 int (*reqbufs)(struct coda_ctx *ctx, struct v4l2_requestbuffers *rb);
181 int (*start_streaming)(struct coda_ctx *ctx);
182 int (*prepare_run)(struct coda_ctx *ctx);
183 void (*finish_run)(struct coda_ctx *ctx);
184 void (*seq_end_work)(struct work_struct *work);
185 void (*release)(struct coda_ctx *ctx);
189 struct coda_dev *dev;
190 struct mutex buffer_mutex;
191 struct list_head list;
192 struct work_struct pic_run_work;
193 struct work_struct seq_end_work;
194 struct completion completion;
195 const struct coda_video_device *cvd;
196 const struct coda_context_ops *ops;
204 struct coda_q_data q_data[2];
205 enum coda_inst_type inst_type;
206 const struct coda_codec *codec;
207 enum v4l2_colorspace colorspace;
208 struct coda_params params;
209 struct v4l2_ctrl_handler ctrls;
213 char vpu_header[3][64];
214 int vpu_header_size[3];
215 struct kfifo bitstream_fifo;
216 struct mutex bitstream_mutex;
217 struct coda_aux_buf bitstream;
219 struct coda_aux_buf parabuf;
220 struct coda_aux_buf psbuf;
221 struct coda_aux_buf slicebuf;
222 struct coda_aux_buf internal_frames[CODA_MAX_FRAMEBUFFERS];
223 u32 frame_types[CODA_MAX_FRAMEBUFFERS];
224 struct coda_buffer_meta frame_metas[CODA_MAX_FRAMEBUFFERS];
225 u32 frame_errors[CODA_MAX_FRAMEBUFFERS];
226 struct list_head buffer_meta_list;
227 struct coda_aux_buf workbuf;
228 int num_internal_frames;
231 struct coda_iram_info iram_info;
232 struct gdi_tiled_map tiled_map;
233 u32 bit_stream_param;
237 struct dentry *debugfs_entry;
241 extern int coda_debug;
243 void coda_write(struct coda_dev *dev, u32 data, u32 reg);
244 unsigned int coda_read(struct coda_dev *dev, u32 reg);
245 void coda_write_base(struct coda_ctx *ctx, struct coda_q_data *q_data,
246 struct vb2_buffer *buf, unsigned int reg_y);
248 int coda_alloc_aux_buf(struct coda_dev *dev, struct coda_aux_buf *buf,
249 size_t size, const char *name, struct dentry *parent);
250 void coda_free_aux_buf(struct coda_dev *dev, struct coda_aux_buf *buf);
252 int coda_encoder_queue_init(void *priv, struct vb2_queue *src_vq,
253 struct vb2_queue *dst_vq);
254 int coda_decoder_queue_init(void *priv, struct vb2_queue *src_vq,
255 struct vb2_queue *dst_vq);
257 int coda_hw_reset(struct coda_ctx *ctx);
259 void coda_fill_bitstream(struct coda_ctx *ctx);
261 void coda_set_gdi_regs(struct coda_ctx *ctx);
263 static inline struct coda_q_data *get_q_data(struct coda_ctx *ctx,
264 enum v4l2_buf_type type)
267 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
268 return &(ctx->q_data[V4L2_M2M_SRC]);
269 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
270 return &(ctx->q_data[V4L2_M2M_DST]);
276 const char *coda_product_name(int product);
278 int coda_check_firmware(struct coda_dev *dev);
280 static inline unsigned int coda_get_bitstream_payload(struct coda_ctx *ctx)
282 return kfifo_len(&ctx->bitstream_fifo);
285 void coda_bit_stream_end_flag(struct coda_ctx *ctx);
287 int coda_h264_padding(int size, char *p);
289 bool coda_jpeg_check_buffer(struct coda_ctx *ctx, struct vb2_buffer *vb);
290 int coda_jpeg_write_tables(struct coda_ctx *ctx);
291 void coda_set_jpeg_compression_quality(struct coda_ctx *ctx, int quality);
293 extern const struct coda_context_ops coda_bit_encode_ops;
294 extern const struct coda_context_ops coda_bit_decode_ops;
296 irqreturn_t coda_irq_handler(int irq, void *data);