Files
BPI-CM9-Linux/aml-comp/hardware/amlogic/video_encoder/tahoe_v4l/tahoe_common.h
T

214 lines
5.6 KiB
C

/*
* Copyright (C) 2017 Amlogic, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Description:
*/
#ifndef __TAHOE_COMMON_H_
#define __TAHOE_COMMON_H_
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/platform_device.h>
#include <linux/dma-mapping.h>
#include <linux/wait.h>
#include <linux/list.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/uaccess.h>
#include <linux/cdev.h>
#include <linux/sched.h>
#include <linux/version.h>
#include <linux/kfifo.h>
#include <linux/kthread.h>
#include <linux/platform_device.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ioctl.h>
#include <media/v4l2-event.h>
#include <media/v4l2-ctrls.h>
#include <media/videobuf2-v4l2.h>
#include <media/videobuf2-core.h>
#include <media/videobuf2-dma-contig.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-fh.h>
#include <media/v4l2-mem2mem.h>
#include <linux/types.h>
#include "tahoe_assist.h"
extern s32 clock_gate_count;
extern u32 clock_a;
typedef enum {
MFDI_INPUT_FMT_NV21 = 0,
MFDI_INPUT_FMT_NV12 = 1,
MFDI_INPUT_FMT_YUV420_PLANAR = 2,
MFDI_INPUT_FMT_YUV444_PACKET = 3,
MFDI_INPUT_FMT_RGB565 = 4,
MFDI_INPUT_FMT_BGR565 = 5,
MFDI_INPUT_FMT_ARGB1555 = 6,
MFDI_INPUT_FMT_BRGA5551 = 7,
MFDI_INPUT_FMT_ARGB8888 = 8,
MFDI_INPUT_FMT_BGRA8888 = 9,
MFDI_INPUT_FMT_RGBA8888 = 10,
MFDI_INPUT_FMT_RGB888 = 11,
MFDI_INPUT_FMT_BGR888 = 12,
MFDI_INPUT_FMT_COM_4U4V = 13,
MFDI_INPUT_FMT_COM_8U8V = 14,
} img_format_e;
typedef enum codec_type {
CODEC_ID_H264 = 0,
CODEC_ID_H265,
} codec_type_e;
struct tahoe_param {
int id;
int poc;
int width;
int height;
int stride;
int plane_num;
img_format_e fmt; //input
codec_type_e codec_type; // 0:264 1:265
int bitrate;
int gop;
int fps;
uint8_t rc_mode;
uint8_t init_qp;
uint8_t fix_qp_I;
uint8_t fix_qp_P;
uint8_t profile;
uint8_t level;
uint8_t tier;
uint8_t coloraspect_enable;
uint8_t video_full_range_flag;
uint8_t colour_primaries;
uint8_t transfer_characteristics;
uint8_t matrix_coefficients;
int force_idr;
int golden_match_flag;
int bytesperline[3];
int imagesize[3];
uint64_t inpt_buf_addr[3];
uint64_t es_addr;
int es_buf_size;
int src_buf_index;
uint8_t separate_header;
uint8_t cfg_update;
};
struct venc_drv_buffer_t {
u32 size;
u32 cached;
uint64_t phys_addr;
uint64_t base; /* kernel logical address in use kernel */
uint64_t virt_addr; /* virtual user space address */
};
struct tahoe_clks {
struct clk *sys_tahoe;
struct clk *tahoe_clk;
};
struct tahoe_rsts {
struct reset_control *core_rst;
struct reset_control *a_rst;
struct reset_control *apb_rst;
struct reset_control *sys_rst;
};
struct venc_drv_context_t {
struct fasync_struct *async_queue;
ulong interrupt_reason;
u32 interrupt_flag;
u32 open_count; /*!<< device reference count. Not instance count */
atomic_t request_ready;
wait_queue_head_t request_complete;
};
struct addr_info {
uint64_t vir_addr;
uint64_t phy_addr_alloc;
uint64_t phy_addr_act;
int size;
int alloc_size;
};
struct tahoe_inst {
//struct list_head list;
struct v4l2_fh v4l2_fh;
struct v4l2_m2m_dev *v4l2_m2m_dev;
struct v4l2_ctrl_handler v4l2_ctrl_hdl;
struct tahoe_device *dev;
struct tahoe_param param;
struct venc_drv_buffer_t s_video_memory; //整个固件需要使用的buffer,当前申请了64M,传到固件中;
void (*output_f)(struct tahoe_inst *inst);
int last_is_done;
struct addr_info sps;
struct addr_info pps;
struct addr_info vps;
volatile uint8_t hw_proc_count;
//uint64_t o_vaddr[16];
struct mutex inst_lock;
uint32_t inst_id;
uint8_t inst_init_flag;
};
struct tahoe_device {
struct device *dev;
struct v4l2_device v4l2_dev;
struct video_device *vdev;
struct v4l2_m2m_dev *tahoe_m2m_dev;
struct venc_drv_buffer_t s_tahoe_register;
struct venc_drv_buffer_t fw_buffer;
struct tahoe_clks s_tahoe_clks;
struct tahoe_rsts s_tahoe_rsts;
int s_tahoe_irq;
u32 cma_cfg_size;
struct venc_drv_context_t s_tahoe_drv_context;
bool s_tahoe_irq_requested;
struct tahoe_inst *instance[6];
struct mutex dev_lock;
unsigned char cur_inst;
wait_queue_head_t hw_complete;
};
void tahoe_hw_reset(void);
void tahoe_clk_put(struct device *dev, struct tahoe_clks *clks);
int tahoe_clk_get(struct device *dev, struct tahoe_clks *clks);
int tahoe_rst_get(struct device *dev, struct tahoe_rsts *rsts);
void tahoe_clk_enable(struct tahoe_clks *clks, struct platform_device *tahoe_pdev);
void tahoe_clk_disable(struct tahoe_clks *clks, struct platform_device *tahoe_pdev);
#endif