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/idr.h>
20 #include <linux/irqreturn.h>
21 #include <linux/mutex.h>
22 #include <linux/kfifo.h>
23 #include <linux/videodev2.h>
25 #include <media/v4l2-ctrls.h>
26 #include <media/v4l2-device.h>
27 #include <media/v4l2-fh.h>
28 #include <media/videobuf2-v4l2.h>
30 #include "coda_regs.h"
32 #define CODA_MAX_FRAMEBUFFERS 19
33 #define FMO_SLICE_SAVE_BUF_SIZE (32)
52 struct coda_video_device
;
56 enum coda_product product
;
57 const struct coda_codec
*codecs
;
58 unsigned int num_codecs
;
59 const struct coda_video_device
**vdevs
;
60 unsigned int num_vdevs
;
70 struct debugfs_blob_wrapper blob
;
71 struct dentry
*dentry
;
75 struct v4l2_device v4l2_dev
;
76 struct video_device vfd
[5];
77 struct platform_device
*plat_dev
;
78 const struct coda_devtype
*devtype
;
80 struct vdoa_data
*vdoa
;
82 void __iomem
*regs_base
;
85 struct reset_control
*rstc
;
87 struct coda_aux_buf codebuf
;
88 struct coda_aux_buf tempbuf
;
89 struct coda_aux_buf workbuf
;
90 struct gen_pool
*iram_pool
;
91 struct coda_aux_buf iram
;
94 struct mutex dev_mutex
;
95 struct mutex coda_mutex
;
96 struct workqueue_struct
*workqueue
;
97 struct v4l2_m2m_dev
*m2m_dev
;
98 struct list_head instances
;
100 struct dentry
*debugfs_root
;
111 struct coda_huff_tab
;
119 u8 h264_disable_deblocking_filter_idc
;
120 s8 h264_slice_alpha_c0_offset_div2
;
121 s8 h264_slice_beta_offset_div2
;
129 u8 jpeg_restart_interval
;
130 u8
*jpeg_qmat_tab
[3];
133 enum v4l2_mpeg_video_multi_slice_mode slice_mode
;
143 struct coda_buffer_meta
{
144 struct list_head list
;
146 struct v4l2_timecode timecode
;
152 /* Per-queue, driver-specific private data */
156 unsigned int bytesperline
;
157 unsigned int sizeimage
;
159 struct v4l2_rect rect
;
162 struct coda_iram_info
{
164 phys_addr_t buf_bit_use
;
165 phys_addr_t buf_ip_ac_dc_use
;
166 phys_addr_t buf_dbk_y_use
;
167 phys_addr_t buf_dbk_c_use
;
168 phys_addr_t buf_ovl_use
;
169 phys_addr_t buf_btp_use
;
170 phys_addr_t search_ram_paddr
;
173 phys_addr_t next_paddr
;
176 #define GDI_LINEAR_FRAME_MAP 0
177 #define GDI_TILED_FRAME_MB_RASTER_MAP 1
181 struct coda_context_ops
{
182 int (*queue_init
)(void *priv
, struct vb2_queue
*src_vq
,
183 struct vb2_queue
*dst_vq
);
184 int (*reqbufs
)(struct coda_ctx
*ctx
, struct v4l2_requestbuffers
*rb
);
185 int (*start_streaming
)(struct coda_ctx
*ctx
);
186 int (*prepare_run
)(struct coda_ctx
*ctx
);
187 void (*finish_run
)(struct coda_ctx
*ctx
);
188 void (*run_timeout
)(struct coda_ctx
*ctx
);
189 void (*seq_end_work
)(struct work_struct
*work
);
190 void (*release
)(struct coda_ctx
*ctx
);
194 struct coda_dev
*dev
;
195 struct mutex buffer_mutex
;
196 struct list_head list
;
197 struct work_struct pic_run_work
;
198 struct work_struct seq_end_work
;
199 struct completion completion
;
200 const struct coda_video_device
*cvd
;
201 const struct coda_context_ops
*ops
;
209 struct coda_q_data q_data
[2];
210 enum coda_inst_type inst_type
;
211 const struct coda_codec
*codec
;
212 enum v4l2_colorspace colorspace
;
213 enum v4l2_xfer_func xfer_func
;
214 enum v4l2_ycbcr_encoding ycbcr_enc
;
215 enum v4l2_quantization quantization
;
216 struct coda_params params
;
217 struct v4l2_ctrl_handler ctrls
;
218 struct v4l2_ctrl
*h264_profile_ctrl
;
219 struct v4l2_ctrl
*h264_level_ctrl
;
223 char vpu_header
[3][64];
224 int vpu_header_size
[3];
225 struct kfifo bitstream_fifo
;
226 struct mutex bitstream_mutex
;
227 struct coda_aux_buf bitstream
;
229 struct coda_aux_buf parabuf
;
230 struct coda_aux_buf psbuf
;
231 struct coda_aux_buf slicebuf
;
232 struct coda_aux_buf internal_frames
[CODA_MAX_FRAMEBUFFERS
];
233 u32 frame_types
[CODA_MAX_FRAMEBUFFERS
];
234 struct coda_buffer_meta frame_metas
[CODA_MAX_FRAMEBUFFERS
];
235 u32 frame_errors
[CODA_MAX_FRAMEBUFFERS
];
236 struct list_head buffer_meta_list
;
237 spinlock_t buffer_meta_lock
;
239 struct coda_aux_buf workbuf
;
240 int num_internal_frames
;
243 struct coda_iram_info iram_info
;
245 u32 bit_stream_param
;
249 struct dentry
*debugfs_entry
;
252 struct vdoa_ctx
*vdoa
;
255 extern int coda_debug
;
257 void coda_write(struct coda_dev
*dev
, u32 data
, u32 reg
);
258 unsigned int coda_read(struct coda_dev
*dev
, u32 reg
);
259 void coda_write_base(struct coda_ctx
*ctx
, struct coda_q_data
*q_data
,
260 struct vb2_v4l2_buffer
*buf
, unsigned int reg_y
);
262 int coda_alloc_aux_buf(struct coda_dev
*dev
, struct coda_aux_buf
*buf
,
263 size_t size
, const char *name
, struct dentry
*parent
);
264 void coda_free_aux_buf(struct coda_dev
*dev
, struct coda_aux_buf
*buf
);
266 int coda_encoder_queue_init(void *priv
, struct vb2_queue
*src_vq
,
267 struct vb2_queue
*dst_vq
);
268 int coda_decoder_queue_init(void *priv
, struct vb2_queue
*src_vq
,
269 struct vb2_queue
*dst_vq
);
271 int coda_hw_reset(struct coda_ctx
*ctx
);
273 void coda_fill_bitstream(struct coda_ctx
*ctx
, struct list_head
*buffer_list
);
275 void coda_set_gdi_regs(struct coda_ctx
*ctx
);
277 static inline struct coda_q_data
*get_q_data(struct coda_ctx
*ctx
,
278 enum v4l2_buf_type type
)
281 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
282 return &(ctx
->q_data
[V4L2_M2M_SRC
]);
283 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
284 return &(ctx
->q_data
[V4L2_M2M_DST
]);
290 const char *coda_product_name(int product
);
292 int coda_check_firmware(struct coda_dev
*dev
);
294 static inline unsigned int coda_get_bitstream_payload(struct coda_ctx
*ctx
)
296 return kfifo_len(&ctx
->bitstream_fifo
);
299 void coda_bit_stream_end_flag(struct coda_ctx
*ctx
);
301 void coda_m2m_buf_done(struct coda_ctx
*ctx
, struct vb2_v4l2_buffer
*buf
,
302 enum vb2_buffer_state state
);
304 int coda_h264_filler_nal(int size
, char *p
);
305 int coda_h264_padding(int size
, char *p
);
306 int coda_h264_profile(int profile_idc
);
307 int coda_h264_level(int level_idc
);
308 int coda_sps_parse_profile(struct coda_ctx
*ctx
, struct vb2_buffer
*vb
);
309 int coda_h264_sps_fixup(struct coda_ctx
*ctx
, int width
, int height
, char *buf
,
310 int *size
, int max_size
);
312 bool coda_jpeg_check_buffer(struct coda_ctx
*ctx
, struct vb2_buffer
*vb
);
313 int coda_jpeg_write_tables(struct coda_ctx
*ctx
);
314 void coda_set_jpeg_compression_quality(struct coda_ctx
*ctx
, int quality
);
316 extern const struct coda_context_ops coda_bit_encode_ops
;
317 extern const struct coda_context_ops coda_bit_decode_ops
;
319 irqreturn_t
coda_irq_handler(int irq
, void *data
);
321 #endif /* __CODA_H__ */