2 * Samsung S5P Multi Format Codec v 5.0
4 * This file contains definitions of enums and structs used by the codec
7 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
8 * Kamil Debski, <k.debski@samsung.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the
13 * License, or (at your option) any later version
16 #ifndef S5P_MFC_COMMON_H_
17 #define S5P_MFC_COMMON_H_
19 #include <linux/videodev2.h>
20 #include <linux/workqueue.h>
22 #include <media/v4l2-device.h>
23 #include <media/v4l2-ioctl.h>
25 #include <media/videobuf2-core.h>
29 #if defined(CONFIG_S5P_SYSMMU_MFC_L) && defined(CONFIG_S5P_SYSMMU_MFC_R)
33 #define MFC_MAX_EXTRA_DPB 5
34 #define MFC_MAX_BUFFERS 32
35 #define MFC_MAX_REF_BUFS 2
36 #define MFC_FRAME_PLANES 2
38 #define MFC_NUM_CONTEXTS 4
39 /* Interrupt timeout */
40 #define MFC_INT_TIMEOUT 2000
41 /* Busy wait timeout */
42 #define MFC_BW_TIMEOUT 500
43 /* Watchdog interval */
44 #define MFC_WATCHDOG_INTERVAL 1000
45 /* After how many executions watchdog should assume lock up */
46 #define MFC_WATCHDOG_CNT 10
48 #define MFC_NO_INSTANCE_SET -1
50 #define MFC_ENC_CAP_PLANE_COUNT 1
51 #define MFC_ENC_OUT_PLANE_COUNT 2
53 #define MFC_NAME_LEN 16
56 #define MFC_WORKQUEUE_LEN 32
59 * enum s5p_mfc_inst_type - The type of an MFC device node.
61 enum s5p_mfc_node_type {
68 * enum s5p_mfc_inst_type - The type of an MFC instance.
70 enum s5p_mfc_inst_type {
77 * enum s5p_mfc_inst_state - The state of an MFC instance.
79 enum s5p_mfc_inst_state {
91 MFCINST_RES_CHANGE_INIT,
92 MFCINST_RES_CHANGE_FLUSH,
93 MFCINST_RES_CHANGE_END,
97 * enum s5p_mfc_queue_state - The state of buffer queue.
99 enum s5p_mfc_queue_state {
101 QUEUE_BUFS_REQUESTED,
109 * struct s5p_mfc_buf - MFC buffer
113 struct list_head list;
114 struct vb2_buffer *b;
128 #ifdef CONFIG_ARCH_S5PV310
130 #ifdef CONFIG_PM_RUNTIME
131 struct device *device;
137 const struct firmware *info;
143 * struct s5p_mfc_dev - The struct containing driver internal parameters.
146 struct v4l2_device v4l2_dev;
147 struct video_device *vfd_dec;
148 struct video_device *vfd_enc;
149 struct platform_device *plat_dev;
151 void __iomem *regs_base;
153 struct resource *mfc_mem;
155 struct s5p_mfc_pm pm;
156 struct s5p_mfc_fw fw;
162 struct mutex mfc_mutex;
166 unsigned int int_err;
167 wait_queue_head_t queue;
172 unsigned long hw_lock;
179 struct s5p_mfc_ctx *ctx[MFC_NUM_CONTEXTS];
181 unsigned long ctx_work_bits;
183 atomic_t watchdog_cnt;
184 struct timer_list watchdog_timer;
185 struct workqueue_struct *watchdog_workqueue;
186 struct work_struct watchdog_work;
188 struct vb2_alloc_ctx **alloc_ctx;
190 unsigned long clk_state;
191 struct work_struct work_struct;
192 struct workqueue_struct *irq_workqueue;
198 struct s5p_mfc_h264_enc_params {
200 enum v4l2_codec_mfc5x_enc_h264_profile profile;
202 enum v4l2_codec_mfc5x_enc_switch interlace;
203 enum v4l2_codec_mfc5x_enc_h264_loop_filter loop_filter_mode;
204 s8 loop_filter_alpha;
206 enum v4l2_codec_mfc5x_enc_h264_entropy_mode entropy_mode;
209 enum v4l2_codec_mfc5x_enc_switch _8x8_transform;
210 enum v4l2_codec_mfc5x_enc_switch rc_mb;
215 enum v4l2_codec_mfc5x_enc_switch_inv rc_mb_dark;
216 enum v4l2_codec_mfc5x_enc_switch_inv rc_mb_smooth;
217 enum v4l2_codec_mfc5x_enc_switch_inv rc_mb_static;
218 enum v4l2_codec_mfc5x_enc_switch_inv rc_mb_activity;
221 enum v4l2_codec_mfc5x_enc_switch ar_vui;
225 enum v4l2_codec_mfc5x_enc_switch open_gop;
232 struct s5p_mfc_mpeg4_enc_params {
235 enum v4l2_codec_mfc5x_enc_mpeg4_profile profile;
237 enum v4l2_codec_mfc5x_enc_switch quarter_pixel;
241 /* Common for MPEG4, H263 */
252 struct s5p_mfc_enc_params {
257 enum v4l2_codec_mfc5x_enc_multi_slice_mode slice_mode;
260 u16 intra_refresh_mb;
261 enum v4l2_codec_mfc5x_enc_switch pad;
265 enum v4l2_codec_mfc5x_enc_switch rc_frame;
267 u16 rc_reaction_coeff;
270 enum v4l2_codec_mfc5x_enc_seq_hdr_mode seq_hdr_mode;
271 enum v4l2_codec_mfc5x_enc_frame_skip_mode frame_skip_mode;
272 enum v4l2_codec_mfc5x_enc_switch fixed_target_bit;
275 struct s5p_mfc_h264_enc_params h264;
276 struct s5p_mfc_mpeg4_enc_params mpeg4;
280 enum s5p_mfc_ctrl_type {
281 MFC_CTRL_TYPE_SET = 0x1,
282 MFC_CTRL_TYPE_GET = 0x2,
285 enum s5p_mfc_ctrl_mode {
286 MFC_CTRL_MODE_NONE = 0x0,
287 MFC_CTRL_MODE_SFR = 0x1,
288 MFC_CTRL_MODE_SHM = 0x2,
289 MFC_CTRL_MODE_CST = 0x4,
292 struct s5p_mfc_ctrl_cfg {
293 enum s5p_mfc_ctrl_type type;
296 unsigned int is_dynamic;
298 unsigned int is_volatile; /* only for MFC_CTRL_TYPE_SET */
303 unsigned int flag_mode; /* only for MFC_CTRL_TYPE_SET */
304 unsigned int flag_addr; /* only for MFC_CTRL_TYPE_SET */
305 unsigned int flag_shft; /* only for MFC_CTRL_TYPE_SET */
308 struct s5p_mfc_ctx_ctrl {
309 struct list_head list;
310 enum s5p_mfc_ctrl_type type;
313 unsigned int is_dynamic;
319 struct s5p_mfc_buf_ctrl {
320 struct list_head list;
324 unsigned int old_val; /* only for MFC_CTRL_TYPE_SET */
325 unsigned int is_volatile; /* only for MFC_CTRL_TYPE_SET */
326 unsigned int updated;
331 unsigned int flag_mode; /* only for MFC_CTRL_TYPE_SET */
332 unsigned int flag_addr; /* only for MFC_CTRL_TYPE_SET */
333 unsigned int flag_shft; /* only for MFC_CTRL_TYPE_SET */
336 struct s5p_mfc_codec_ops {
337 /* initialization routines */
338 int (*alloc_ctx_buf) (struct s5p_mfc_ctx *ctx);
339 int (*alloc_desc_buf) (struct s5p_mfc_ctx *ctx);
340 int (*get_init_arg) (struct s5p_mfc_ctx *ctx, void *arg);
341 int (*pre_seq_start) (struct s5p_mfc_ctx *ctx);
342 int (*post_seq_start) (struct s5p_mfc_ctx *ctx);
343 int (*set_init_arg) (struct s5p_mfc_ctx *ctx, void *arg);
344 int (*set_codec_bufs) (struct s5p_mfc_ctx *ctx);
345 int (*set_dpbs) (struct s5p_mfc_ctx *ctx); /* decoder */
346 /* execution routines */
347 int (*get_exe_arg) (struct s5p_mfc_ctx *ctx, void *arg);
348 int (*pre_frame_start) (struct s5p_mfc_ctx *ctx);
349 int (*post_frame_start) (struct s5p_mfc_ctx *ctx);
350 int (*multi_data_frame) (struct s5p_mfc_ctx *ctx);
351 int (*set_exe_arg) (struct s5p_mfc_ctx *ctx, void *arg);
352 /* configuration routines */
353 int (*get_codec_cfg) (struct s5p_mfc_ctx *ctx, unsigned int type, int *value);
354 int (*set_codec_cfg) (struct s5p_mfc_ctx *ctx, unsigned int type, int *value);
355 /* controls per buffer */
356 int (*init_ctx_ctrls) (struct s5p_mfc_ctx *ctx);
357 int (*cleanup_ctx_ctrls) (struct s5p_mfc_ctx *ctx);
358 int (*init_buf_ctrls) (struct s5p_mfc_ctx *ctx, enum s5p_mfc_ctrl_type type, unsigned int index);
359 int (*cleanup_buf_ctrls) (struct s5p_mfc_ctx *ctx, struct list_head *head);
360 int (*to_buf_ctrls) (struct s5p_mfc_ctx *ctx, struct list_head *head);
361 int (*to_ctx_ctrls) (struct s5p_mfc_ctx *ctx, struct list_head *head);
362 int (*set_buf_ctrls_val) (struct s5p_mfc_ctx *ctx, struct list_head *head);
363 int (*get_buf_ctrls_val) (struct s5p_mfc_ctx *ctx, struct list_head *head);
364 int (*recover_buf_ctrls_val) (struct s5p_mfc_ctx *ctx, struct list_head *head);
367 #define call_cop(c, op, args...) \
368 (((c)->c_ops->op) ? \
369 ((c)->c_ops->op(args)) : 0)
372 * struct s5p_mfc_ctx - This struct contains the instance context
375 struct s5p_mfc_dev *dev;
380 unsigned int int_err;
381 wait_queue_head_t queue;
383 struct s5p_mfc_fmt *src_fmt;
384 struct s5p_mfc_fmt *dst_fmt;
386 struct vb2_queue vq_src;
387 struct vb2_queue vq_dst;
389 struct list_head src_queue;
390 struct list_head dst_queue;
392 unsigned int src_queue_cnt;
393 unsigned int dst_queue_cnt;
395 enum s5p_mfc_inst_type type;
396 enum s5p_mfc_inst_state state;
399 /* Decoder parameters */
411 unsigned long consumed_stream;
414 unsigned int dpb_flush_flag;
426 enum s5p_mfc_queue_state capture_state;
427 enum s5p_mfc_queue_state output_state;
429 // size_t dec_dst_buf_luma[MFC_MAX_BUFFERS];
430 // size_t dec_dst_buf_chroma[MFC_MAX_BUFFERS];
432 struct s5p_mfc_buf src_bufs[MFC_MAX_BUFFERS];
434 struct s5p_mfc_buf dst_bufs[MFC_MAX_BUFFERS];
437 struct list_head ctrls;
439 struct list_head src_ctrls[MFC_MAX_BUFFERS];
440 struct list_head dst_ctrls[MFC_MAX_BUFFERS];
442 // int dec_dst_buf_cnt;
443 unsigned int sequence;
444 unsigned long dec_dst_flag;
445 size_t dec_src_buf_size;
450 int loop_filter_mpeg4;
460 //dma_addr_t context_dma;
468 //dma_addr_t shared_dma;
474 struct s5p_mfc_enc_params enc_params;
476 size_t enc_dst_buf_size;
479 enum v4l2_codec_mfc5x_enc_frame_type frame_type;
480 enum v4l2_codec_mfc5x_enc_force_frame_type force_frame_type;
482 struct list_head ref_queue;
483 unsigned int ref_queue_cnt;
485 struct s5p_mfc_codec_ops *c_ops;
488 #define MFC_FMT_DEC 0
489 #define MFC_FMT_ENC 1
490 #define MFC_FMT_RAW 2
500 #endif /* S5P_MFC_COMMON_H_ */