0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef RKVDEC_H_
0012 #define RKVDEC_H_
0013
0014 #include <linux/platform_device.h>
0015 #include <linux/videodev2.h>
0016 #include <linux/wait.h>
0017 #include <linux/clk.h>
0018
0019 #include <media/v4l2-ctrls.h>
0020 #include <media/v4l2-device.h>
0021 #include <media/v4l2-ioctl.h>
0022 #include <media/videobuf2-core.h>
0023 #include <media/videobuf2-dma-contig.h>
0024
0025 struct rkvdec_ctx;
0026
0027 struct rkvdec_ctrl_desc {
0028 struct v4l2_ctrl_config cfg;
0029 };
0030
0031 struct rkvdec_ctrls {
0032 const struct rkvdec_ctrl_desc *ctrls;
0033 unsigned int num_ctrls;
0034 };
0035
0036 struct rkvdec_run {
0037 struct {
0038 struct vb2_v4l2_buffer *src;
0039 struct vb2_v4l2_buffer *dst;
0040 } bufs;
0041 };
0042
0043 struct rkvdec_vp9_decoded_buffer_info {
0044
0045 unsigned short width;
0046 unsigned short height;
0047 unsigned int bit_depth : 4;
0048 };
0049
0050 struct rkvdec_decoded_buffer {
0051
0052 struct v4l2_m2m_buffer base;
0053
0054 union {
0055 struct rkvdec_vp9_decoded_buffer_info vp9;
0056 };
0057 };
0058
0059 static inline struct rkvdec_decoded_buffer *
0060 vb2_to_rkvdec_decoded_buf(struct vb2_buffer *buf)
0061 {
0062 return container_of(buf, struct rkvdec_decoded_buffer,
0063 base.vb.vb2_buf);
0064 }
0065
0066 struct rkvdec_coded_fmt_ops {
0067 int (*adjust_fmt)(struct rkvdec_ctx *ctx,
0068 struct v4l2_format *f);
0069 int (*start)(struct rkvdec_ctx *ctx);
0070 void (*stop)(struct rkvdec_ctx *ctx);
0071 int (*run)(struct rkvdec_ctx *ctx);
0072 void (*done)(struct rkvdec_ctx *ctx, struct vb2_v4l2_buffer *src_buf,
0073 struct vb2_v4l2_buffer *dst_buf,
0074 enum vb2_buffer_state result);
0075 int (*try_ctrl)(struct rkvdec_ctx *ctx, struct v4l2_ctrl *ctrl);
0076 };
0077
0078 struct rkvdec_coded_fmt_desc {
0079 u32 fourcc;
0080 struct v4l2_frmsize_stepwise frmsize;
0081 const struct rkvdec_ctrls *ctrls;
0082 const struct rkvdec_coded_fmt_ops *ops;
0083 unsigned int num_decoded_fmts;
0084 const u32 *decoded_fmts;
0085 u32 subsystem_flags;
0086 };
0087
0088 struct rkvdec_dev {
0089 struct v4l2_device v4l2_dev;
0090 struct media_device mdev;
0091 struct video_device vdev;
0092 struct v4l2_m2m_dev *m2m_dev;
0093 struct device *dev;
0094 struct clk_bulk_data *clocks;
0095 void __iomem *regs;
0096 struct mutex vdev_lock;
0097 struct delayed_work watchdog_work;
0098 };
0099
0100 struct rkvdec_ctx {
0101 struct v4l2_fh fh;
0102 struct v4l2_format coded_fmt;
0103 struct v4l2_format decoded_fmt;
0104 const struct rkvdec_coded_fmt_desc *coded_fmt_desc;
0105 struct v4l2_ctrl_handler ctrl_hdl;
0106 struct rkvdec_dev *dev;
0107 void *priv;
0108 };
0109
0110 static inline struct rkvdec_ctx *fh_to_rkvdec_ctx(struct v4l2_fh *fh)
0111 {
0112 return container_of(fh, struct rkvdec_ctx, fh);
0113 }
0114
0115 struct rkvdec_aux_buf {
0116 void *cpu;
0117 dma_addr_t dma;
0118 size_t size;
0119 };
0120
0121 void rkvdec_run_preamble(struct rkvdec_ctx *ctx, struct rkvdec_run *run);
0122 void rkvdec_run_postamble(struct rkvdec_ctx *ctx, struct rkvdec_run *run);
0123
0124 extern const struct rkvdec_coded_fmt_ops rkvdec_h264_fmt_ops;
0125 extern const struct rkvdec_coded_fmt_ops rkvdec_vp9_fmt_ops;
0126
0127 #endif