[media] s5p-mfc: Use generic of_device_get_match_data helper
[linux-2.6-block.git] / drivers / media / platform / s5p-mfc / s5p_mfc_common.h
CommitLineData
af935746
KD
1/*
2 * Samsung S5P Multi Format Codec v 5.0
3 *
4 * This file contains definitions of enums and structs used by the codec
5 * driver.
6 *
7 * Copyright (C) 2011 Samsung Electronics Co., Ltd.
8 * Kamil Debski, <k.debski@samsung.com>
9 *
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
14 */
15
16#ifndef S5P_MFC_COMMON_H_
17#define S5P_MFC_COMMON_H_
18
af935746
KD
19#include <linux/platform_device.h>
20#include <linux/videodev2.h>
21#include <media/v4l2-ctrls.h>
22#include <media/v4l2-device.h>
23#include <media/v4l2-ioctl.h>
c139990e 24#include <media/videobuf2-v4l2.h>
f96f3cfa 25#include "regs-mfc.h"
e2b9deb2 26#include "regs-mfc-v8.h"
af935746 27
e0d80c8a
JMC
28#define S5P_MFC_NAME "s5p-mfc"
29
af935746
KD
30/* Definitions related to MFC memory */
31
32/* Offset base used to differentiate between CAPTURE and OUTPUT
33* while mmaping */
a301ea1f 34#define DST_QUEUE_OFF_BASE (1 << 30)
af935746 35
af935746
KD
36#define MFC_BANK1_ALLOC_CTX 0
37#define MFC_BANK2_ALLOC_CTX 1
38
39#define MFC_BANK1_ALIGN_ORDER 13
40#define MFC_BANK2_ALIGN_ORDER 13
41#define MFC_BASE_ALIGN_ORDER 17
42
77ba6b73
AK
43#define MFC_FW_MAX_VERSIONS 2
44
af935746
KD
45#include <media/videobuf2-dma-contig.h>
46
af935746
KD
47/* MFC definitions */
48#define MFC_MAX_EXTRA_DPB 5
49#define MFC_MAX_BUFFERS 32
50#define MFC_NUM_CONTEXTS 4
51/* Interrupt timeout */
52#define MFC_INT_TIMEOUT 2000
53/* Busy wait timeout */
54#define MFC_BW_TIMEOUT 500
55/* Watchdog interval */
56#define MFC_WATCHDOG_INTERVAL 1000
57/* After how many executions watchdog should assume lock up */
58#define MFC_WATCHDOG_CNT 10
59#define MFC_NO_INSTANCE_SET -1
60#define MFC_ENC_CAP_PLANE_COUNT 1
61#define MFC_ENC_OUT_PLANE_COUNT 2
62#define STUFF_BYTE 4
3a967706 63#define MFC_MAX_CTRLS 77
43a1ea1f
AK
64
65#define S5P_MFC_CODEC_NONE -1
66#define S5P_MFC_CODEC_H264_DEC 0
67#define S5P_MFC_CODEC_H264_MVC_DEC 1
68#define S5P_MFC_CODEC_VC1_DEC 2
69#define S5P_MFC_CODEC_MPEG4_DEC 3
70#define S5P_MFC_CODEC_MPEG2_DEC 4
71#define S5P_MFC_CODEC_H263_DEC 5
72#define S5P_MFC_CODEC_VC1RCV_DEC 6
73#define S5P_MFC_CODEC_VP8_DEC 7
74
75#define S5P_MFC_CODEC_H264_ENC 20
76#define S5P_MFC_CODEC_H264_MVC_ENC 21
77#define S5P_MFC_CODEC_MPEG4_ENC 22
78#define S5P_MFC_CODEC_H263_ENC 23
3a967706 79#define S5P_MFC_CODEC_VP8_ENC 24
43a1ea1f
AK
80
81#define S5P_MFC_R2H_CMD_EMPTY 0
82#define S5P_MFC_R2H_CMD_SYS_INIT_RET 1
83#define S5P_MFC_R2H_CMD_OPEN_INSTANCE_RET 2
84#define S5P_MFC_R2H_CMD_SEQ_DONE_RET 3
85#define S5P_MFC_R2H_CMD_INIT_BUFFERS_RET 4
86#define S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET 6
87#define S5P_MFC_R2H_CMD_SLEEP_RET 7
88#define S5P_MFC_R2H_CMD_WAKEUP_RET 8
89#define S5P_MFC_R2H_CMD_COMPLETE_SEQ_RET 9
90#define S5P_MFC_R2H_CMD_DPB_FLUSH_RET 10
91#define S5P_MFC_R2H_CMD_NAL_ABORT_RET 11
92#define S5P_MFC_R2H_CMD_FW_STATUS_RET 12
93#define S5P_MFC_R2H_CMD_FRAME_DONE_RET 13
94#define S5P_MFC_R2H_CMD_FIELD_DONE_RET 14
95#define S5P_MFC_R2H_CMD_SLICE_DONE_RET 15
96#define S5P_MFC_R2H_CMD_ENC_BUFFER_FUL_RET 16
97#define S5P_MFC_R2H_CMD_ERR_RET 32
af935746 98
1bce6fb3
MS
99#define MFC_MAX_CLOCKS 4
100
af935746
KD
101#define mfc_read(dev, offset) readl(dev->regs_base + (offset))
102#define mfc_write(dev, data, offset) writel((data), dev->regs_base + \
103 (offset))
104
105/**
106 * enum s5p_mfc_fmt_type - type of the pixelformat
107 */
108enum s5p_mfc_fmt_type {
109 MFC_FMT_DEC,
110 MFC_FMT_ENC,
111 MFC_FMT_RAW,
112};
113
af935746
KD
114/**
115 * enum s5p_mfc_inst_type - The type of an MFC instance.
116 */
117enum s5p_mfc_inst_type {
118 MFCINST_INVALID,
119 MFCINST_DECODER,
120 MFCINST_ENCODER,
121};
122
123/**
124 * enum s5p_mfc_inst_state - The state of an MFC instance.
125 */
126enum s5p_mfc_inst_state {
127 MFCINST_FREE = 0,
128 MFCINST_INIT = 100,
129 MFCINST_GOT_INST,
130 MFCINST_HEAD_PARSED,
e9d98ddc 131 MFCINST_HEAD_PRODUCED,
af935746
KD
132 MFCINST_BUFS_SET,
133 MFCINST_RUNNING,
134 MFCINST_FINISHING,
135 MFCINST_FINISHED,
136 MFCINST_RETURN_INST,
137 MFCINST_ERROR,
138 MFCINST_ABORT,
8f23cc02 139 MFCINST_FLUSH,
af935746
KD
140 MFCINST_RES_CHANGE_INIT,
141 MFCINST_RES_CHANGE_FLUSH,
142 MFCINST_RES_CHANGE_END,
143};
144
145/**
146 * enum s5p_mfc_queue_state - The state of buffer queue.
147 */
148enum s5p_mfc_queue_state {
149 QUEUE_FREE,
150 QUEUE_BUFS_REQUESTED,
151 QUEUE_BUFS_QUERIED,
152 QUEUE_BUFS_MMAPED,
153};
154
155/**
156 * enum s5p_mfc_decode_arg - type of frame decoding
157 */
158enum s5p_mfc_decode_arg {
159 MFC_DEC_FRAME,
160 MFC_DEC_LAST_FRAME,
161 MFC_DEC_RES_CHANGE,
162};
163
77ba6b73
AK
164enum s5p_mfc_fw_ver {
165 MFC_FW_V1,
166 MFC_FW_V2,
167};
168
f9f715a9
AH
169#define MFC_BUF_FLAG_USED (1 << 0)
170#define MFC_BUF_FLAG_EOS (1 << 1)
171
af935746
KD
172struct s5p_mfc_ctx;
173
174/**
175 * struct s5p_mfc_buf - MFC buffer
176 */
177struct s5p_mfc_buf {
2d700715 178 struct vb2_v4l2_buffer *b;
af935746 179 struct list_head list;
af935746
KD
180 union {
181 struct {
182 size_t luma;
183 size_t chroma;
184 } raw;
185 size_t stream;
186 } cookie;
f9f715a9 187 int flags;
af935746
KD
188};
189
190/**
191 * struct s5p_mfc_pm - power management data structure
192 */
193struct s5p_mfc_pm {
af935746 194 struct clk *clock_gate;
4a5ab64c 195 const char * const *clk_names;
1bce6fb3
MS
196 struct clk *clocks[MFC_MAX_CLOCKS];
197 int num_clocks;
c5086f13 198 bool use_clock_gating;
1bce6fb3 199
af935746
KD
200 struct device *device;
201};
202
8f532a7f
AK
203struct s5p_mfc_buf_size_v5 {
204 unsigned int h264_ctx;
205 unsigned int non_h264_ctx;
206 unsigned int dsc;
207 unsigned int shm;
208};
209
f96f3cfa
JP
210struct s5p_mfc_buf_size_v6 {
211 unsigned int dev_ctx;
212 unsigned int h264_dec_ctx;
213 unsigned int other_dec_ctx;
214 unsigned int h264_enc_ctx;
215 unsigned int other_enc_ctx;
216};
217
8f532a7f
AK
218struct s5p_mfc_buf_size {
219 unsigned int fw;
220 unsigned int cpb;
221 void *priv;
222};
223
8f532a7f
AK
224struct s5p_mfc_variant {
225 unsigned int version;
226 unsigned int port_num;
9aa5f008 227 u32 version_bit;
8f532a7f 228 struct s5p_mfc_buf_size *buf_size;
77ba6b73 229 char *fw_name[MFC_FW_MAX_VERSIONS];
1bce6fb3
MS
230 const char *clk_names[MFC_MAX_CLOCKS];
231 int num_clocks;
c5086f13 232 bool use_clock_gating;
8f532a7f
AK
233};
234
235/**
236 * struct s5p_mfc_priv_buf - represents internal used buffer
8f532a7f
AK
237 * @ofs: offset of each buffer, will be used for MFC
238 * @virt: kernel virtual address, only valid when the
239 * buffer accessed by driver
240 * @dma: DMA address, only valid when kernel DMA API used
241 * @size: size of the buffer
242 */
243struct s5p_mfc_priv_buf {
8f532a7f
AK
244 unsigned long ofs;
245 void *virt;
246 dma_addr_t dma;
247 size_t size;
248};
249
af935746
KD
250/**
251 * struct s5p_mfc_dev - The struct containing driver internal parameters.
252 *
253 * @v4l2_dev: v4l2_device
254 * @vfd_dec: video device for decoding
255 * @vfd_enc: video device for encoding
256 * @plat_dev: platform device
257 * @mem_dev_l: child device of the left memory bank (0)
258 * @mem_dev_r: child device of the right memory bank (1)
259 * @regs_base: base address of the MFC hw registers
260 * @irq: irq resource
af935746
KD
261 * @dec_ctrl_handler: control framework handler for decoding
262 * @enc_ctrl_handler: control framework handler for encoding
263 * @pm: power management control
8f532a7f 264 * @variant: MFC hardware variant information
af935746
KD
265 * @num_inst: couter of active MFC instances
266 * @irqlock: lock for operations on videobuf2 queues
267 * @condlock: lock for changing/checking if a context is ready to be
268 * processed
269 * @mfc_mutex: lock for video_device
270 * @int_cond: variable used by the waitqueue
271 * @int_type: type of last interrupt
272 * @int_err: error number for last interrupt
273 * @queue: waitqueue for waiting for completion of device commands
274 * @fw_size: size of firmware
2e731e44
KD
275 * @fw_virt_addr: virtual firmware address
276 * @bank1: address of the beginning of bank 1 memory
277 * @bank2: address of the beginning of bank 2 memory
af935746
KD
278 * @hw_lock: used for hardware locking
279 * @ctx: array of driver contexts
280 * @curr_ctx: number of the currently running context
281 * @ctx_work_bits: used to mark which contexts are waiting for hardware
282 * @watchdog_cnt: counter for the watchdog
283 * @watchdog_workqueue: workqueue for the watchdog
284 * @watchdog_work: worker for the watchdog
af935746 285 * @enter_suspend: flag set when entering suspend
f96f3cfa 286 * @ctx_buf: common context memory (MFCv6)
43a1ea1f
AK
287 * @warn_start: hardware error code from which warnings start
288 * @mfc_ops: ops structure holding HW operation function pointers
289 * @mfc_cmds: cmd structure holding HW commands function pointers
d188b679 290 * @mfc_regs: structure holding MFC registers
77ba6b73 291 * @fw_ver: loaded firmware sub-version
d188b679 292 * risc_on: flag indicates RISC is on or off
af935746
KD
293 *
294 */
295struct s5p_mfc_dev {
296 struct v4l2_device v4l2_dev;
297 struct video_device *vfd_dec;
298 struct video_device *vfd_enc;
299 struct platform_device *plat_dev;
300 struct device *mem_dev_l;
301 struct device *mem_dev_r;
302 void __iomem *regs_base;
303 int irq;
af935746
KD
304 struct v4l2_ctrl_handler dec_ctrl_handler;
305 struct v4l2_ctrl_handler enc_ctrl_handler;
306 struct s5p_mfc_pm pm;
4a5ab64c 307 const struct s5p_mfc_variant *variant;
af935746 308 int num_inst;
7969b125 309 spinlock_t irqlock; /* lock when operating on context */
af935746
KD
310 spinlock_t condlock; /* lock when changing/checking if a context is
311 ready to be processed */
312 struct mutex mfc_mutex; /* video_device lock */
313 int int_cond;
314 int int_type;
315 unsigned int int_err;
316 wait_queue_head_t queue;
317 size_t fw_size;
2e731e44
KD
318 void *fw_virt_addr;
319 dma_addr_t bank1;
320 dma_addr_t bank2;
af935746
KD
321 unsigned long hw_lock;
322 struct s5p_mfc_ctx *ctx[MFC_NUM_CONTEXTS];
323 int curr_ctx;
324 unsigned long ctx_work_bits;
325 atomic_t watchdog_cnt;
326 struct timer_list watchdog_timer;
327 struct workqueue_struct *watchdog_workqueue;
328 struct work_struct watchdog_work;
af935746 329 unsigned long enter_suspend;
43a1ea1f 330
f96f3cfa 331 struct s5p_mfc_priv_buf ctx_buf;
43a1ea1f
AK
332 int warn_start;
333 struct s5p_mfc_hw_ops *mfc_ops;
334 struct s5p_mfc_hw_cmds *mfc_cmds;
6a9c6f68 335 const struct s5p_mfc_regs *mfc_regs;
77ba6b73 336 enum s5p_mfc_fw_ver fw_ver;
d7dce6a3 337 bool risc_on; /* indicates if RISC is on or off */
af935746
KD
338};
339
340/**
341 * struct s5p_mfc_h264_enc_params - encoding parameters for h264
342 */
343struct s5p_mfc_h264_enc_params {
344 enum v4l2_mpeg_video_h264_profile profile;
345 enum v4l2_mpeg_video_h264_loop_filter_mode loop_filter_mode;
346 s8 loop_filter_alpha;
347 s8 loop_filter_beta;
348 enum v4l2_mpeg_video_h264_entropy_mode entropy_mode;
349 u8 max_ref_pic;
350 u8 num_ref_pic_4p;
351 int _8x8_transform;
af935746
KD
352 int rc_mb_dark;
353 int rc_mb_smooth;
354 int rc_mb_static;
355 int rc_mb_activity;
356 int vui_sar;
357 u8 vui_sar_idc;
358 u16 vui_ext_sar_width;
359 u16 vui_ext_sar_height;
360 int open_gop;
361 u16 open_gop_size;
362 u8 rc_frame_qp;
363 u8 rc_min_qp;
364 u8 rc_max_qp;
365 u8 rc_p_frame_qp;
366 u8 rc_b_frame_qp;
367 enum v4l2_mpeg_video_h264_level level_v4l2;
368 int level;
369 u16 cpb_size;
8f532a7f 370 int interlace;
f96f3cfa
JP
371 u8 hier_qp;
372 u8 hier_qp_type;
373 u8 hier_qp_layer;
374 u8 hier_qp_layer_qp[7];
375 u8 sei_frame_packing;
376 u8 sei_fp_curr_frame_0;
377 u8 sei_fp_arrangement_type;
378
379 u8 fmo;
380 u8 fmo_map_type;
381 u8 fmo_slice_grp;
382 u8 fmo_chg_dir;
383 u32 fmo_chg_rate;
384 u32 fmo_run_len[4];
385 u8 aso;
386 u32 aso_slice_order[8];
af935746
KD
387};
388
389/**
390 * struct s5p_mfc_mpeg4_enc_params - encoding parameters for h263 and mpeg4
391 */
392struct s5p_mfc_mpeg4_enc_params {
393 /* MPEG4 Only */
394 enum v4l2_mpeg_video_mpeg4_profile profile;
395 int quarter_pixel;
396 /* Common for MPEG4, H263 */
397 u16 vop_time_res;
398 u16 vop_frm_delta;
399 u8 rc_frame_qp;
400 u8 rc_min_qp;
401 u8 rc_max_qp;
402 u8 rc_p_frame_qp;
403 u8 rc_b_frame_qp;
404 enum v4l2_mpeg_video_mpeg4_level level_v4l2;
405 int level;
406};
407
3a967706
AK
408/**
409 * struct s5p_mfc_vp8_enc_params - encoding parameters for vp8
410 */
411struct s5p_mfc_vp8_enc_params {
412 u8 imd_4x4;
413 enum v4l2_vp8_num_partitions num_partitions;
414 enum v4l2_vp8_num_ref_frames num_ref;
415 u8 filter_level;
416 u8 filter_sharpness;
417 u32 golden_frame_ref_period;
418 enum v4l2_vp8_golden_frame_sel golden_frame_sel;
419 u8 hier_layer;
420 u8 hier_layer_qp[3];
4773ab99
AK
421 u8 rc_min_qp;
422 u8 rc_max_qp;
423 u8 rc_frame_qp;
424 u8 rc_p_frame_qp;
bbd8f3fe 425 u8 profile;
3a967706
AK
426};
427
af935746
KD
428/**
429 * struct s5p_mfc_enc_params - general encoding parameters
430 */
431struct s5p_mfc_enc_params {
432 u16 width;
433 u16 height;
a378a320
AG
434 u32 mv_h_range;
435 u32 mv_v_range;
af935746
KD
436
437 u16 gop_size;
438 enum v4l2_mpeg_video_multi_slice_mode slice_mode;
439 u16 slice_mb;
440 u32 slice_bit;
441 u16 intra_refresh_mb;
442 int pad;
443 u8 pad_luma;
444 u8 pad_cb;
445 u8 pad_cr;
446 int rc_frame;
8f532a7f 447 int rc_mb;
af935746
KD
448 u32 rc_bitrate;
449 u16 rc_reaction_coeff;
450 u16 vbv_size;
f96f3cfa 451 u32 vbv_delay;
af935746
KD
452
453 enum v4l2_mpeg_video_header_mode seq_hdr_mode;
454 enum v4l2_mpeg_mfc51_video_frame_skip_mode frame_skip_mode;
455 int fixed_target_bit;
456
457 u8 num_b_frame;
458 u32 rc_framerate_num;
459 u32 rc_framerate_denom;
af935746 460
ac5f867f 461 struct {
af935746
KD
462 struct s5p_mfc_h264_enc_params h264;
463 struct s5p_mfc_mpeg4_enc_params mpeg4;
3a967706 464 struct s5p_mfc_vp8_enc_params vp8;
af935746
KD
465 } codec;
466
467};
468
469/**
470 * struct s5p_mfc_codec_ops - codec ops, used by encoding
471 */
472struct s5p_mfc_codec_ops {
473 /* initialization routines */
474 int (*pre_seq_start) (struct s5p_mfc_ctx *ctx);
475 int (*post_seq_start) (struct s5p_mfc_ctx *ctx);
476 /* execution routines */
477 int (*pre_frame_start) (struct s5p_mfc_ctx *ctx);
478 int (*post_frame_start) (struct s5p_mfc_ctx *ctx);
479};
480
481#define call_cop(c, op, args...) \
482 (((c)->c_ops->op) ? \
483 ((c)->c_ops->op(args)) : 0)
484
485/**
486 * struct s5p_mfc_ctx - This struct contains the instance context
487 *
488 * @dev: pointer to the s5p_mfc_dev of the device
489 * @fh: struct v4l2_fh
490 * @num: number of the context that this structure describes
491 * @int_cond: variable used by the waitqueue
492 * @int_type: type of the last interrupt
493 * @int_err: error number received from MFC hw in the interrupt
494 * @queue: waitqueue that can be used to wait for this context to
495 * finish
496 * @src_fmt: source pixelformat information
497 * @dst_fmt: destination pixelformat information
498 * @vq_src: vb2 queue for source buffers
499 * @vq_dst: vb2 queue for destination buffers
500 * @src_queue: driver internal queue for source buffers
501 * @dst_queue: driver internal queue for destination buffers
502 * @src_queue_cnt: number of buffers queued on the source internal queue
503 * @dst_queue_cnt: number of buffers queued on the dest internal queue
504 * @type: type of the instance - decoder or encoder
505 * @state: state of the context
506 * @inst_no: number of hw instance associated with the context
507 * @img_width: width of the image that is decoded or encoded
508 * @img_height: height of the image that is decoded or encoded
509 * @buf_width: width of the buffer for processed image
510 * @buf_height: height of the buffer for processed image
511 * @luma_size: size of a luma plane
512 * @chroma_size: size of a chroma plane
513 * @mv_size: size of a motion vectors buffer
514 * @consumed_stream: number of bytes that have been used so far from the
515 * decoding buffer
516 * @dpb_flush_flag: flag used to indicate that a DPB buffers are being
517 * flushed
f96f3cfa
JP
518 * @head_processed: flag mentioning whether the header data is processed
519 * completely or not
317b4ca4 520 * @bank1: handle to memory allocated for temporary buffers from
af935746 521 * memory bank 1
317b4ca4 522 * @bank2: handle to memory allocated for temporary buffers from
af935746
KD
523 * memory bank 2
524 * @capture_state: state of the capture buffers queue
525 * @output_state: state of the output buffers queue
526 * @src_bufs: information on allocated source buffers
527 * @dst_bufs: information on allocated destination buffers
528 * @sequence: counter for the sequence number for v4l2
529 * @dec_dst_flag: flags for buffers queued in the hardware
530 * @dec_src_buf_size: size of the buffer for source buffers in decoding
531 * @codec_mode: number of codec mode used by MFC hw
532 * @slice_interface: slice interface flag
533 * @loop_filter_mpeg4: loop filter for MPEG4 flag
534 * @display_delay: value of the display delay for H264
535 * @display_delay_enable: display delay for H264 enable flag
536 * @after_packed_pb: flag used to track buffer when stream is in
537 * Packed PB format
f96f3cfa 538 * @sei_fp_parse: enable/disable parsing of frame packing SEI information
af935746
KD
539 * @dpb_count: count of the DPB buffers required by MFC hw
540 * @total_dpb_count: count of DPB buffers with additional buffers
541 * requested by the application
8f532a7f
AK
542 * @ctx: context buffer information
543 * @dsc: descriptor buffer information
544 * @shm: shared memory buffer information
f96f3cfa 545 * @mv_count: number of MV buffers allocated for decoding
af935746
KD
546 * @enc_params: encoding parameters for MFC
547 * @enc_dst_buf_size: size of the buffers for encoder output
f96f3cfa
JP
548 * @luma_dpb_size: dpb buffer size for luma
549 * @chroma_dpb_size: dpb buffer size for chroma
550 * @me_buffer_size: size of the motion estimation buffer
551 * @tmv_buffer_size: size of temporal predictor motion vector buffer
af935746
KD
552 * @frame_type: used to force the type of the next encoded frame
553 * @ref_queue: list of the reference buffers for encoding
554 * @ref_queue_cnt: number of the buffers in the reference list
555 * @c_ops: ops for encoding
556 * @ctrls: array of controls, used when adding controls to the
557 * v4l2 control framework
558 * @ctrl_handler: handler for v4l2 framework
559 */
560struct s5p_mfc_ctx {
561 struct s5p_mfc_dev *dev;
562 struct v4l2_fh fh;
563
564 int num;
565
566 int int_cond;
567 int int_type;
568 unsigned int int_err;
569 wait_queue_head_t queue;
570
571 struct s5p_mfc_fmt *src_fmt;
572 struct s5p_mfc_fmt *dst_fmt;
573
574 struct vb2_queue vq_src;
575 struct vb2_queue vq_dst;
576
577 struct list_head src_queue;
578 struct list_head dst_queue;
579
580 unsigned int src_queue_cnt;
581 unsigned int dst_queue_cnt;
582
583 enum s5p_mfc_inst_type type;
584 enum s5p_mfc_inst_state state;
585 int inst_no;
586
587 /* Image parameters */
588 int img_width;
589 int img_height;
590 int buf_width;
591 int buf_height;
592
593 int luma_size;
594 int chroma_size;
595 int mv_size;
596
597 unsigned long consumed_stream;
598
599 unsigned int dpb_flush_flag;
f96f3cfa 600 unsigned int head_processed;
af935746 601
317b4ca4
KD
602 struct s5p_mfc_priv_buf bank1;
603 struct s5p_mfc_priv_buf bank2;
af935746
KD
604
605 enum s5p_mfc_queue_state capture_state;
606 enum s5p_mfc_queue_state output_state;
607
608 struct s5p_mfc_buf src_bufs[MFC_MAX_BUFFERS];
609 int src_bufs_cnt;
610 struct s5p_mfc_buf dst_bufs[MFC_MAX_BUFFERS];
611 int dst_bufs_cnt;
612
613 unsigned int sequence;
614 unsigned long dec_dst_flag;
615 size_t dec_src_buf_size;
616
617 /* Control values */
618 int codec_mode;
619 int slice_interface;
620 int loop_filter_mpeg4;
621 int display_delay;
622 int display_delay_enable;
623 int after_packed_pb;
f96f3cfa 624 int sei_fp_parse;
af935746 625
e9d98ddc 626 int pb_count;
af935746 627 int total_dpb_count;
f96f3cfa 628 int mv_count;
af935746 629 /* Buffers */
8f532a7f
AK
630 struct s5p_mfc_priv_buf ctx;
631 struct s5p_mfc_priv_buf dsc;
632 struct s5p_mfc_priv_buf shm;
af935746
KD
633
634 struct s5p_mfc_enc_params enc_params;
635
636 size_t enc_dst_buf_size;
f96f3cfa
JP
637 size_t luma_dpb_size;
638 size_t chroma_dpb_size;
639 size_t me_buffer_size;
640 size_t tmv_buffer_size;
af935746
KD
641
642 enum v4l2_mpeg_mfc51_video_force_frame_type force_frame_type;
643
644 struct list_head ref_queue;
645 unsigned int ref_queue_cnt;
646
f96f3cfa
JP
647 enum v4l2_mpeg_video_multi_slice_mode slice_mode;
648 union {
649 unsigned int mb;
650 unsigned int bits;
651 } slice_size;
652
4e9691aa 653 const struct s5p_mfc_codec_ops *c_ops;
af935746
KD
654
655 struct v4l2_ctrl *ctrls[MFC_MAX_CTRLS];
656 struct v4l2_ctrl_handler ctrl_handler;
f96f3cfa
JP
657 unsigned int frame_tag;
658 size_t scratch_buf_size;
af935746
KD
659};
660
661/*
662 * struct s5p_mfc_fmt - structure used to store information about pixelformats
663 * used by the MFC
664 */
665struct s5p_mfc_fmt {
666 char *name;
667 u32 fourcc;
668 u32 codec_mode;
669 enum s5p_mfc_fmt_type type;
670 u32 num_planes;
9aa5f008 671 u32 versions;
af935746
KD
672};
673
674/**
675 * struct mfc_control - structure used to store information about MFC controls
676 * it is used to initialize the control framework.
677 */
678struct mfc_control {
679 __u32 id;
680 enum v4l2_ctrl_type type;
681 __u8 name[32]; /* Whatever */
682 __s32 minimum; /* Note signedness */
683 __s32 maximum;
684 __s32 step;
685 __u32 menu_skip_mask;
686 __s32 default_value;
687 __u32 flags;
688 __u32 reserved[2];
689 __u8 is_volatile;
690};
691
43a1ea1f
AK
692/* Macro for making hardware specific calls */
693#define s5p_mfc_hw_call(f, op, args...) \
fdd1d4b0 694 ((f && f->op) ? f->op(args) : (typeof(f->op(args)))(-ENODEV))
e2c3be2a 695
af935746
KD
696#define fh_to_ctx(__fh) container_of(__fh, struct s5p_mfc_ctx, fh)
697#define ctrl_to_ctx(__ctrl) \
698 container_of((__ctrl)->handler, struct s5p_mfc_ctx, ctrl_handler)
699
7fb89eca
AH
700void clear_work_bit(struct s5p_mfc_ctx *ctx);
701void set_work_bit(struct s5p_mfc_ctx *ctx);
702void clear_work_bit_irqsave(struct s5p_mfc_ctx *ctx);
703void set_work_bit_irqsave(struct s5p_mfc_ctx *ctx);
05d1d0f0 704int s5p_mfc_get_new_ctx(struct s5p_mfc_dev *dev);
62bbd72b 705void s5p_mfc_cleanup_queue(struct list_head *lh, struct vb2_queue *vq);
7fb89eca 706
f96f3cfa
JP
707#define HAS_PORTNUM(dev) (dev ? (dev->variant ? \
708 (dev->variant->port_num ? 1 : 0) : 0) : 0)
709#define IS_TWOPORT(dev) (dev->variant->port_num == 2 ? 1 : 0)
722b979e 710#define IS_MFCV6_PLUS(dev) (dev->variant->version >= 0x60 ? 1 : 0)
109b794c 711#define IS_MFCV7_PLUS(dev) (dev->variant->version >= 0x70 ? 1 : 0)
e2b9deb2 712#define IS_MFCV8(dev) (dev->variant->version >= 0x80 ? 1 : 0)
f96f3cfa 713
9aa5f008
KD
714#define MFC_V5_BIT BIT(0)
715#define MFC_V6_BIT BIT(1)
716#define MFC_V7_BIT BIT(2)
e2b9deb2 717#define MFC_V8_BIT BIT(3)
9aa5f008
KD
718
719
af935746 720#endif /* S5P_MFC_COMMON_H_ */