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) 2011 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_
20 #include <linux/platform_device.h>
21 #include <linux/videodev2.h>
22 #include <media/v4l2-ctrls.h>
23 #include <media/v4l2-device.h>
24 #include <media/v4l2-ioctl.h>
25 #include <media/videobuf2-core.h>
27 /* Definitions related to MFC memory */
29 /* Offset base used to differentiate between CAPTURE and OUTPUT
31 #define DST_QUEUE_OFF_BASE (TASK_SIZE / 2)
33 /* Offset used by the hardware to store addresses */
34 #define MFC_OFFSET_SHIFT 11
36 #define FIRMWARE_ALIGN 0x20000 /* 128KB */
37 #define MFC_H264_CTX_BUF_SIZE 0x96000 /* 600KB per H264 instance */
38 #define MFC_CTX_BUF_SIZE 0x2800 /* 10KB per instance */
39 #define DESC_BUF_SIZE 0x20000 /* 128KB for DESC buffer */
40 #define SHARED_BUF_SIZE 0x2000 /* 8KB for shared buffer */
42 #define DEF_CPB_SIZE 0x40000 /* 512KB */
44 #define MFC_BANK1_ALLOC_CTX 0
45 #define MFC_BANK2_ALLOC_CTX 1
47 #define MFC_BANK1_ALIGN_ORDER 13
48 #define MFC_BANK2_ALIGN_ORDER 13
49 #define MFC_BASE_ALIGN_ORDER 17
51 #include <media/videobuf2-dma-contig.h>
53 static inline dma_addr_t
s5p_mfc_mem_cookie(void *a
, void *b
)
55 /* Same functionality as the vb2_dma_contig_plane_paddr */
56 dma_addr_t
*paddr
= vb2_dma_contig_memops
.cookie(b
);
62 #define MFC_MAX_EXTRA_DPB 5
63 #define MFC_MAX_BUFFERS 32
64 #define MFC_NUM_CONTEXTS 4
65 /* Interrupt timeout */
66 #define MFC_INT_TIMEOUT 2000
67 /* Busy wait timeout */
68 #define MFC_BW_TIMEOUT 500
69 /* Watchdog interval */
70 #define MFC_WATCHDOG_INTERVAL 1000
71 /* After how many executions watchdog should assume lock up */
72 #define MFC_WATCHDOG_CNT 10
73 #define MFC_NO_INSTANCE_SET -1
74 #define MFC_ENC_CAP_PLANE_COUNT 1
75 #define MFC_ENC_OUT_PLANE_COUNT 2
77 #define MFC_MAX_CTRLS 64
79 #define mfc_read(dev, offset) readl(dev->regs_base + (offset))
80 #define mfc_write(dev, data, offset) writel((data), dev->regs_base + \
84 * enum s5p_mfc_fmt_type - type of the pixelformat
86 enum s5p_mfc_fmt_type
{
93 * enum s5p_mfc_node_type - The type of an MFC device node.
95 enum s5p_mfc_node_type
{
102 * enum s5p_mfc_inst_type - The type of an MFC instance.
104 enum s5p_mfc_inst_type
{
111 * enum s5p_mfc_inst_state - The state of an MFC instance.
113 enum s5p_mfc_inst_state
{
125 MFCINST_RES_CHANGE_INIT
,
126 MFCINST_RES_CHANGE_FLUSH
,
127 MFCINST_RES_CHANGE_END
,
131 * enum s5p_mfc_queue_state - The state of buffer queue.
133 enum s5p_mfc_queue_state
{
135 QUEUE_BUFS_REQUESTED
,
141 * enum s5p_mfc_decode_arg - type of frame decoding
143 enum s5p_mfc_decode_arg
{
152 * struct s5p_mfc_buf - MFC buffer
155 struct list_head list
;
156 struct vb2_buffer
*b
;
168 * struct s5p_mfc_pm - power management data structure
172 struct clk
*clock_gate
;
174 struct device
*device
;
178 * struct s5p_mfc_dev - The struct containing driver internal parameters.
180 * @v4l2_dev: v4l2_device
181 * @vfd_dec: video device for decoding
182 * @vfd_enc: video device for encoding
183 * @plat_dev: platform device
184 * @mem_dev_l: child device of the left memory bank (0)
185 * @mem_dev_r: child device of the right memory bank (1)
186 * @regs_base: base address of the MFC hw registers
188 * @dec_ctrl_handler: control framework handler for decoding
189 * @enc_ctrl_handler: control framework handler for encoding
190 * @pm: power management control
191 * @num_inst: couter of active MFC instances
192 * @irqlock: lock for operations on videobuf2 queues
193 * @condlock: lock for changing/checking if a context is ready to be
195 * @mfc_mutex: lock for video_device
196 * @int_cond: variable used by the waitqueue
197 * @int_type: type of last interrupt
198 * @int_err: error number for last interrupt
199 * @queue: waitqueue for waiting for completion of device commands
200 * @fw_size: size of firmware
201 * @bank1: address of the beggining of bank 1 memory
202 * @bank2: address of the beggining of bank 2 memory
203 * @hw_lock: used for hardware locking
204 * @ctx: array of driver contexts
205 * @curr_ctx: number of the currently running context
206 * @ctx_work_bits: used to mark which contexts are waiting for hardware
207 * @watchdog_cnt: counter for the watchdog
208 * @watchdog_workqueue: workqueue for the watchdog
209 * @watchdog_work: worker for the watchdog
210 * @alloc_ctx: videobuf2 allocator contexts for two memory banks
211 * @enter_suspend: flag set when entering suspend
215 struct v4l2_device v4l2_dev
;
216 struct video_device
*vfd_dec
;
217 struct video_device
*vfd_enc
;
218 struct platform_device
*plat_dev
;
219 struct device
*mem_dev_l
;
220 struct device
*mem_dev_r
;
221 void __iomem
*regs_base
;
223 struct v4l2_ctrl_handler dec_ctrl_handler
;
224 struct v4l2_ctrl_handler enc_ctrl_handler
;
225 struct s5p_mfc_pm pm
;
227 spinlock_t irqlock
; /* lock when operating on videobuf2 queues */
228 spinlock_t condlock
; /* lock when changing/checking if a context is
229 ready to be processed */
230 struct mutex mfc_mutex
; /* video_device lock */
233 unsigned int int_err
;
234 wait_queue_head_t queue
;
238 unsigned long hw_lock
;
239 struct s5p_mfc_ctx
*ctx
[MFC_NUM_CONTEXTS
];
241 unsigned long ctx_work_bits
;
242 atomic_t watchdog_cnt
;
243 struct timer_list watchdog_timer
;
244 struct workqueue_struct
*watchdog_workqueue
;
245 struct work_struct watchdog_work
;
247 unsigned long enter_suspend
;
251 * struct s5p_mfc_h264_enc_params - encoding parameters for h264
253 struct s5p_mfc_h264_enc_params
{
254 enum v4l2_mpeg_video_h264_profile profile
;
255 enum v4l2_mpeg_video_h264_loop_filter_mode loop_filter_mode
;
256 s8 loop_filter_alpha
;
258 enum v4l2_mpeg_video_h264_entropy_mode entropy_mode
;
269 u16 vui_ext_sar_width
;
270 u16 vui_ext_sar_height
;
278 enum v4l2_mpeg_video_h264_level level_v4l2
;
284 * struct s5p_mfc_mpeg4_enc_params - encoding parameters for h263 and mpeg4
286 struct s5p_mfc_mpeg4_enc_params
{
288 enum v4l2_mpeg_video_mpeg4_profile profile
;
290 /* Common for MPEG4, H263 */
298 enum v4l2_mpeg_video_mpeg4_level level_v4l2
;
303 * struct s5p_mfc_enc_params - general encoding parameters
305 struct s5p_mfc_enc_params
{
310 enum v4l2_mpeg_video_multi_slice_mode slice_mode
;
313 u16 intra_refresh_mb
;
320 u16 rc_reaction_coeff
;
323 enum v4l2_mpeg_video_header_mode seq_hdr_mode
;
324 enum v4l2_mpeg_mfc51_video_frame_skip_mode frame_skip_mode
;
325 int fixed_target_bit
;
328 u32 rc_framerate_num
;
329 u32 rc_framerate_denom
;
333 struct s5p_mfc_h264_enc_params h264
;
334 struct s5p_mfc_mpeg4_enc_params mpeg4
;
340 * struct s5p_mfc_codec_ops - codec ops, used by encoding
342 struct s5p_mfc_codec_ops
{
343 /* initialization routines */
344 int (*pre_seq_start
) (struct s5p_mfc_ctx
*ctx
);
345 int (*post_seq_start
) (struct s5p_mfc_ctx
*ctx
);
346 /* execution routines */
347 int (*pre_frame_start
) (struct s5p_mfc_ctx
*ctx
);
348 int (*post_frame_start
) (struct s5p_mfc_ctx
*ctx
);
351 #define call_cop(c, op, args...) \
352 (((c)->c_ops->op) ? \
353 ((c)->c_ops->op(args)) : 0)
356 * struct s5p_mfc_ctx - This struct contains the instance context
358 * @dev: pointer to the s5p_mfc_dev of the device
359 * @fh: struct v4l2_fh
360 * @num: number of the context that this structure describes
361 * @int_cond: variable used by the waitqueue
362 * @int_type: type of the last interrupt
363 * @int_err: error number received from MFC hw in the interrupt
364 * @queue: waitqueue that can be used to wait for this context to
366 * @src_fmt: source pixelformat information
367 * @dst_fmt: destination pixelformat information
368 * @vq_src: vb2 queue for source buffers
369 * @vq_dst: vb2 queue for destination buffers
370 * @src_queue: driver internal queue for source buffers
371 * @dst_queue: driver internal queue for destination buffers
372 * @src_queue_cnt: number of buffers queued on the source internal queue
373 * @dst_queue_cnt: number of buffers queued on the dest internal queue
374 * @type: type of the instance - decoder or encoder
375 * @state: state of the context
376 * @inst_no: number of hw instance associated with the context
377 * @img_width: width of the image that is decoded or encoded
378 * @img_height: height of the image that is decoded or encoded
379 * @buf_width: width of the buffer for processed image
380 * @buf_height: height of the buffer for processed image
381 * @luma_size: size of a luma plane
382 * @chroma_size: size of a chroma plane
383 * @mv_size: size of a motion vectors buffer
384 * @consumed_stream: number of bytes that have been used so far from the
386 * @dpb_flush_flag: flag used to indicate that a DPB buffers are being
388 * @bank1_buf: handle to memory allocated for temporary buffers from
390 * @bank1_phys: address of the temporary buffers from memory bank 1
391 * @bank1_size: size of the memory allocated for temporary buffers from
393 * @bank2_buf: handle to memory allocated for temporary buffers from
395 * @bank2_phys: address of the temporary buffers from memory bank 2
396 * @bank2_size: size of the memory allocated for temporary buffers from
398 * @capture_state: state of the capture buffers queue
399 * @output_state: state of the output buffers queue
400 * @src_bufs: information on allocated source buffers
401 * @dst_bufs: information on allocated destination buffers
402 * @sequence: counter for the sequence number for v4l2
403 * @dec_dst_flag: flags for buffers queued in the hardware
404 * @dec_src_buf_size: size of the buffer for source buffers in decoding
405 * @codec_mode: number of codec mode used by MFC hw
406 * @slice_interface: slice interface flag
407 * @loop_filter_mpeg4: loop filter for MPEG4 flag
408 * @display_delay: value of the display delay for H264
409 * @display_delay_enable: display delay for H264 enable flag
410 * @after_packed_pb: flag used to track buffer when stream is in
412 * @dpb_count: count of the DPB buffers required by MFC hw
413 * @total_dpb_count: count of DPB buffers with additional buffers
414 * requested by the application
415 * @ctx_buf: handle to the memory associated with this context
416 * @ctx_phys: address of the memory associated with this context
417 * @ctx_size: size of the memory associated with this context
418 * @desc_buf: description buffer for decoding handle
419 * @desc_phys: description buffer for decoding address
420 * @shm_alloc: handle for the shared memory buffer
421 * @shm: virtual address for the shared memory buffer
422 * @shm_ofs: address offset for shared memory
423 * @enc_params: encoding parameters for MFC
424 * @enc_dst_buf_size: size of the buffers for encoder output
425 * @frame_type: used to force the type of the next encoded frame
426 * @ref_queue: list of the reference buffers for encoding
427 * @ref_queue_cnt: number of the buffers in the reference list
428 * @c_ops: ops for encoding
429 * @ctrls: array of controls, used when adding controls to the
430 * v4l2 control framework
431 * @ctrl_handler: handler for v4l2 framework
434 struct s5p_mfc_dev
*dev
;
441 unsigned int int_err
;
442 wait_queue_head_t queue
;
444 struct s5p_mfc_fmt
*src_fmt
;
445 struct s5p_mfc_fmt
*dst_fmt
;
447 struct vb2_queue vq_src
;
448 struct vb2_queue vq_dst
;
450 struct list_head src_queue
;
451 struct list_head dst_queue
;
453 unsigned int src_queue_cnt
;
454 unsigned int dst_queue_cnt
;
456 enum s5p_mfc_inst_type type
;
457 enum s5p_mfc_inst_state state
;
460 /* Image parameters */
470 unsigned long consumed_stream
;
472 unsigned int dpb_flush_flag
;
483 enum s5p_mfc_queue_state capture_state
;
484 enum s5p_mfc_queue_state output_state
;
486 struct s5p_mfc_buf src_bufs
[MFC_MAX_BUFFERS
];
488 struct s5p_mfc_buf dst_bufs
[MFC_MAX_BUFFERS
];
491 unsigned int sequence
;
492 unsigned long dec_dst_flag
;
493 size_t dec_src_buf_size
;
498 int loop_filter_mpeg4
;
500 int display_delay_enable
;
520 struct s5p_mfc_enc_params enc_params
;
522 size_t enc_dst_buf_size
;
524 enum v4l2_mpeg_mfc51_video_force_frame_type force_frame_type
;
526 struct list_head ref_queue
;
527 unsigned int ref_queue_cnt
;
529 struct s5p_mfc_codec_ops
*c_ops
;
531 struct v4l2_ctrl
*ctrls
[MFC_MAX_CTRLS
];
532 struct v4l2_ctrl_handler ctrl_handler
;
536 * struct s5p_mfc_fmt - structure used to store information about pixelformats
543 enum s5p_mfc_fmt_type type
;
548 * struct mfc_control - structure used to store information about MFC controls
549 * it is used to initialize the control framework.
553 enum v4l2_ctrl_type type
;
554 __u8 name
[32]; /* Whatever */
555 __s32 minimum
; /* Note signedness */
558 __u32 menu_skip_mask
;
566 #define fh_to_ctx(__fh) container_of(__fh, struct s5p_mfc_ctx, fh)
567 #define ctrl_to_ctx(__ctrl) \
568 container_of((__ctrl)->handler, struct s5p_mfc_ctx, ctrl_handler)
570 #endif /* S5P_MFC_COMMON_H_ */