From fffe80c1936a9eb02d36c9908612d6de5b85c34e Mon Sep 17 00:00:00 2001 From: "xiaoqian.zhang" Date: Mon, 10 Aug 2026 09:41:06 +0000 Subject: [PATCH 2/3] encoder: CB1 fix tahoe crash on early interrupt. [1/1] PD#SWPL-284054 Problem: crash on early interrupt when dule-sensor. Solution: add protect for the situation. Verify: a9 Change-Id: I313a253da820654713d83f94eee50442ae4a9349 Signed-off-by: xiaoqian.zhang --- tahoe_v4l/tahoe_common.h | 1 + tahoe_v4l/tahoe_entry.c | 346 +++++++------------------------------ tahoe_v4l/tahoe_hw.c | 49 ++---- tahoe_v4l/tahoe_register.h | 23 +++ 4 files changed, 99 insertions(+), 320 deletions(-) diff --git a/tahoe_v4l/tahoe_common.h b/tahoe_v4l/tahoe_common.h index c6c2440..00d3e8e 100644 --- a/tahoe_v4l/tahoe_common.h +++ b/tahoe_v4l/tahoe_common.h @@ -200,6 +200,7 @@ struct tahoe_device { struct tahoe_inst *instance[6]; struct mutex dev_lock; unsigned char cur_inst; + wait_queue_head_t hw_complete; }; diff --git a/tahoe_v4l/tahoe_entry.c b/tahoe_v4l/tahoe_entry.c index 0706b22..ed330f7 100644 --- a/tahoe_v4l/tahoe_entry.c +++ b/tahoe_v4l/tahoe_entry.c @@ -67,26 +67,6 @@ #include "tahoe_assist.h" #include "tahoe_common.h" -#define IRQ_FRM_DONE_FBC 0x1 -#define IRQ_FRM_START 0x2 -#define IRQ_SCR_WRITE 0x4 -#define IRQ_RDMA_DONE 0x8 -#define IRQ_PRELOAD_DONE 0x10 -#define IRQ_ROWRC_1 0x20 -#define IRQ_ROWRC_2 0x40 -#define IRQ_FRM_DONE_EC 0x80 -#define IRQ_FRM_DONE_LPF 0x100 -#define IRQ_FRM_DONE_RDO 0x200 -#define IRQ_FRM_DONE_ME 0x400 -#define IRQ_SLICE_DONE_FBC 0x800 -#define IRQ_SLICE_DONE_EC 0x1000 -#define IRQ_SLICE_DONE_LPF 0x2000 -#define IRQ_SLICE_DONE_RDO 0x4000 -#define IRQ_SLICE_DONE_ME 0x8000 -#define IRQ_ES_OVERFLOW 0x10000 -#define IRQ_RESERVED 0x20000 -#define IRQ_LOW_LATENCY 0x40000 - #define DRIVER_NAME "tahoe" #define DEVICE_NAME "tahoe" #define CLASS_NAME "tahoe" @@ -104,10 +84,8 @@ #define P_T_UL(p) ((unsigned long)(uintptr_t)(p)) #define ALIGN_32(x) ((((x) + 31) >> 5) << 5) -//static struct venc_drv_buffer_t fw_buffer; //fw addr + #define MC_SIZE (4096 * 1024) -//static int s_interrupt_flag; -//static wait_queue_head_t s_interrupt_wait_q; static struct venc_drv_context_t s_tahoe_drv_context; static s32 s_tahoe_major; @@ -127,16 +105,11 @@ static spinlock_t s_vpu_lock = __SPIN_LOCK_UNLOCKED(s_vpu_lock); #endif static struct list_head s_vbp_head = LIST_HEAD_INIT(s_vbp_head); -//static struct venc_drv_buffer_t s_video_memory = {0}; //整个固件需要使用的buffer,当前申请了64M,传到固件中; -//static struct venc_drv_buffer_t s_tahoe_register = {0}; static bool use_reserve = false; static u32 cma_cfg_size; static struct tasklet_struct tahoe_tasklet; -//static struct venc_bit_firmware_info_t s_bit_firmware_info; - - struct vb2_queue vb2_q; struct mutex q_lock; @@ -154,15 +127,6 @@ struct vb2_manage_cap_st { uint64_t viraddr; }; -//static struct tahoe_clks s_tahoe_clks; - -//static struct tahoe_rsts s_tahoe_rsts; - -//static void tahoe_clk_enable(struct tahoe_clks *clks); -//static void tahoe_clk_disable(struct tahoe_clks *clks); -//static s32 tahoe_free_buffers(struct file *filp); - - struct tahoe_fmt { unsigned int v4l2_pix_fmt; unsigned int max_width; @@ -187,24 +151,6 @@ static const int fmt_list_out[MAX_FMT_NUM] = { V4L2_PIX_FMT_HEVC, V4L2_PIX_FMT_H264 }; -#if 0 -static void dma_flushh(struct device *dev, u32 buf_start, u32 buf_size) -{ - if (dev) - dma_sync_single_for_device( - dev, buf_start, - buf_size, DMA_TO_DEVICE); -} - -static void cache_flushh(struct device *dev, u64 buf_start, u32 buf_size) -{ - if (dev) - dma_sync_single_for_cpu( - dev, buf_start, - buf_size, DMA_FROM_DEVICE); -} -#endif - //__need_modify__ @@ -216,26 +162,19 @@ static void tahoe_isr_tasklet(ulong data) enc_pr(LOG_ALL, "[+]%s,data:%lx,open_count:%d,\n", __func__,data,dev->s_tahoe_drv_context.open_count); - //struct vb2_manage_st *src_vb = (struct vb2_manage_cap_st *)src_buf; - //src_vb->inst_on = (uint64_t)inst; - // struct venc_drv_context_t *s_context = &dev->s_tahoe_drv_context; - for (uint8_t i = 0; i < /*dev->s_tahoe_drv_context.open_count*/MAX_INSTANCE; i++) { + for (uint8_t i = 0; i < MAX_INSTANCE; i++) { enc_pr(LOG_ALL,"index:%d,inst_id:%d,instance addr:%lx\n",i,dev->cur_inst,P_T_UL(dev->instance[i])); if (dev->instance[i] && (dev->instance[i]->inst_id == dev->cur_inst)) { inst = dev->instance[i]; break; } - if (i == (/*dev->s_tahoe_drv_context.open_count*/MAX_INSTANCE - 1)) { + if (i == (MAX_INSTANCE - 1)) { enc_pr(LOG_ALL, "cannot find the instance,return\n"); return; } } - - enc_pr(LOG_ALL, "inst:%lx\n", (ulong)inst); - atomic_inc(&dev->s_tahoe_drv_context.request_ready); - wake_up_interruptible(&dev->s_tahoe_drv_context.request_complete); inst->output_f(inst); enc_pr(LOG_ALL, "[-]%s\n", __func__); @@ -246,19 +185,30 @@ static void tahoe_isr_tasklet(ulong data) static irqreturn_t tahoe_irq_handler(int irq, void *dev_id) { struct tahoe_device *root_dev = (struct tahoe_device *)dev_id; + if (NULL == dev_id) { + enc_pr(LOG_ERROR,"irq_handler,receive null ptr!\n"); + return IRQ_HANDLED; + } struct venc_drv_context_t *dev = &root_dev->s_tahoe_drv_context; + if (NULL == dev) { + enc_pr(LOG_ERROR,"irq_handler,find null ptr!\n"); + return IRQ_HANDLED; + } dev->interrupt_reason = tahoe_reg_read(root_dev,TAHOE_VRISC_IRQ_STAT); - enc_pr(LOG_INFO, "interrupt_reason 0x%lx\n", dev->interrupt_reason); + enc_pr(LOG_DEBUG, "interrupt_reason 0x%lx\n", dev->interrupt_reason); tahoe_reg_write(root_dev,TAHOE_VRISC_IRQ_STAT, ~dev->interrupt_reason); if (dev->interrupt_reason & IRQ_PRELOAD_DONE) { - //preload_irq_flag = 1; - enc_pr(LOG_INFO, "preload irq received, preload done\n"); + enc_pr(LOG_DEBUG, "preload irq received, preload done\n"); + wake_up_interruptible(&dev->request_complete); } if (dev->interrupt_reason & IRQ_SCR_WRITE) { - //scrw_irq_flag = 1; - enc_pr(LOG_INFO, "scr write irq received\n"); + if (CMD_DONE == tahoe_reg_read(root_dev,CMD_OPT_CODE)) { + enc_pr(LOG_DEBUG, "scr cmd done write irq received\n"); + wake_up_interruptible(&dev->request_complete); + } + enc_pr(LOG_DEBUG, "scr write irq received\n"); } if (dev->interrupt_reason & IRQ_FRM_DONE_FBC) { @@ -266,10 +216,8 @@ static irqreturn_t tahoe_irq_handler(int irq, void *dev_id) enc_pr(LOG_INFO, "frame done irq received,instance id:%d\n",root_dev->cur_inst);//0; tasklet_schedule(&tahoe_tasklet); } - //tasklet_schedule(&tahoe_tasklet); - enc_pr(LOG_ALL, "[-]%s\n", __func__); - //wake_up_interruptible(&s_interrupt_wait_q); + enc_pr(LOG_ALL, "[-]%s\n", __func__); return IRQ_HANDLED; } @@ -278,7 +226,6 @@ static int tahoe_vb2ops_queue_setup(struct vb2_queue *vq, unsigned int *num_buffers, unsigned int *num_planes, unsigned int sizes[], struct device *alloc_devs[]) { - enc_pr(LOG_INFO,"enter function tahoe_vb2ops_queue_setup\n"); struct tahoe_inst *inst = vb2_get_drv_priv(vq); int i = 0; @@ -302,7 +249,6 @@ static int tahoe_vb2ops_queue_setup(struct vb2_queue *vq, } static int tahoe_vb2ops_buffer_prepare(struct vb2_buffer *vb) { - enc_pr(LOG_INFO,"enter function tahoe_vb2ops_buffer_prepare\n"); return 0; } @@ -312,7 +258,6 @@ static void tahoe_vb2ops_buffer_queue(struct vb2_buffer *vb) { struct tahoe_inst *inst = vb2_get_drv_priv(vb->vb2_queue); struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx; - enc_pr(LOG_INFO,"enter function tahoe_vb2ops_buffer_queue\n"); v4l2_m2m_buf_queue(m2m_ctx, vbuf); return; } @@ -324,13 +269,11 @@ static int tahoe_vb2ops_buf_init(struct vb2_buffer *vb) { } static int tahoe_vb2ops_start_streaming(struct vb2_queue *vq, unsigned int count) { - enc_pr(LOG_INFO,"enter function tahoe_vb2ops_start_streaming,count:%d\n",count); + enc_pr(LOG_INFO,"tahoe_vb2ops_start_streaming,count:%d\n",count); #if 0 struct tahoe_inst *inst = vb2_get_drv_priv(vq); create_channel(inst->dev,inst); #endif - - enc_pr(LOG_INFO,"enter function tahoe_vb2ops_start_streaming end\n"); return 0; } @@ -361,11 +304,6 @@ static void tahoe_vb2ops_stop_streaming(struct vb2_queue *vq) { v4l2_m2m_buf_done(buf, VB2_BUF_STATE_ERROR); } v4l2_m2m_clear_state(m2m_ctx); -#if 0 - for (int i = 0;i < sizeof(inst->o_vaddr);i++) { - inst->o_vaddr[i] = 0; - } -#endif } inst->inst_init_flag = 0; //reset uninit state @@ -422,14 +360,11 @@ static int vb2_queue_tahoe_init(void *priv, struct vb2_queue *src_vq, struct vb2 int get_bsbframe(struct tahoe_device *dev,struct tahoe_inst *inst , ulong *es_virt, int *es_length,uint32_t *frame_type) { - //venc_info_t *venc = &s_venc_info; unsigned int esaddr_offset = 0; unsigned long esPhyAddr; int eslength; unsigned long espVirAddr = 0; unsigned long slice_header_length = 0; - //venc_buffer_t vdb; - //memset(&vdb, 0x00, sizeof(venc_buffer_t)); slice_header_length = tahoe_reg_read(dev, TAHOE_EC_DMA0) & 0x3F; esPhyAddr = tahoe_reg_read(dev, TAHOE_EC_DMA0) - slice_header_length; @@ -446,7 +381,6 @@ int get_bsbframe(struct tahoe_device *dev,struct tahoe_inst *inst , ulong *es_vi (*es_length) = eslength; (*es_virt) = (ulong)espVirAddr; - //cache_flushh(dev->dev,esPhyAddr,eslength); return 0; } @@ -471,10 +405,7 @@ void header_separate(struct tahoe_inst *inst,u64 timestamp) { int index = dst_buf->vb2_buf.index; ulong es_phy_addr = vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0); enc_pr(LOG_INFO,"es_phy_addr:%lx,index:%d",es_phy_addr,index); - //mutex_lock(&inst->inst_lock); ulong es_vir_addr = dst_man_buf->viraddr; - //ulong es_vir_addr = inst->o_vaddr[index]; - //mutex_unlock(&inst->inst_lock); if (0 == es_vir_addr) { enc_pr(LOG_INFO,"virtual addr is null!\n"); return; @@ -513,7 +444,6 @@ void header_separate(struct tahoe_inst *inst,u64 timestamp) { void output_proc(struct tahoe_inst *inst) { enc_pr(LOG_INFO,"output_proc enter,inst:%lx\n",(ulong)inst); - //struct tahoe_param *param = &inst->param; struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx; int header_len = 0; bool is_idr = false; @@ -526,18 +456,12 @@ void header_separate(struct tahoe_inst *inst,u64 timestamp) { bool is_daring_last_src = false; uint32_t frame_type = 0; - //is_idr = ((inst->param.poc - 1) == 0 || (inst->param.poc - 1) % 30 == 0) ? true : false; - get_bsbframe(inst->dev,inst, &es_addr, &es_len, &frame_type); if ((0 == frame_type) || (1 == frame_type)) { is_idr = 1; } - /* - * The source buffer will not be found in the ready-queue as it has been - * dropped after sending of the encode firmware command, locate it in - * the videobuf2 queue directly - */ + enc_pr(LOG_INFO,"output_proc src_index:%d,frame_type:%d,is_idr:%d\n",inst->param.src_buf_index,frame_type,is_idr); if (inst->param.src_buf_index >= 0) { struct vb2_buffer *vb = vb2_get_buffer(v4l2_m2m_get_src_vq(m2m_ctx), @@ -581,7 +505,6 @@ void header_separate(struct tahoe_inst *inst,u64 timestamp) { int index = dst_buf->vb2_buf.index; ulong es_phy_addr = vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0); enc_pr(LOG_INFO,"es_phy_addr:%lx,index:%d",es_phy_addr,index); - //ulong es_vir_addr = inst->o_vaddr[index]; ulong es_vir_addr = dst_man_buf->viraddr; if (0 == es_vir_addr) { enc_pr(LOG_INFO,"virtual addr is null!\n"); @@ -625,16 +548,14 @@ void header_separate(struct tahoe_inst *inst,u64 timestamp) { dst_buf->flags |= V4L2_BUF_FLAG_PFRAME; } - if (m2m_ctx->is_draining && is_daring_last_src/*v4l2_m2m_is_last_draining_src_buf(m2m_ctx,src_buf)*/) { //draining over + if (m2m_ctx->is_draining && is_daring_last_src) { //draining over enc_pr(LOG_INFO,"daining last buffer done!\n"); - //v4l2_m2m_last_buffer_done(m2m_ctx,dst_buf); static const struct v4l2_event tahoe_event_eos = { .type = V4L2_EVENT_EOS }; if (!WARN_ON(!dst_buf)) { - //vb2_set_plane_payload(&dst_buf->vb2_buf, 0, 0); dst_buf->field = V4L2_FIELD_NONE; v4l2_m2m_last_buffer_done(m2m_ctx, dst_buf); } @@ -871,10 +792,8 @@ static int tahoe_enc_s_ctrl(struct v4l2_ctrl *ctrl) } break; case V4L2_CID_MPEG_VIDEO_H264_PROFILE: - //if ((ctrl->val != inst->param.profile) && (ctrl->val != 0)) { inst->param.profile = toTahoeProfile(ctrl->val); enc_pr(LOG_DEBUG,"avc profile setting:%d\n",inst->param.profile); - //} break; case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE: if ((ctrl->val != inst->param.profile) && (ctrl->val != 0)) { @@ -887,17 +806,13 @@ static int tahoe_enc_s_ctrl(struct v4l2_ctrl *ctrl) } break; case V4L2_CID_MPEG_VIDEO_H264_LEVEL: { - // if ((ctrl->val != inst->param.level) && (ctrl->val != 0)) { inst->param.level = toTahoeAvcLevel(ctrl->val); enc_pr(LOG_DEBUG,"avc level setting:%d\n",inst->param.level); - // } break; } case V4L2_CID_MPEG_VIDEO_HEVC_LEVEL: - // if ((ctrl->val != inst->param.level) && (ctrl->val != 0)) { inst->param.level = toTahoeHevcLevel(ctrl->val); enc_pr(LOG_DEBUG,"hevc level setting:%d\n",inst->param.level); - //} break; case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT: break; @@ -941,7 +856,6 @@ static void tahoe_init_param(struct tahoe_param *param) { static int tahoe_v4l_open(struct file *filp) { - enc_pr(LOG_INFO, "tahoe_v4l_open \n"); struct tahoe_device *dev = video_drvdata(filp); struct video_device *vdev = video_devdata(filp); struct tahoe_inst *inst_info = NULL; @@ -950,8 +864,7 @@ static int tahoe_v4l_open(struct file *filp) { char *virt_ptr = NULL; s32 r = 0; - //enc_pr(LOG_DEBUG, "[+] %s, filp=%lu, %lu, f_count=%lld\n", __func__, - //(unsigned long)filp, ( ((unsigned long)filp)%8), filp->f_count.counter); + enc_pr(LOG_ERROR, "[+] %s\n", __func__); inst_info = kzalloc(sizeof(*inst_info), GFP_KERNEL); if (!inst_info) { enc_pr(LOG_ERROR, "alloc inst_info failed!\n"); @@ -963,7 +876,6 @@ static int tahoe_v4l_open(struct file *filp) { v4l2_ctrl_hdl = &inst_info->v4l2_ctrl_hdl; inst_info->dev = dev; - enc_pr(LOG_INFO,"output_f:%lx\n",P_T_UL(inst_info->output_f)); v4l2_fh_init(&inst_info->v4l2_fh,vdev); filp->private_data = &inst_info->v4l2_fh; @@ -1046,10 +958,9 @@ static int tahoe_v4l_open(struct file *filp) { dev->s_tahoe_drv_context.open_count++; if (dev->s_tahoe_drv_context.open_count == 1) { first_open = true; + init_waitqueue_head(&dev->s_tahoe_drv_context.request_complete); } - init_waitqueue_head(&dev->s_tahoe_drv_context.request_complete); atomic_set(&dev->s_tahoe_drv_context.request_ready, 0); - //filp->private_data = (void *)(&dev->s_tahoe_drv_context); spin_unlock(&s_vpu_lock); enc_pr(LOG_DEBUG, "first_open:%d,use_reserve:%d,open_count:%d,instance id:%d",first_open,use_reserve,dev->s_tahoe_drv_context.open_count,inst_info->inst_id); if (!use_reserve) { @@ -1058,10 +969,14 @@ static int tahoe_v4l_open(struct file *filp) { inst_info->s_video_memory.phys_addr = codec_mm_alloc_for_dma(DEVICE_NAME, cma_cfg_size >> PAGE_SHIFT, 0, 0); if (inst_info->s_video_memory.phys_addr) { - //inst_info->s_video_memory.virt_addr = (unsigned long)memremap(inst_info->s_video_memory.phys_addr, inst_info->s_video_memory.size, MEMREMAP_WB); inst_info->s_video_memory.virt_addr = (unsigned long)codec_mm_vmap_noncache(inst_info->s_video_memory.phys_addr, inst_info->s_video_memory.size); - enc_pr(LOG_DEBUG, "allocating phys 0x%llx, ", inst_info->s_video_memory.phys_addr); - enc_pr(LOG_DEBUG, "virt addr 0x%llx, size %dk\n", inst_info->s_video_memory.virt_addr, inst_info->s_video_memory.size >> 10); + enc_pr(LOG_ERROR, "allocating phys 0x%llx, ", inst_info->s_video_memory.phys_addr); + enc_pr(LOG_ERROR, "virt addr 0x%llx, size %dk\n", inst_info->s_video_memory.virt_addr, inst_info->s_video_memory.size >> 10); + if (0 == inst_info->s_video_memory.virt_addr) { + codec_mm_free_for_dma(DEVICE_NAME, inst_info->s_video_memory.phys_addr); + enc_pr(LOG_ERROR,"virtual addr is NULL\n"); + r = -ENOMEM; + } } else { enc_pr(LOG_ERROR, "Failed to alloc dma buffer %s, phys:0x%llx\n", DEVICE_NAME, inst_info->s_video_memory.phys_addr); @@ -1103,12 +1018,17 @@ static int tahoe_v4l_open(struct file *filp) { dev->fw_buffer.phys_addr = codec_mm_alloc_for_dma(DEVICE_NAME, PAGE_ALIGN(dev->fw_buffer.size) >> PAGE_SHIFT, 0, 0); if (dev->fw_buffer.phys_addr) { + enc_pr(LOG_ERROR, "allocating fw phys 0x%llx,size:%d \n", dev->fw_buffer.phys_addr,dev->fw_buffer.size); //virt_ptr = ioremap(dev->fw_buffer.phys_addr, dev->fw_buffer.size);//memremap(dev->fw_buffer.phys_addr, dev->fw_buffer.size, MEMREMAP_WB); virt_ptr = codec_mm_vmap_noncache(dev->fw_buffer.phys_addr, dev->fw_buffer.size); dev->fw_buffer.virt_addr = P_T_UL(virt_ptr); dev->fw_buffer.base = dev->fw_buffer.phys_addr; - enc_pr(LOG_DEBUG, "allocating fw phys 0x%llx,size:%d \n", dev->fw_buffer.phys_addr,dev->fw_buffer.size); enc_pr(LOG_DEBUG, "virt addr 0x%llx, size %dk\n", dev->fw_buffer.virt_addr, dev->fw_buffer.size >> 10); + if (NULL == virt_ptr) { + codec_mm_free_for_dma(DEVICE_NAME, dev->fw_buffer.phys_addr); + enc_pr(LOG_ERROR, "fw memory mmap failed,vir addr is NULL\n"); + r = -ENOMEM; + } } else { enc_pr(LOG_ERROR, "Failed to alloc dma buffer %s, phys:0x%llx\n", DEVICE_NAME, dev->fw_buffer.phys_addr); @@ -1128,6 +1048,10 @@ static int tahoe_v4l_open(struct file *filp) { r = -EBUSY; } if (first_open) { + /* enable tahoe clks and power*/ + tahoe_clk_enable(&dev->s_tahoe_clks, tahoe_pdev); + tahoe_top_sw_reset(dev); + if ((dev->s_tahoe_irq >= 0) && (dev->s_tahoe_irq_requested == false)) { s32 err; @@ -1143,10 +1067,6 @@ static int tahoe_v4l_open(struct file *filp) { dev->s_tahoe_irq_requested = true; } - - /* enable tahoe clks and power*/ - tahoe_clk_enable(&dev->s_tahoe_clks, tahoe_pdev); - tahoe_top_sw_reset(dev); } enc_pr(LOG_INFO,"reg base memory:%llx,first_open:%d\n",dev->s_tahoe_register.virt_addr,first_open); @@ -1168,11 +1088,7 @@ static int tahoe_v4l_open(struct file *filp) { enc_pr(LOG_INFO,"instance %d,value:%lx,dev:%lx\n",i,P_T_UL(dev->instance[i]),P_T_UL(dev)); } - //mutex_init(&inst_info->inst_lock); - - enc_pr(LOG_INFO,"output_f:%lx 1111\n",(ulong)inst_info->output_f); - enc_pr(LOG_DEBUG, "[-] %s, ret: %d\n", __func__, r); - + enc_pr(LOG_ERROR, "[-] %s, ret: %d\n", __func__, r); return r; } @@ -1182,6 +1098,8 @@ static int tahoe_v4l_release(struct file *filp) { struct tahoe_inst *pinst = GET_PRI(filp->private_data); dev->s_tahoe_drv_context.open_count--; + enc_pr(LOG_ERROR,"tahoe_v4l_release +\n"); + if (pinst->s_video_memory.phys_addr && !use_reserve) { enc_pr(LOG_DEBUG, "tahoe_release, s_video_memory 0x%llx\n", @@ -1259,10 +1177,8 @@ static int tahoe_v4l_release(struct file *filp) { v4l2_fh_del(&pinst->v4l2_fh); v4l2_fh_exit(&pinst->v4l2_fh); - // mutex_destroy(&pinst->inst_lock); - if (pinst) { - for (int i = 0;i < /*dev->s_tahoe_drv_context.open_count*/MAX_INSTANCE;i++) { + for (int i = 0;i < MAX_INSTANCE;i++) { if (dev->instance[i] && (dev->instance[i] == pinst)) { dev->instance[i] = NULL; } @@ -1273,7 +1189,7 @@ static int tahoe_v4l_release(struct file *filp) { filp->private_data = NULL; - enc_pr(LOG_INFO, "tahoe_v4l_release,dev:%lx \n",(ulong)dev); + enc_pr(LOG_ERROR, "tahoe_v4l_release,dev:%lx \n",(ulong)dev); return 0; } @@ -1282,26 +1198,22 @@ static const struct v4l2_file_operations tahoe_v4l_fops = { .open = tahoe_v4l_open, .release = tahoe_v4l_release, .read = vb2_fop_read, -.poll = v4l2_m2m_fop_poll,//tahoe_poll, -.unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */ -.mmap = v4l2_m2m_fop_mmap,//tahoe_mmap, +.poll = v4l2_m2m_fop_poll, +.unlocked_ioctl = video_ioctl2, +.mmap = v4l2_m2m_fop_mmap, }; static int tahoe_querycap(struct file *file, void *priv, struct v4l2_capability *cap) { - enc_pr(LOG_INFO,"enter function tahoe_querycap\n"); strscpy(cap->driver, "tahoe", sizeof(cap->driver)); strscpy(cap->card, "tahoe", sizeof(cap->card)); cap->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING; cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; - enc_pr(LOG_INFO,"leave function tahoe_querycap\n"); return 0; } static int tahoe_enum_fmt_vid(struct file *file, void *fh, struct v4l2_fmtdesc *f) { - enc_pr(LOG_INFO,"enter function tahoe_enum_fmt_vid_cap\n"); - int *fmt_list_ptr = NULL; if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE || f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { fmt_list_ptr = (int *)&fmt_list[0]; @@ -1319,7 +1231,7 @@ static int tahoe_enum_fmt_vid(struct file *file, void *fh, struct v4l2_fmtdesc * f->flags = 0; } else { - enc_pr(LOG_ERROR,"enter function query fmt support failed\n"); + enc_pr(LOG_ERROR,"function query fmt support failed\n"); return -EINVAL; } return 0; @@ -1397,8 +1309,6 @@ int ditrans_fmt(img_format_e hw_fmt,int *v4l_fmt) { #if 1 static int tahoe_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f) { - enc_pr(LOG_INFO,"enter function tahoe_g_fmt_vid_cap\n"); - struct tahoe_inst *pinst = GET_PRI(fh); if ( pinst->param.codec_type == CODEC_ID_H264) { @@ -1424,7 +1334,6 @@ static int tahoe_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format * static int tahoe_g_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *f) { - enc_pr(LOG_INFO,"enter function tahoe_g_fmt_vid_out\n"); int i = 0; struct tahoe_inst *pinst = GET_PRI(fh); @@ -1438,13 +1347,12 @@ static int tahoe_g_fmt_vid_out(struct file *file, void *fh, struct v4l2_format * ditrans_fmt(pinst->param.fmt,&f->fmt.pix_mp.pixelformat); //f->fmt.pix_mp.field = V4L2_FIELD_NONE; - enc_pr(LOG_INFO,"enter function tahoe_g_fmt_vid_out end,num_planes:%d\n",f->fmt.pix_mp.num_planes); + enc_pr(LOG_INFO,"function tahoe_g_fmt_vid_out end,num_planes:%d\n",f->fmt.pix_mp.num_planes); return 0; } static int tahoe_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f) { - enc_pr(LOG_INFO,"enter function tahoe_try_fmt_vid_cap,fmt:%d\n",f->fmt.pix_mp.pixelformat); f->fmt.pix_mp.flags = 0; //f->fmt.pix_mp.field = V4L2_FIELD_NONE; @@ -1453,10 +1361,11 @@ static int tahoe_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format } static int tahoe_try_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *f) { - enc_pr(LOG_INFO,"enter function tahoe_try_fmt_vid_out,fmt:%d,plane_num:%d\n",f->fmt.pix_mp.pixelformat,f->fmt.pix_mp.num_planes); int width; - int height; - const struct v4l2_format_info *info = v4l2_format_info(f->fmt.pix_mp.pixelformat); + int height; + const struct v4l2_format_info *info = v4l2_format_info(f->fmt.pix_mp.pixelformat); + + enc_pr(LOG_INFO,"tahoe_try_fmt_vid_out,fmt:%d,plane_num:%d\n",f->fmt.pix_mp.pixelformat,f->fmt.pix_mp.num_planes); if ((f->fmt.pix_mp.width < 128) || (f->fmt.pix_mp.height < 128)) { f->fmt.pix_mp.width = 128; @@ -1478,26 +1387,21 @@ static int tahoe_try_fmt_vid_out(struct file *file, void *fh, struct v4l2_format if (f->fmt.pix_mp.num_planes == 1) { if (V4L2_PIX_FMT_RGBA32 == f->fmt.pix_mp.pixelformat) { enc_pr(LOG_INFO,"try set rgba32 format\n"); - //f->fmt.pix_mp.plane_fmt[0].bytesperline = width * 4; f->fmt.pix_mp.plane_fmt[0].sizeimage = width * height * 4; } else if (V4L2_PIX_FMT_RGB24 == f->fmt.pix_mp.pixelformat) { enc_pr(LOG_INFO,"try set rgb24 format\n"); - //f->fmt.pix_mp.plane_fmt[0].bytesperline = width * 3; f->fmt.pix_mp.plane_fmt[0].sizeimage = width * height * 3; } else { - //f->fmt.pix_mp.plane_fmt[0].bytesperline = width; f->fmt.pix_mp.plane_fmt[0].sizeimage = width * height * 3 / 2; //fix me!! } } else if (f->fmt.pix_mp.num_planes == 2) { - //f->fmt.pix_mp.plane_fmt[0].bytesperline = width; f->fmt.pix_mp.plane_fmt[0].sizeimage = width * height; f->fmt.pix_mp.plane_fmt[1].sizeimage = width * height / 2; //fix me!! align need confirm } else if (f->fmt.pix_mp.num_planes == 3) { - //f->fmt.pix_mp.plane_fmt[0].bytesperline = width; f->fmt.pix_mp.plane_fmt[0].sizeimage = width * height; f->fmt.pix_mp.plane_fmt[1].sizeimage = width * height / 4; f->fmt.pix_mp.plane_fmt[2].sizeimage = width * height / 4; @@ -1510,10 +1414,8 @@ static int tahoe_try_fmt_vid_out(struct file *file, void *fh, struct v4l2_format return 0; } -#define valid_color(a) static int tahoe_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f) { - enc_pr(LOG_INFO,"enter function tahoe_s_fmt_vid_cap,format:%d\n",f->fmt.pix_mp.pixelformat); struct tahoe_inst *pinst = GET_PRI(fh); tahoe_try_fmt_vid_cap(file, fh, f); @@ -1539,11 +1441,11 @@ static int tahoe_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format * static int tahoe_s_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *f) { - enc_pr(LOG_INFO,"enter function tahoe_s_fmt_vid_out,type:%d,width:%d,height:%d,num_planes:%d,fmt:%d\n",f->type,f->fmt.pix_mp.width,f->fmt.pix_mp.height, - f->fmt.pix_mp.num_planes,f->fmt.pix_mp.pixelformat); struct tahoe_inst *pinst = GET_PRI(fh); int i = 0; + enc_pr(LOG_INFO,"tahoe_s_fmt_vid_out,type:%d,width:%d,height:%d,num_planes:%d,fmt:%d\n",f->type,f->fmt.pix_mp.width,f->fmt.pix_mp.height, + f->fmt.pix_mp.num_planes,f->fmt.pix_mp.pixelformat); tahoe_try_fmt_vid_out(file, fh, f); pinst->param.width = f->fmt.pix_mp.width; @@ -1594,7 +1496,6 @@ static int tahoe_enc_g_parm(struct file *file, void *fh, struct v4l2_streamparm static int tahoe_enc_s_parm(struct file *file, void *fh, struct v4l2_streamparm *param) { - enc_pr(LOG_INFO,"tahoe_enc_s_parm enter\n"); struct tahoe_inst *inst = GET_PRI(fh); enc_pr(LOG_INFO,"tahoe_enc_s_parm type:%u\n",param->type); @@ -1622,26 +1523,14 @@ static int tahoe_ioctl_reqbufs(struct file *file, void *priv, struct v4l2_reques } int tahoe_ioctl_qbuf(struct file *file, void *priv,struct v4l2_buffer *buf) { - enc_pr(LOG_INFO,"v4l2_m2m_ioctl_qbuf memory type:%d,type:%d,share_fd:%d\n",buf->memory,buf->type,buf->m.planes[0].m.fd); - //struct tahoe_device *dev = video_drvdata(file); struct tahoe_inst *inst = GET_PRI(file->private_data); struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx; - //mutex_lock(&inst->inst_lock); + + enc_pr(LOG_INFO,"v4l2_m2m_ioctl_qbuf memory type:%d,type:%d,share_fd:%d\n",buf->memory,buf->type,buf->m.planes[0].m.fd); int ret = v4l2_m2m_ioctl_qbuf(file, priv,buf); if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { enc_pr(LOG_INFO,"output buffer transform!,buffer flags:%x\n",buf->flags); - #if 0 - int index = buf->index; - struct vb2_buffer *vb = vb2_get_buffer(v4l2_m2m_get_dst_vq(m2m_ctx), index); - struct vb2_manage_cap_st *man_vb = (struct vb2_manage_cap_st *)vb; - - enc_pr(LOG_ERROR,"vb:%llx,vb plane_num:%d\n",(uint64_t)vb,vb->num_planes); - man_vb->viraddr = (uint64_t)vb2_plane_vaddr(vb, 0); - //inst->o_vaddr[index] = (uint64_t)vb2_plane_vaddr(vb, 0); - enc_pr(LOG_ERROR,"vaddr:%llx,index:%d",man_vb->viraddr,index); - #endif - //} } else { int index = buf->index; @@ -1649,7 +1538,6 @@ int tahoe_ioctl_qbuf(struct file *file, void *priv,struct v4l2_buffer *buf) { struct vb2_buffer *vb = vb2_get_buffer(v4l2_m2m_get_dst_vq(m2m_ctx), index); enc_pr(LOG_INFO,"vb:%llx,vb plane_num:%d\n",(uint64_t)vb,vb->num_planes); } - //mutex_unlock(&inst->inst_lock); enc_pr(LOG_INFO,"v4l2_m2m_ioctl_qbuf ret:%d",ret); return ret; } @@ -1726,11 +1614,11 @@ static const struct v4l2_ioctl_ops tahoe_ioctl_ops = { .vidioc_g_fmt_vid_out_mplane = tahoe_g_fmt_vid_out, .vidioc_try_fmt_vid_out_mplane = tahoe_try_fmt_vid_out, -.vidioc_reqbufs = tahoe_ioctl_reqbufs,//v4l2_m2m_ioctl_reqbufs, +.vidioc_reqbufs = tahoe_ioctl_reqbufs, .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, -.vidioc_qbuf = tahoe_ioctl_qbuf,//v4l2_m2m_ioctl_qbuf, +.vidioc_qbuf = tahoe_ioctl_qbuf, .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, .vidioc_streamon = v4l2_m2m_ioctl_streamon, @@ -1741,46 +1629,9 @@ static const struct v4l2_ioctl_ops tahoe_ioctl_ops = { .vidioc_try_encoder_cmd = v4l2_m2m_ioctl_try_encoder_cmd, .vidioc_encoder_cmd = tahoe_ioctl_encoder_cmd, -#if 0 -.vidioc_reqbufs = NULL,//vidioc_reqbufs, -.vidioc_querybuf = NULL,//vidioc_querybuf, -.vidioc_qbuf = NULL,//vidioc_qbuf, -.vidioc_expbuf = NULL,//vb2_ioctl_expbuf, -.vidioc_dqbuf = NULL,//vidioc_dqbuf, -.vidioc_s_std = NULL,//vidioc_s_std, -.vidioc_queryctrl = NULL,//vidioc_queryctrl, -.vidioc_g_ctrl = NULL,//vidioc_g_ctrl, -.vidioc_s_ctrl = NULL,//vidioc_s_ctrl, -.vidioc_g_ext_ctrls = NULL,//videoenc_g_ext_ctrls, -.vidioc_s_ext_ctrls = NULL,//videoenc_s_ext_ctrls, -.vidioc_streamon = NULL,//vidioc_streamon, -.vidioc_streamoff = NULL,//vidioc_streamoff, -.vidioc_enum_framesizes = NULL,//vidioc_enum_framesizes, -.vidioc_enum_frameintervals = NULL,//vidioc_enum_frameintervals, -.vidioc_s_input = NULL,//vidioc_s_input, -.vidioc_g_input = NULL,//vidioc_g_input, -.vidioc_g_selection = NULL,//vidioc_g_selection, -.vidioc_s_selection = NULL,//vidioc_s_selection, -.vidioc_s_output = NULL,//vidioc_s_output, -.vidioc_subscribe_event = NULL,//vidioc_subscribe_event, -.vidioc_unsubscribe_event = NULL,//vidioc_unsubscribe_event, -#endif }; -#if 0 -static struct video_device tahoe_template = { -.name = "tahoe", -.fops = &tahoe_v4l_fops, -.ioctl_ops = &tahoe_ioctl_ops, -.release = video_device_release, -.tvnorms = V4L2_STD_525_60, -/* .current_norm = V4L2_STD_NTSC_M, */ -}; -#endif - - - static void tahoe_device_run(void *priv) { struct tahoe_inst *inst = priv; @@ -1840,7 +1691,6 @@ static void tahoe_device_run(void *priv) if (param->inpt_buf_addr[0] == param->inpt_buf_addr[1]) { param->inpt_buf_addr[1] = param->inpt_buf_addr[0] + param->width * param->height; } - //frame_buf.buf_cr = frame_buf.buf_cb + chroma_size; } else if (param->plane_num == 3) { param->inpt_buf_addr[0] = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0); @@ -1851,31 +1701,22 @@ static void tahoe_device_run(void *priv) } param->src_buf_index = src_buf->vb2_buf.index; enc_pr(LOG_INFO,"tahoe_device_run src_buf_index:%d\n",param->src_buf_index); - - //frame_buf.stride = stride; - //pic_param.src_idx = src_buf->vb2_buf.index; } - - //mutex_lock(&dev->dev_lock); dst_buf = v4l2_m2m_next_dst_buf(m2m_ctx); if (!dst_buf) { - //mutex_unlock(&dev->dev_lock); v4l2_m2m_job_finish(inst->v4l2_m2m_dev, m2m_ctx); enc_pr(LOG_ERROR, "%s: No destination buffer found\n", __func__); return; } struct vb2_manage_cap_st *man_vb = (struct vb2_manage_cap_st *)dst_buf; - //enc_pr(LOG_ERROR,"vb:%llx,vb plane_num:%d\n",(uint64_t)vb,vb->num_planes); man_vb->viraddr = (uint64_t)vb2_plane_vaddr(&dst_buf->vb2_buf, 0); enc_pr(LOG_INFO,"vaddr:%llx",man_vb->viraddr); - //mutex_unlock(&dev->dev_lock); param->es_addr = vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0); param->es_buf_size = vb2_plane_size(&dst_buf->vb2_buf, 0); enc_pr(LOG_INFO,"get es_addr:%llx\n",param->es_addr); - //dma_flushh(dev->dev, param->es_addr, param->es_buf_size); if (!inst->inst_init_flag) { create_channel(inst->dev,inst); @@ -1883,10 +1724,6 @@ static void tahoe_device_run(void *priv) } encode_one_frame(dev,inst); - //if (src_buf) { - //enc_pr(LOG_ERROR,"remove src buf from vb2,index:%d\n",src_buf->vb2_buf.index); - //v4l2_m2m_src_buf_remove_by_idx(m2m_ctx, src_buf->vb2_buf.index); - // } inst->param.poc++; inst->hw_proc_count++; enc_pr(LOG_INFO,"enter function tahoe_device_run end\n"); @@ -1921,7 +1758,6 @@ static s32 tahoe_probe(struct platform_device *pdev) s32 err = 0, irq, reg_count; struct resource res; struct device_node *np, *child; - // struct video_device *vdev = NULL; struct tahoe_device *dev = NULL; int ret = 0; @@ -1939,9 +1775,6 @@ static s32 tahoe_probe(struct platform_device *pdev) tahoe_pdev = NULL; s_register_flag = 0; - //memset(&s_video_memory, 0, sizeof(struct venc_drv_buffer_t)); - //memset(&s_tahoe_register, 0, sizeof(struct venc_drv_buffer_t)); - //memset(&s_bit_firmware_info, 0, sizeof(s_bit_firmware_info)); memset(&res, 0, sizeof(struct resource)); cma_cfg_size = 36*SZ_1M; //__need_modify__ @@ -1952,17 +1785,10 @@ static s32 tahoe_probe(struct platform_device *pdev) enc_pr(LOG_INFO, "probe dev:%lx \n",(unsigned long)dev); dev_set_drvdata(&pdev->dev, dev); dev->dev = &pdev->dev; - //memset(&dev->s_video_memory, 0, sizeof(struct venc_drv_buffer_t)); + memset(&dev->s_tahoe_register, 0, sizeof(struct venc_drv_buffer_t)); memset(&dev->s_tahoe_drv_context,0,sizeof(struct venc_drv_context_t)); -#if 0 - dev->s_tahoe_register.phys_addr = TAHOE_REG_BASE_ADDR; - dev->s_tahoe_register.virt_addr = (unsigned long)ioremap(s_tahoe_register.phys_addr, TAHOE_REG_SIZE); - dev->s_tahoe_register.size = TAHOE_REG_SIZE; - enc_pr(LOG_ERROR, "s_venc_register.phys_addr = 0x%lx\n", dev->s_tahoe_register.phys_addr); - enc_pr(LOG_ERROR, "s_venc_register.virt_addr = 0x%lx, size = 0x%x\n", dev->s_tahoe_register.virt_addr, TAHOE_REG_SIZE); -#endif /* get interrupt resource */ irq = platform_get_irq_byname(pdev, "tahoe_irq0"); @@ -2022,19 +1848,9 @@ static s32 tahoe_probe(struct platform_device *pdev) } else enc_pr(LOG_DEBUG, "tahoe. rsts get success\n"); - /* get the major number of the character device */ - /* if (init_tahoe_device()) { - err = -EBUSY; - enc_pr(LOG_ERROR, "could not allocate major number\n"); - - goto ERROR_PROVE_DEVICE; - }*/ - snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), "%s", DEVICE_NAME); - //platform_set_drvdata(pdev, &dev->v4l2_dev); - dev->tahoe_m2m_dev = v4l2_m2m_init(&tahoe_m2m_ops); if (IS_ERR(dev->tahoe_m2m_dev)) { enc_pr(LOG_ERROR, "v4l2_m2m_init, fail: %d\n", ret); @@ -2051,31 +1867,12 @@ static s32 tahoe_probe(struct platform_device *pdev) mutex_init(&dev_lock); mutex_init(&dev->dev_lock); -#if 0 - vb2_q.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - vb2_q.io_modes = VB2_MMAP | VB2_DMABUF | VB2_READ; - - vb2_q.dev = &pdev->dev; - vb2_q.drv_priv = &s_tahoe_drv_context;//aml2_dev; - vb2_q.buf_struct_size = sizeof(struct vb2_manage_st);//sizeof(struct amlvideo2_node_buffer); - vb2_q.ops = &tahoe_vb2ops; - vb2_q.mem_ops = &vb2_dma_contig_memops; - vb2_q.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; - vb2_q.min_queued_buffers = 1; - vb2_q.lock = &q_lock; - - ret = vb2_queue_init(&vb2_q); - if (ret < 0) { - enc_pr(LOG_INFO, "%s: vb2_queue_init fail\n", __func__); - goto ERROR_PROVE_DEVICE; - } -#endif + dev->vdev = video_device_alloc(); if (!dev->vdev) { goto ERROR_PROVE_DEVICE; } - //*dev->vdev = tahoe_template; strscpy(dev->vdev->name, "tahoe_enc", sizeof(dev->vdev->name)); dev->vdev->fops = &tahoe_v4l_fops; dev->vdev->ioctl_ops = &tahoe_ioctl_ops; @@ -2084,14 +1881,12 @@ static s32 tahoe_probe(struct platform_device *pdev) dev->vdev->v4l2_dev = &dev->v4l2_dev; dev->vdev->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING ; dev->vdev->vfl_dir = VFL_DIR_M2M; - //dev->vdev->queue = &vb2_q; dev->vdev->lock = &dev_lock; ret = video_register_device(dev->vdev, VFL_TYPE_VIDEO, video_nr); if (ret < 0) { ret = -ENODEV; goto ERROR_PROVE_DEVICE; - //return ret; } video_set_drvdata(dev->vdev, dev); @@ -2114,7 +1909,6 @@ ERROR_PROVE_DEVICE: video_unregister_device(dev->vdev); if (dev->tahoe_m2m_dev) v4l2_m2m_release(dev->tahoe_m2m_dev); - //uninit_tahoe_device(); v4l2_device_unregister(&dev->v4l2_dev); video_device_release(dev->vdev); return err; @@ -2124,15 +1918,7 @@ static KV_INT_TO_VOID tahoe_remove(struct platform_device *pdev) { struct tahoe_device *dev = dev_get_drvdata(&pdev->dev); enc_pr(LOG_DEBUG, "tahoe_remove\n"); -#if 0 - if (s_video_memory.phys_addr) { - codec_mm_free_for_dma( - DEVICE_NAME, - s_video_memory.phys_addr); - memset(&s_video_memory, - 0, sizeof(struct venc_drv_buffer_t)); - } -#endif + if (dev->s_tahoe_irq_requested == true) { if (dev->s_tahoe_irq >= 0) { free_irq(dev->s_tahoe_irq, /*&dev->s_tahoe_drv_context*/dev); @@ -2151,14 +1937,12 @@ static KV_INT_TO_VOID tahoe_remove(struct platform_device *pdev) tahoe_clk_disable(&dev->s_tahoe_clks, tahoe_pdev); } tahoe_clk_put(&tahoe_pdev->dev, &dev->s_tahoe_clks); - //tahoe_pdev = NULL; mutex_destroy(&dev->dev_lock); video_unregister_device(dev->vdev); if (dev->tahoe_m2m_dev) v4l2_m2m_release(dev->tahoe_m2m_dev); v4l2_device_unregister(&dev->v4l2_dev); - //uninit_tahoe_device(); if (dev) { kfree(dev); dev = NULL; diff --git a/tahoe_v4l/tahoe_hw.c b/tahoe_v4l/tahoe_hw.c index 11a58c7..b3f52ac 100644 --- a/tahoe_v4l/tahoe_hw.c +++ b/tahoe_v4l/tahoe_hw.c @@ -55,7 +55,6 @@ int tahoe_load_fw(struct tahoe_device *dev, const char *fw_name) { const struct firmware *fw; int ret; - char *test = NULL; enc_pr(LOG_ERROR, "tahoe_load_firmware %s\n",fw_name); ret = request_firmware(&fw, fw_name, dev->dev); @@ -67,10 +66,8 @@ int tahoe_load_fw(struct tahoe_device *dev, const char *fw_name) enc_pr(LOG_ERROR,"dev->fw_buffer.virt_addr:%llx\n",dev->fw_buffer.virt_addr); memcpy((void*)dev->fw_buffer.virt_addr, fw->data, fw->size); - test = (char *)dev->fw_buffer.virt_addr; - enc_pr(LOG_ERROR,"tahoe_load_fw,%llx %px\n",dev->fw_buffer.virt_addr,(void*)dev->fw_buffer.virt_addr); - enc_pr(LOG_ERROR,"fw content:%x %x %x %x %x %x %x %x\n",test[0],test[1],test[2],test[3],test[4],test[5],test[6],test[7]); + enc_pr(LOG_ERROR,"tahoe_load_fw,%llx %px\n",dev->fw_buffer.virt_addr,(void*)dev->fw_buffer.virt_addr); return 0; } @@ -81,7 +78,6 @@ void create_channel(struct tahoe_device *dev,struct tahoe_inst *pinst) int data = 0; struct tahoe_param *param = &pinst->param; enc_pr(LOG_ERROR,"[%s][%d]create_channel start\n", __func__, __LINE__); - //venc_info_t *venc = &s_venc_info; disable_host_scrw_irq(dev); tahoe_reg_write(dev, CHN_ID, param->id); @@ -190,15 +186,8 @@ void dynamic_parameter_set(struct tahoe_device *dev,struct tahoe_param *param) int get_header(struct tahoe_device *dev, struct tahoe_inst *inst) { - //unsigned long vpsPhyAddr, spsPhyAddr, ppsPhyAddr; int headerLength = 0;//, vpsLength, spsLength, ppsLength; - //unsigned int headeroffset = 0; - //unsigned long headerVirAddr = 0; -#if 0 - inst->vps.phy_addr_act = tahoe_reg_read(dev, HEADER_VPS_ADDR); - inst->sps.phy_addr_act = tahoe_reg_read(dev,HEADER_SPS_ADDR); - inst->pps.phy_addr_act = tahoe_reg_read(dev,HEADER_PPS_ADDR); -#endif + inst->vps.phy_addr_act = ((((uint64_t)(tahoe_reg_read(dev, HEADER_ADDR_HIGHER) >> 4) & 0x03)) << 32) | tahoe_reg_read(dev,HEADER_VPS_ADDR); inst->sps.phy_addr_act = (((uint64_t)(tahoe_reg_read(dev, HEADER_ADDR_HIGHER) & 0x03)) << 32) | tahoe_reg_read(dev,HEADER_SPS_ADDR); inst->pps.phy_addr_act = ((((uint64_t)(tahoe_reg_read(dev, HEADER_ADDR_HIGHER) >> 2) & 0x03)) << 32) | tahoe_reg_read(dev,HEADER_PPS_ADDR); @@ -213,18 +202,7 @@ int get_header(struct tahoe_device *dev, struct tahoe_inst *inst) inst->vps.size = (headerLength & 0xff0000) >> 16; inst->sps.size = (headerLength & 0xff00) >> 8; inst->pps.size = (headerLength & 0xff); -#if 0 - if (handle->enc_fmt == CODEC_ID_H265) { - vdi_read_memory(vpsPhyAddr, pHeader, vpsLength); - vdi_read_memory(spsPhyAddr, pHeader+vpsLength, spsLength); - vdi_read_memory(ppsPhyAddr, pHeader+vpsLength+spsLength, ppsLength); - *pLength = vpsLength + spsLength + ppsLength; - } else if (handle->enc_fmt == CODEC_ID_H264) { - vdi_read_memory(spsPhyAddr, pHeader, spsLength); - vdi_read_memory(ppsPhyAddr, pHeader+spsLength, ppsLength); - *pLength = spsLength + ppsLength; - } -#endif + enc_pr(LOG_INFO,"[%s][%d]headerLength:%d %d %d\n", __func__, __LINE__,inst->vps.size,inst->sps.size,inst->pps.size); return 0; } @@ -354,9 +332,8 @@ void tahoe_top_sw_reset(struct tahoe_device *dev) } int tahoe_boot(struct tahoe_device *dev) { - int data = 0; enc_pr(LOG_ERROR, "tahoe boot begin,reg addr:%llx!\n",dev->s_tahoe_register.phys_addr); - //venc_info_t *venc = &s_venc_info; + tahoe_reg_write(dev, TAHOE_VRISC_MBASE, dev->fw_buffer.phys_addr); tahoe_reg_write(dev, TAHOE_VRISC_MISC, ((dev->fw_buffer.phys_addr >> 32 & 0x03) << 16)); @@ -364,26 +341,20 @@ int tahoe_boot(struct tahoe_device *dev) { (PRELOAD_SIZE << 0) | // mpreload_size_m1 (0 << 12) | // mpreload_axi_id (1 << 31)); // mpreload_enable); - data = tahoe_reg_read(dev, TAHOE_VRISC_MPRELOAD) >> 31; - while (0 != data) { - data = tahoe_reg_read(dev, TAHOE_VRISC_MPRELOAD) >> 31; - //usleep(1000); - } + wait_event_interruptible(dev->s_tahoe_drv_context.request_complete, + (dev->s_tahoe_drv_context.interrupt_reason & IRQ_PRELOAD_DONE)); + enc_pr(LOG_ERROR, "tahoe preload OK!\n"); - #if 1 tahoe_reg_write(dev, TAHOE_VRISC_CORECFG, ((1 << 0) | // stop_on_reset release (0 << 1) | // clkgate_bypass (0 << 2) | // reset_bypass (0 << 3) )); // reserved enc_pr(LOG_ERROR, "tahoe reset ok!\n"); - data = tahoe_reg_read(dev, CMD_OPT_CODE); - while (CMD_DONE != data) { - data = tahoe_reg_read(dev, CMD_OPT_CODE); - //usleep(100); - } - #endif + wait_event_interruptible(dev->s_tahoe_drv_context.request_complete, + (dev->s_tahoe_drv_context.interrupt_reason & IRQ_SCR_WRITE)); + enc_pr(LOG_ERROR, "tahoe boot OK!\n"); return 0; } diff --git a/tahoe_v4l/tahoe_register.h b/tahoe_v4l/tahoe_register.h index b9fbbb2..4c7a6ba 100644 --- a/tahoe_v4l/tahoe_register.h +++ b/tahoe_v4l/tahoe_register.h @@ -277,4 +277,27 @@ enum profile_e PROFILE_HIGH422 = 122, PROFILE_HIGH444_PREDICTIVE = 244, }; + + + +#define IRQ_FRM_DONE_FBC 0x1 +#define IRQ_FRM_START 0x2 +#define IRQ_SCR_WRITE 0x4 +#define IRQ_RDMA_DONE 0x8 +#define IRQ_PRELOAD_DONE 0x10 +#define IRQ_ROWRC_1 0x20 +#define IRQ_ROWRC_2 0x40 +#define IRQ_FRM_DONE_EC 0x80 +#define IRQ_FRM_DONE_LPF 0x100 +#define IRQ_FRM_DONE_RDO 0x200 +#define IRQ_FRM_DONE_ME 0x400 +#define IRQ_SLICE_DONE_FBC 0x800 +#define IRQ_SLICE_DONE_EC 0x1000 +#define IRQ_SLICE_DONE_LPF 0x2000 +#define IRQ_SLICE_DONE_RDO 0x4000 +#define IRQ_SLICE_DONE_ME 0x8000 +#define IRQ_ES_OVERFLOW 0x10000 +#define IRQ_RESERVED 0x20000 +#define IRQ_LOW_LATENCY 0x40000 + #endif -- 2.43.2