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 CODA_MAX_FRAME_SIZE 0x100000
30 #define FMO_SLICE_SAVE_BUF_SIZE (32)
50 enum coda_product product;
51 const struct coda_codec *codecs;
52 unsigned int num_codecs;
62 struct debugfs_blob_wrapper blob;
63 struct dentry *dentry;
67 struct v4l2_device v4l2_dev;
68 struct video_device vfd[2];
69 struct platform_device *plat_dev;
70 const struct coda_devtype *devtype;
72 void __iomem *regs_base;
75 struct reset_control *rstc;
77 struct coda_aux_buf codebuf;
78 struct coda_aux_buf tempbuf;
79 struct coda_aux_buf workbuf;
80 struct gen_pool *iram_pool;
81 struct coda_aux_buf iram;
84 struct mutex dev_mutex;
85 struct mutex coda_mutex;
86 struct workqueue_struct *workqueue;
87 struct v4l2_m2m_dev *m2m_dev;
88 struct vb2_alloc_ctx *alloc_ctx;
89 struct list_head instances;
90 unsigned long instance_mask;
91 struct dentry *debugfs_root;
102 struct coda_huff_tab;
110 u8 h264_deblk_enabled;
119 enum v4l2_mpeg_video_multi_slice_mode slice_mode;
126 struct coda_timestamp {
127 struct list_head list;
129 struct v4l2_timecode timecode;
130 struct timeval timestamp;
133 /* Per-queue, driver-specific private data */
137 unsigned int bytesperline;
138 unsigned int sizeimage;
140 struct v4l2_rect rect;
143 struct coda_iram_info {
145 phys_addr_t buf_bit_use;
146 phys_addr_t buf_ip_ac_dc_use;
147 phys_addr_t buf_dbk_y_use;
148 phys_addr_t buf_dbk_c_use;
149 phys_addr_t buf_ovl_use;
150 phys_addr_t buf_btp_use;
151 phys_addr_t search_ram_paddr;
154 phys_addr_t next_paddr;
157 struct gdi_tiled_map {
164 #define GDI_LINEAR_FRAME_MAP 0
169 struct coda_context_ops {
170 int (*queue_init)(void *priv, struct vb2_queue *src_vq,
171 struct vb2_queue *dst_vq);
172 int (*start_streaming)(struct coda_ctx *ctx);
173 int (*prepare_run)(struct coda_ctx *ctx);
174 void (*finish_run)(struct coda_ctx *ctx);
175 void (*seq_end_work)(struct work_struct *work);
176 void (*release)(struct coda_ctx *ctx);
180 struct coda_dev *dev;
181 struct mutex buffer_mutex;
182 struct list_head list;
183 struct work_struct pic_run_work;
184 struct work_struct seq_end_work;
185 struct completion completion;
186 const struct coda_context_ops *ops;
195 struct coda_q_data q_data[2];
196 enum coda_inst_type inst_type;
197 const struct coda_codec *codec;
198 enum v4l2_colorspace colorspace;
199 struct coda_params params;
200 struct v4l2_ctrl_handler ctrls;
204 char vpu_header[3][64];
205 int vpu_header_size[3];
206 struct kfifo bitstream_fifo;
207 struct mutex bitstream_mutex;
208 struct coda_aux_buf bitstream;
210 struct coda_aux_buf parabuf;
211 struct coda_aux_buf psbuf;
212 struct coda_aux_buf slicebuf;
213 struct coda_aux_buf internal_frames[CODA_MAX_FRAMEBUFFERS];
214 u32 frame_types[CODA_MAX_FRAMEBUFFERS];
215 struct coda_timestamp frame_timestamps[CODA_MAX_FRAMEBUFFERS];
216 u32 frame_errors[CODA_MAX_FRAMEBUFFERS];
217 struct list_head timestamp_list;
218 struct coda_aux_buf workbuf;
219 int num_internal_frames;
222 struct coda_iram_info iram_info;
223 struct gdi_tiled_map tiled_map;
224 u32 bit_stream_param;
228 struct dentry *debugfs_entry;
231 extern int coda_debug;
233 void coda_write(struct coda_dev *dev, u32 data, u32 reg);
234 unsigned int coda_read(struct coda_dev *dev, u32 reg);
236 int coda_alloc_aux_buf(struct coda_dev *dev, struct coda_aux_buf *buf,
237 size_t size, const char *name, struct dentry *parent);
238 void coda_free_aux_buf(struct coda_dev *dev, struct coda_aux_buf *buf);
240 static inline int coda_alloc_context_buf(struct coda_ctx *ctx,
241 struct coda_aux_buf *buf, size_t size,
244 return coda_alloc_aux_buf(ctx->dev, buf, size, name, ctx->debugfs_entry);
247 int coda_encoder_queue_init(void *priv, struct vb2_queue *src_vq,
248 struct vb2_queue *dst_vq);
249 int coda_decoder_queue_init(void *priv, struct vb2_queue *src_vq,
250 struct vb2_queue *dst_vq);
252 int coda_hw_reset(struct coda_ctx *ctx);
254 void coda_fill_bitstream(struct coda_ctx *ctx);
256 void coda_set_gdi_regs(struct coda_ctx *ctx);
258 static inline struct coda_q_data *get_q_data(struct coda_ctx *ctx,
259 enum v4l2_buf_type type)
262 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
263 return &(ctx->q_data[V4L2_M2M_SRC]);
264 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
265 return &(ctx->q_data[V4L2_M2M_DST]);
271 const char *coda_product_name(int product);
273 int coda_check_firmware(struct coda_dev *dev);
275 static inline int coda_get_bitstream_payload(struct coda_ctx *ctx)
277 return kfifo_len(&ctx->bitstream_fifo);
280 void coda_bit_stream_end_flag(struct coda_ctx *ctx);
282 int coda_h264_padding(int size, char *p);
284 extern const struct coda_context_ops coda_bit_encode_ops;
285 extern const struct coda_context_ops coda_bit_decode_ops;
287 irqreturn_t coda_irq_handler(int irq, void *data);