Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
s5p_mfc_common.h
Go to the documentation of this file.
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, <[email protected]>
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 
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>
24 #include <media/videobuf2-core.h>
25 #include "regs-mfc.h"
26 #include "regs-mfc-v6.h"
27 
28 /* Definitions related to MFC memory */
29 
30 /* Offset base used to differentiate between CAPTURE and OUTPUT
31 * while mmaping */
32 #define DST_QUEUE_OFF_BASE (TASK_SIZE / 2)
33 
34 #define MFC_BANK1_ALLOC_CTX 0
35 #define MFC_BANK2_ALLOC_CTX 1
36 
37 #define MFC_BANK1_ALIGN_ORDER 13
38 #define MFC_BANK2_ALIGN_ORDER 13
39 #define MFC_BASE_ALIGN_ORDER 17
40 
42 
43 static inline dma_addr_t s5p_mfc_mem_cookie(void *a, void *b)
44 {
45  /* Same functionality as the vb2_dma_contig_plane_paddr */
47 
48  return *paddr;
49 }
50 
51 /* MFC definitions */
52 #define MFC_MAX_EXTRA_DPB 5
53 #define MFC_MAX_BUFFERS 32
54 #define MFC_NUM_CONTEXTS 4
55 /* Interrupt timeout */
56 #define MFC_INT_TIMEOUT 2000
57 /* Busy wait timeout */
58 #define MFC_BW_TIMEOUT 500
59 /* Watchdog interval */
60 #define MFC_WATCHDOG_INTERVAL 1000
61 /* After how many executions watchdog should assume lock up */
62 #define MFC_WATCHDOG_CNT 10
63 #define MFC_NO_INSTANCE_SET -1
64 #define MFC_ENC_CAP_PLANE_COUNT 1
65 #define MFC_ENC_OUT_PLANE_COUNT 2
66 #define STUFF_BYTE 4
67 #define MFC_MAX_CTRLS 70
68 
69 #define S5P_MFC_CODEC_NONE -1
70 #define S5P_MFC_CODEC_H264_DEC 0
71 #define S5P_MFC_CODEC_H264_MVC_DEC 1
72 #define S5P_MFC_CODEC_VC1_DEC 2
73 #define S5P_MFC_CODEC_MPEG4_DEC 3
74 #define S5P_MFC_CODEC_MPEG2_DEC 4
75 #define S5P_MFC_CODEC_H263_DEC 5
76 #define S5P_MFC_CODEC_VC1RCV_DEC 6
77 #define S5P_MFC_CODEC_VP8_DEC 7
78 
79 #define S5P_MFC_CODEC_H264_ENC 20
80 #define S5P_MFC_CODEC_H264_MVC_ENC 21
81 #define S5P_MFC_CODEC_MPEG4_ENC 22
82 #define S5P_MFC_CODEC_H263_ENC 23
83 
84 #define S5P_MFC_R2H_CMD_EMPTY 0
85 #define S5P_MFC_R2H_CMD_SYS_INIT_RET 1
86 #define S5P_MFC_R2H_CMD_OPEN_INSTANCE_RET 2
87 #define S5P_MFC_R2H_CMD_SEQ_DONE_RET 3
88 #define S5P_MFC_R2H_CMD_INIT_BUFFERS_RET 4
89 #define S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET 6
90 #define S5P_MFC_R2H_CMD_SLEEP_RET 7
91 #define S5P_MFC_R2H_CMD_WAKEUP_RET 8
92 #define S5P_MFC_R2H_CMD_COMPLETE_SEQ_RET 9
93 #define S5P_MFC_R2H_CMD_DPB_FLUSH_RET 10
94 #define S5P_MFC_R2H_CMD_NAL_ABORT_RET 11
95 #define S5P_MFC_R2H_CMD_FW_STATUS_RET 12
96 #define S5P_MFC_R2H_CMD_FRAME_DONE_RET 13
97 #define S5P_MFC_R2H_CMD_FIELD_DONE_RET 14
98 #define S5P_MFC_R2H_CMD_SLICE_DONE_RET 15
99 #define S5P_MFC_R2H_CMD_ENC_BUFFER_FUL_RET 16
100 #define S5P_MFC_R2H_CMD_ERR_RET 32
101 
102 #define mfc_read(dev, offset) readl(dev->regs_base + (offset))
103 #define mfc_write(dev, data, offset) writel((data), dev->regs_base + \
104  (offset))
105 
113 };
114 
122 };
123 
131 };
132 
151 };
152 
161 };
162 
170 };
171 
172 #define MFC_BUF_FLAG_USED (1 << 0)
173 #define MFC_BUF_FLAG_EOS (1 << 1)
174 
175 struct s5p_mfc_ctx;
176 
180 struct s5p_mfc_buf {
181  struct list_head list;
182  struct vb2_buffer *b;
183  union {
184  struct {
185  size_t luma;
186  size_t chroma;
187  } raw;
188  size_t stream;
189  } cookie;
190  int flags;
191 };
192 
196 struct s5p_mfc_pm {
197  struct clk *clock;
198  struct clk *clock_gate;
200  struct device *device;
201 };
202 
204  unsigned int h264_ctx;
205  unsigned int non_h264_ctx;
206  unsigned int dsc;
207  unsigned int shm;
208 };
209 
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 
219  unsigned int fw;
220  unsigned int cpb;
221  void *priv;
222 };
223 
225  unsigned int base;
226 };
227 
229  unsigned int version;
230  unsigned int port_num;
233  char *mclk_name;
234  char *fw_name;
235 };
236 
248  void *alloc;
249  unsigned long ofs;
250  void *virt;
252  size_t size;
253 };
254 
297 struct s5p_mfc_dev {
302  struct device *mem_dev_l;
303  struct device *mem_dev_r;
305  int irq;
308  struct s5p_mfc_pm pm;
310  int num_inst;
311  spinlock_t irqlock; /* lock when operating on videobuf2 queues */
312  spinlock_t condlock; /* lock when changing/checking if a context is
313  ready to be processed */
314  struct mutex mfc_mutex; /* video_device lock */
315  int int_cond;
316  int int_type;
317  unsigned int int_err;
319  size_t fw_size;
320  size_t bank1;
321  size_t bank2;
322  unsigned long hw_lock;
324  int curr_ctx;
325  unsigned long ctx_work_bits;
330  void *alloc_ctx[2];
331  unsigned long enter_suspend;
332 
337 };
338 
355  int vui_sar;
359  int open_gop;
367  int level;
377 
386 };
387 
392  /* MPEG4 Only */
395  /* Common for MPEG4, H263 */
404  int level;
405 };
406 
413 
419  int pad;
423  int rc_frame;
424  int rc_mb;
429 
433 
437 
438  union {
441  } codec;
442 
443 };
444 
449  /* initialization routines */
452  /* execution routines */
455 };
456 
457 #define call_cop(c, op, args...) \
458  (((c)->c_ops->op) ? \
459  ((c)->c_ops->op(args)) : 0)
460 
542 struct s5p_mfc_ctx {
543  struct s5p_mfc_dev *dev;
544  struct v4l2_fh fh;
545 
546  int num;
547 
548  int int_cond;
549  int int_type;
550  unsigned int int_err;
552 
555 
558 
561 
562  unsigned int src_queue_cnt;
563  unsigned int dst_queue_cnt;
564 
567  int inst_no;
568 
569  /* Image parameters */
574 
577  int mv_size;
578 
579  unsigned long consumed_stream;
580 
581  unsigned int dpb_flush_flag;
582  unsigned int head_processed;
583 
584  /* Buffers */
585  void *bank1_buf;
586  size_t bank1_phys;
587  size_t bank1_size;
588 
589  void *bank2_buf;
590  size_t bank2_phys;
591  size_t bank2_size;
592 
595 
600 
601  unsigned int sequence;
602  unsigned long dec_dst_flag;
604 
605  /* Control values */
613 
616  int mv_count;
617  /* Buffers */
621 
623 
629 
631 
633  unsigned int ref_queue_cnt;
634 
636  union {
637  unsigned int mb;
638  unsigned int bits;
639  } slice_size;
640 
642 
645  unsigned int frame_tag;
647 };
648 
649 /*
650  * struct s5p_mfc_fmt - structure used to store information about pixelformats
651  * used by the MFC
652  */
653 struct s5p_mfc_fmt {
654  char *name;
659 };
660 
665 struct mfc_control {
668  __u8 name[32]; /* Whatever */
669  __s32 minimum; /* Note signedness */
677 };
678 
679 /* Macro for making hardware specific calls */
680 #define s5p_mfc_hw_call(f, op, args...) \
681  ((f && f->op) ? f->op(args) : -ENODEV)
682 
683 #define fh_to_ctx(__fh) container_of(__fh, struct s5p_mfc_ctx, fh)
684 #define ctrl_to_ctx(__ctrl) \
685  container_of((__ctrl)->handler, struct s5p_mfc_ctx, ctrl_handler)
686 
687 void clear_work_bit(struct s5p_mfc_ctx *ctx);
688 void set_work_bit(struct s5p_mfc_ctx *ctx);
690 void set_work_bit_irqsave(struct s5p_mfc_ctx *ctx);
691 
692 #define HAS_PORTNUM(dev) (dev ? (dev->variant ? \
693  (dev->variant->port_num ? 1 : 0) : 0) : 0)
694 #define IS_TWOPORT(dev) (dev->variant->port_num == 2 ? 1 : 0)
695 #define IS_MFCV6(dev) (dev->variant->version >= 0x60 ? 1 : 0)
696 
697 #endif /* S5P_MFC_COMMON_H_ */