coda.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. * Coda multi-standard codec IP
  3. *
  4. * Copyright (C) 2012 Vista Silicon S.L.
  5. * Javier Martin, <javier.martin@vista-silicon.com>
  6. * Xavier Duret
  7. * Copyright (C) 2012-2014 Philipp Zabel, Pengutronix
  8. *
  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.
  13. */
  14. #include <linux/debugfs.h>
  15. #include <linux/irqreturn.h>
  16. #include <linux/mutex.h>
  17. #include <linux/kfifo.h>
  18. #include <linux/videodev2.h>
  19. #include <media/v4l2-ctrls.h>
  20. #include <media/v4l2-device.h>
  21. #include <media/v4l2-fh.h>
  22. #include <media/videobuf2-core.h>
  23. #include "coda_regs.h"
  24. #define CODA_MAX_FRAMEBUFFERS 8
  25. #define CODA_MAX_FRAME_SIZE 0x100000
  26. #define FMO_SLICE_SAVE_BUF_SIZE (32)
  27. enum {
  28. V4L2_M2M_SRC = 0,
  29. V4L2_M2M_DST = 1,
  30. };
  31. enum coda_inst_type {
  32. CODA_INST_ENCODER,
  33. CODA_INST_DECODER,
  34. };
  35. enum coda_product {
  36. CODA_DX6 = 0xf001,
  37. CODA_7541 = 0xf012,
  38. CODA_960 = 0xf020,
  39. };
  40. struct coda_devtype {
  41. char *firmware;
  42. enum coda_product product;
  43. const struct coda_codec *codecs;
  44. unsigned int num_codecs;
  45. size_t workbuf_size;
  46. size_t tempbuf_size;
  47. size_t iram_size;
  48. };
  49. struct coda_aux_buf {
  50. void *vaddr;
  51. dma_addr_t paddr;
  52. u32 size;
  53. struct debugfs_blob_wrapper blob;
  54. struct dentry *dentry;
  55. };
  56. struct coda_dev {
  57. struct v4l2_device v4l2_dev;
  58. struct video_device vfd[2];
  59. struct platform_device *plat_dev;
  60. const struct coda_devtype *devtype;
  61. void __iomem *regs_base;
  62. struct clk *clk_per;
  63. struct clk *clk_ahb;
  64. struct reset_control *rstc;
  65. struct coda_aux_buf codebuf;
  66. struct coda_aux_buf tempbuf;
  67. struct coda_aux_buf workbuf;
  68. struct gen_pool *iram_pool;
  69. struct coda_aux_buf iram;
  70. spinlock_t irqlock;
  71. struct mutex dev_mutex;
  72. struct mutex coda_mutex;
  73. struct workqueue_struct *workqueue;
  74. struct v4l2_m2m_dev *m2m_dev;
  75. struct vb2_alloc_ctx *alloc_ctx;
  76. struct list_head instances;
  77. unsigned long instance_mask;
  78. struct dentry *debugfs_root;
  79. };
  80. struct coda_codec {
  81. u32 mode;
  82. u32 src_fourcc;
  83. u32 dst_fourcc;
  84. u32 max_w;
  85. u32 max_h;
  86. };
  87. struct coda_huff_tab;
  88. struct coda_params {
  89. u8 rot_mode;
  90. u8 h264_intra_qp;
  91. u8 h264_inter_qp;
  92. u8 h264_min_qp;
  93. u8 h264_max_qp;
  94. u8 h264_deblk_enabled;
  95. u8 h264_deblk_alpha;
  96. u8 h264_deblk_beta;
  97. u8 mpeg4_intra_qp;
  98. u8 mpeg4_inter_qp;
  99. u8 gop_size;
  100. int intra_refresh;
  101. int codec_mode;
  102. int codec_mode_aux;
  103. enum v4l2_mpeg_video_multi_slice_mode slice_mode;
  104. u32 framerate;
  105. u16 bitrate;
  106. u32 slice_max_bits;
  107. u32 slice_max_mb;
  108. };
  109. struct coda_timestamp {
  110. struct list_head list;
  111. u32 sequence;
  112. struct v4l2_timecode timecode;
  113. struct timeval timestamp;
  114. };
  115. /* Per-queue, driver-specific private data */
  116. struct coda_q_data {
  117. unsigned int width;
  118. unsigned int height;
  119. unsigned int bytesperline;
  120. unsigned int sizeimage;
  121. unsigned int fourcc;
  122. struct v4l2_rect rect;
  123. };
  124. struct coda_iram_info {
  125. u32 axi_sram_use;
  126. phys_addr_t buf_bit_use;
  127. phys_addr_t buf_ip_ac_dc_use;
  128. phys_addr_t buf_dbk_y_use;
  129. phys_addr_t buf_dbk_c_use;
  130. phys_addr_t buf_ovl_use;
  131. phys_addr_t buf_btp_use;
  132. phys_addr_t search_ram_paddr;
  133. int search_ram_size;
  134. int remaining;
  135. phys_addr_t next_paddr;
  136. };
  137. struct gdi_tiled_map {
  138. int xy2ca_map[16];
  139. int xy2ba_map[16];
  140. int xy2ra_map[16];
  141. int rbc2axi_map[32];
  142. int xy2rbc_config;
  143. int map_type;
  144. #define GDI_LINEAR_FRAME_MAP 0
  145. };
  146. struct coda_ctx;
  147. struct coda_context_ops {
  148. int (*queue_init)(void *priv, struct vb2_queue *src_vq,
  149. struct vb2_queue *dst_vq);
  150. int (*start_streaming)(struct coda_ctx *ctx);
  151. int (*prepare_run)(struct coda_ctx *ctx);
  152. void (*finish_run)(struct coda_ctx *ctx);
  153. void (*seq_end_work)(struct work_struct *work);
  154. void (*release)(struct coda_ctx *ctx);
  155. };
  156. struct coda_ctx {
  157. struct coda_dev *dev;
  158. struct mutex buffer_mutex;
  159. struct list_head list;
  160. struct work_struct pic_run_work;
  161. struct work_struct seq_end_work;
  162. struct completion completion;
  163. const struct coda_context_ops *ops;
  164. int aborting;
  165. int initialized;
  166. int streamon_out;
  167. int streamon_cap;
  168. u32 isequence;
  169. u32 qsequence;
  170. u32 osequence;
  171. u32 sequence_offset;
  172. struct coda_q_data q_data[2];
  173. enum coda_inst_type inst_type;
  174. const struct coda_codec *codec;
  175. enum v4l2_colorspace colorspace;
  176. struct coda_params params;
  177. struct v4l2_ctrl_handler ctrls;
  178. struct v4l2_fh fh;
  179. int gopcounter;
  180. int runcounter;
  181. char vpu_header[3][64];
  182. int vpu_header_size[3];
  183. struct kfifo bitstream_fifo;
  184. struct mutex bitstream_mutex;
  185. struct coda_aux_buf bitstream;
  186. bool hold;
  187. struct coda_aux_buf parabuf;
  188. struct coda_aux_buf psbuf;
  189. struct coda_aux_buf slicebuf;
  190. struct coda_aux_buf internal_frames[CODA_MAX_FRAMEBUFFERS];
  191. u32 frame_types[CODA_MAX_FRAMEBUFFERS];
  192. struct coda_timestamp frame_timestamps[CODA_MAX_FRAMEBUFFERS];
  193. u32 frame_errors[CODA_MAX_FRAMEBUFFERS];
  194. struct list_head timestamp_list;
  195. struct coda_aux_buf workbuf;
  196. int num_internal_frames;
  197. int idx;
  198. int reg_idx;
  199. struct coda_iram_info iram_info;
  200. struct gdi_tiled_map tiled_map;
  201. u32 bit_stream_param;
  202. u32 frm_dis_flg;
  203. u32 frame_mem_ctrl;
  204. int display_idx;
  205. struct dentry *debugfs_entry;
  206. };
  207. extern int coda_debug;
  208. void coda_write(struct coda_dev *dev, u32 data, u32 reg);
  209. unsigned int coda_read(struct coda_dev *dev, u32 reg);
  210. int coda_alloc_aux_buf(struct coda_dev *dev, struct coda_aux_buf *buf,
  211. size_t size, const char *name, struct dentry *parent);
  212. void coda_free_aux_buf(struct coda_dev *dev, struct coda_aux_buf *buf);
  213. static inline int coda_alloc_context_buf(struct coda_ctx *ctx,
  214. struct coda_aux_buf *buf, size_t size,
  215. const char *name)
  216. {
  217. return coda_alloc_aux_buf(ctx->dev, buf, size, name, ctx->debugfs_entry);
  218. }
  219. int coda_encoder_queue_init(void *priv, struct vb2_queue *src_vq,
  220. struct vb2_queue *dst_vq);
  221. int coda_decoder_queue_init(void *priv, struct vb2_queue *src_vq,
  222. struct vb2_queue *dst_vq);
  223. int coda_hw_reset(struct coda_ctx *ctx);
  224. void coda_fill_bitstream(struct coda_ctx *ctx);
  225. void coda_set_gdi_regs(struct coda_ctx *ctx);
  226. static inline struct coda_q_data *get_q_data(struct coda_ctx *ctx,
  227. enum v4l2_buf_type type)
  228. {
  229. switch (type) {
  230. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  231. return &(ctx->q_data[V4L2_M2M_SRC]);
  232. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  233. return &(ctx->q_data[V4L2_M2M_DST]);
  234. default:
  235. return NULL;
  236. }
  237. }
  238. const char *coda_product_name(int product);
  239. int coda_check_firmware(struct coda_dev *dev);
  240. static inline int coda_get_bitstream_payload(struct coda_ctx *ctx)
  241. {
  242. return kfifo_len(&ctx->bitstream_fifo);
  243. }
  244. void coda_bit_stream_end_flag(struct coda_ctx *ctx);
  245. int coda_h264_padding(int size, char *p);
  246. extern const struct coda_context_ops coda_bit_encode_ops;
  247. extern const struct coda_context_ops coda_bit_decode_ops;
  248. irqreturn_t coda_irq_handler(int irq, void *data);