static int jpeg_flush(struct file * a_pstFile , fl_owner_t a_id) { unsigned int *pStatus; pStatus = (unsigned int*)a_pstFile->private_data; if(NULL == pStatus) { JPEG_WRN("Private data is null in flush operation. HOW COULD THIS HAPPEN ??\n"); return -EFAULT; } if (*pStatus == JPEG_DEC_PROCESS) { if(dec_status != 0) { JPEG_WRN("Error! Enable error handling for jpeg decoder"); jpeg_drv_dec_deinit(); } } else if (*pStatus == JPEG_ENC_PROCESS) { if(enc_status != 0) { JPEG_WRN("Error! Enable error handling for jpeg encoder"); jpeg_drv_enc_deinit(); } } return 0; }
//-------------------------------------------------------------------------- // JPEG REG DUMP FUNCTION //-------------------------------------------------------------------------- void jpeg_reg_dump(void) { unsigned int reg_value = 0; unsigned int index = 0; JPEG_WRN("JPEG REG:\n ********************\n"); for(index = 0 ; index < 0x168 ; index += 4) { reg_value = ioread32(JPG_CODEC_BASE + index); JPEG_WRN("+0x%x 0x%x\n", index, reg_value); } }
static int jpeg_drv_enc_init(void) { int retValue; spin_lock(&jpeg_enc_lock); if(enc_status != 0) { JPEG_WRN("JPEG Encoder is busy\n"); retValue = -EBUSY; } else { enc_status = 1; retValue = 0; } spin_unlock(&jpeg_enc_lock); if(retValue == 0) { jpeg_drv_enc_power_on(); jpeg_drv_enc_reset(); } return retValue; }
void jpeg_drv_dec_warm_reset(void) { unsigned int int_status, i, value; int_status = REG_JPGDEC_INTERRUPT_STATUS; /* clear all interrupts except pause interrupt since clear this interrupt will cause HW to trigger */ IMG_REG_WRITE(0x000000EF, REG_ADDR_JPGDEC_INTERRUPT_STATUS); /* ack decoder */ /* we need to wait GMC idle only when EOF irq does not issue */ if (!(int_status & BIT_INQST_MASK_EOF)) { IMG_REG_READ(value, REG_ADDR_JPGDEC_DU_CTRL); IMG_REG_WRITE((value & 0xBFFFFFFF), REG_ADDR_JPGDEC_DU_CTRL); /* dsiable GMC */ /* wait GMC idle */ i = 5000; while (i > 0) { /* break if GMC idle is 1 */ if (((REG_JPGDEC_STATUS) & 0x08000000)) break; i--; } if (i == 0) { /* dump key register */ JPEG_WRN ("[JPEGDRV] jpeg_dec_reset timeout!! 0x278 = 0x%x, 0x23c = 0x%x, 0x184 = 0x%x\n", REG_JPGDEC_STATUS, REG_JPGDEC_DU_CTRL, REG_JPGDEC_DEBUG1); JPEG_WRN ("[JPEGDRV] 0x304 = 0x%x, 0x308 = 0x%x, 0x30c = 0x%x, 0x310 = 0x%x\n", REG_JPGDEC_SMI_DEBUG0, REG_JPGDEC_SMI_DEBUG1, REG_JPGDEC_SMI_DEBUG2, REG_JPGDEC_SMI_DEBUG3); } } IMG_REG_WRITE(0x00, REG_ADDR_JPGDEC_RESET); IMG_REG_WRITE(0x10, REG_ADDR_JPGDEC_RESET); /* REG_JPGDEC_RESET = 0x00; */ _jpeg_dec_int_status = 0; _jpeg_dec_mode = 0; }
void jpeg_drv_dec_soft_reset(void) { unsigned int int_status, i; int_status = REG_JPGDEC_INTERRUPT_STATUS; // clear all interrupts except pause interrupt since clear this interrupt will cause HW to trigger IMG_REG_WRITE(0x000000EF, REG_ADDR_JPGDEC_INTERRUPT_STATUS); //ack decoder // we need to wait GMC idle only when EOF irq does not issue if (!(int_status & BIT_INQST_MASK_EOF)) { IMG_REG_WRITE(((REG_JPGDEC_DU_CTRL) & 0xBFFFFFFF), REG_ADDR_JPGDEC_DU_CTRL); //dsiable GMC // wait GMC idle i = 5000; while(i > 0) { // break if GMC idle is 1 if (((REG_JPGDEC_STATUS) & 0x08000000)) { break; } i--; } if (i == 0) { // dump key register JPEG_WRN("[JPEGDRV] jpeg_drv_dec_soft_reset timeout!! 0x278 = 0x%x, 0x23c = 0x%x, 0x184 = 0x%x\n", REG_JPGDEC_STATUS, REG_JPGDEC_DU_CTRL, REG_JPGDEC_DEBUG1); JPEG_WRN("[JPEGDRV] jpeg_drv_dec_soft_reset timeout!! 0x304 = 0x%x, 0x308 = 0x%x, 0x30c = 0x%x, 0x310 = 0x%x\n", REG_JPGDEC_SMI_DEBUG0, REG_JPGDEC_SMI_DEBUG1, REG_JPGDEC_SMI_DEBUG2, REG_JPGDEC_SMI_DEBUG3); } } IMG_REG_WRITE(0x00, REG_ADDR_JPGDEC_RESET); //REG_JPGDEC_RESET = 0x00; IMG_REG_WRITE(0x10, REG_ADDR_JPGDEC_RESET); //REG_JPGDEC_RESET = 0x01; //REG_JPGDEC_RESET = 0x00; _jpeg_dec_int_status = 0; _jpeg_dec_mode = 0; }
// set q table for each component void jpeg_drv_dec_set_q_table(kal_uint32 id0, kal_uint32 id1, kal_uint32 id2) { unsigned int u4Value; u4Value = ((id0&0x0f) << 8) | ((id1&0x0f) << 4) | ((id2&0x0f) << 0); IMG_REG_WRITE((u4Value), REG_ADDR_JPGDEC_QT_ID ); #ifdef DUMP_REG_CMD JPEG_WRN("WriteREG(VLD_REG_OFST , 32'h%08x);\n", ((id0&0x0f) << 8) | ((id1&0x0f) << 4) | ((id2&0x0f) << 0)); #endif }
void jpeg_drv_dec_set_dec_mode(int i4DecMode) { unsigned int u4Value = i4DecMode; /* 0: full frame, 1: direct couple mode, 2: pause/resume mode, 3: Reserved */ if (u4Value > 0x02) JPEG_WRN("Warning : try to set invalid decode mode, %d!!\n", u4Value); IMG_REG_WRITE((u4Value & 0x03), REG_ADDR_JPGDEC_OPERATION_MODE); }
static int jpeg_open(struct inode *inode, struct file *file) { unsigned int *pStatus; //Allocate and initialize private data file->private_data = kmalloc(sizeof(unsigned int) , GFP_ATOMIC); if(NULL == file->private_data) { JPEG_WRN("Not enough entry for JPEG open operation\n"); return -ENOMEM; } pStatus = (unsigned int *)file->private_data; *pStatus = 0; return 0; }
static int jpeg_enc_ioctl(unsigned int cmd, unsigned long arg, struct file *file) { int retValue; //unsigned int decResult; long timeout_jiff; unsigned int file_size, enc_result_code; //unsigned int _jpeg_enc_int_status; unsigned int jpeg_enc_wait_timeout = 0; unsigned int cycle_count; unsigned int ret ; unsigned int *pStatus; //JpegDrvEncParam cfgEnc; JPEG_ENC_DRV_IN cfgEnc; JpegDrvEncResult enc_result; //JpegDrvEncSrcCfg src_cfg; //JpegDrvEncDstCfg dst_cfg; //JpegDrvEncCtrlCfg ctrl_cfg; pStatus = (unsigned int*)file->private_data; if(NULL == pStatus) { JPEG_WRN("Private data is null in flush operation. HOW COULD THIS HAPPEN ??\n"); return -EFAULT; } switch(cmd) { case JPEG_ENC_IOCTL_RW_REG: //jpeg_drv_enc_rw_reg(); break; // initial and reset JPEG encoder case JPEG_ENC_IOCTL_INIT: JPEG_MSG("[JPEGDRV][IOCTL] JPEG Encoder Init!!\n"); retValue = jpeg_drv_enc_init(); if(retValue == 0) { *pStatus = JPEG_ENC_PROCESS; } return retValue; break; case JPEG_ENC_IOCTL_WARM_RESET: JPEG_MSG("[JPEGDRV][IOCTL] JPEG Encoder Warm Reset\n"); enc_result_code = jpeg_drv_enc_warm_reset(); if (0 == enc_result_code) { return -EFAULT; } break; // configure the register case JPEG_ENC_IOCTL_CONFIG: JPEG_MSG("[JPEGDRV][IOCTL] JPEG Encoder Configure Hardware\n"); if(*pStatus != JPEG_ENC_PROCESS) { JPEG_WRN("Permission Denied! This process can not access encoder"); return -EFAULT; } if(enc_status == 0) { JPEG_WRN("Encoder status is available, HOW COULD THIS HAPPEN ??"); *pStatus = 0; return -EFAULT; } // copy input parameters if(copy_from_user(&cfgEnc, (void *)arg, sizeof(JPEG_ENC_DRV_IN))) { JPEG_MSG("[JPEGDRV]JPEG Encoder : Copy from user error\n"); return -EFAULT; } // 0. reset jpeg_drv_enc_reset(); // 1. set src config //memset(&src_cfg, 0, sizeof(JpegDrvEncSrcCfg)); //src_cfg.luma_addr = cfgEnc.srcBufferAddr; //if (cfgEnc.encFormat == NV12 || cfgEnc.encFormat == NV21) //{ // unsigned int srcChromaAddr = cfgEnc.srcChromaAddr; // srcChromaAddr = TO_CEIL(srcChromaAddr, 128); //((srcChromaAddr+127)&~127); // src_cfg.chroma_addr = srcChromaAddr; //} // //src_cfg.width = cfgEnc.encWidth; //src_cfg.height = cfgEnc.encHeight; //src_cfg.yuv_format = cfgEnc.encFormat; // 1. set src config JPEG_MSG("[JPEGDRV]SRC_IMG: %x %x, DU:%x, fmt:%x!!\n", cfgEnc.encWidth, cfgEnc.encHeight, cfgEnc.totalEncDU, cfgEnc.encFormat); ret = jpeg_drv_enc_set_src_image(cfgEnc.encWidth, cfgEnc.encHeight, cfgEnc.encFormat, cfgEnc.totalEncDU) ; if(ret == 0) { JPEG_MSG("[JPEGDRV]JPEG Encoder set srouce image failed\n"); return -EFAULT; } // 2. set src buffer info JPEG_MSG("[JPEGDRV]SRC_BUF: addr %x, %x, stride %x, %x!!\n", cfgEnc.srcBufferAddr, cfgEnc.srcChromaAddr ,cfgEnc.imgStride, cfgEnc.memStride); ret = jpeg_drv_enc_set_src_buf(cfgEnc.encFormat, cfgEnc.imgStride, cfgEnc.memStride, cfgEnc.srcBufferAddr, cfgEnc.srcChromaAddr); if(ret == 0) { JPEG_MSG("[JPEGDRV]JPEG Encoder set srouce buffer failed\n"); return -EFAULT; } //if (0 == jpeg_drv_enc_src_cfg(src_cfg)) //{ // JPEG_MSG("JPEG Encoder src cfg failed\n"); // return -EFAULT; //} // 3. set dst buffer info JPEG_MSG("[JPEGDRV]DST_BUF: addr:%x, size:%x, ofs:%x, mask:%x!!\n",cfgEnc.dstBufferAddr, cfgEnc.dstBufferSize, cfgEnc.dstBufAddrOffset, cfgEnc.dstBufAddrOffsetMask); ret = jpeg_drv_enc_set_dst_buff(cfgEnc.dstBufferAddr, cfgEnc.dstBufferSize, cfgEnc.dstBufAddrOffset, cfgEnc.dstBufAddrOffsetMask); if (ret == 0 ) { JPEG_MSG("[JPEGDRV]JPEG Encoder set dst buffer failed\n"); return -EFAULT; } //memset(&dst_cfg, 0, sizeof(JpegDrvEncDstCfg)); // //dst_cfg.dst_addr = cfgEnc.dstBufferAddr; //dst_cfg.dst_size = cfgEnc.dstBufferSize; //dst_cfg.exif_en = cfgEnc.enableEXIF; // //JPEG_MSG("go L:%d, %x, %d, %d !!", __LINE__, dst_cfg.dst_addr, dst_cfg.dst_size, dst_cfg.file_format); // //if (0 == jpeg_drv_enc_dst_buff(dst_cfg)) // return -EFAULT; // 4 .set ctrl config JPEG_MSG("[JPEGDRV]ENC_CFG: exif:%d, q:%d, DRI:%d !!\n", cfgEnc.enableEXIF, cfgEnc.encQuality, cfgEnc.restartInterval); jpeg_drv_enc_ctrl_cfg(cfgEnc.enableEXIF, cfgEnc.encQuality, cfgEnc.restartInterval); //memset(&ctrl_cfg, 0, sizeof(JpegDrvEncCtrlCfg)); // //ctrl_cfg.quality = cfgEnc.encQuality; //ctrl_cfg.gmc_disable = cfgEnc.disableGMC; //ctrl_cfg.restart_interval = cfgEnc.restartInterval; // break; case JPEG_ENC_IOCTL_START: JPEG_MSG("[JPEGDRV][IOCTL] JPEG Encoder Start!!\n"); if(*pStatus != JPEG_ENC_PROCESS) { JPEG_WRN("Permission Denied! This process can not access encoder"); return -EFAULT; } if(enc_status == 0) { JPEG_WRN("Encoder status is available, HOW COULD THIS HAPPEN ??"); *pStatus = 0; return -EFAULT; } jpeg_drv_enc_start(); break; case JPEG_ENC_IOCTL_WAIT: JPEG_MSG("[JPEGDRV][IOCTL] JPEG Encoder Wait!!\n"); if(*pStatus != JPEG_ENC_PROCESS) { JPEG_WRN("Permission Denied! This process can not access encoder"); return -EFAULT; } if(enc_status == 0) { JPEG_WRN("Encoder status is available, HOW COULD THIS HAPPEN ??"); *pStatus = 0; return -EFAULT; } if(copy_from_user(&enc_result, (void *)arg, sizeof(JpegDrvEncResult))) { JPEG_WRN("JPEG Encoder : Copy from user error\n"); return -EFAULT; } //#ifdef FPGA_VERSION //TODO: ENC_DONE in REG_JPEG_ENC_INTERRUPT_STATUS need to set to 0 after read. jpeg_enc_wait_timeout = 0xFFFFFF; #if 0 do { _jpeg_enc_int_status = REG_JPEG_ENC_INTERRUPT_STATUS; jpeg_enc_wait_timeout--; } while(_jpeg_enc_int_status == 0 && jpeg_enc_wait_timeout > 0); if (jpeg_enc_wait_timeout == 0) JPEG_MSG("JPEG Encoder timeout\n"); ret = jpeg_drv_enc_get_result(&file_size); JPEG_MSG("Result : %d, Size : %u, addres : 0x%x\n", ret, file_size, ioread32(JPG_CODEC_BASE + 0x120)); if(_jpeg_enc_int_status != 1) { jpeg_drv_enc_dump_reg(); } #else //set timeout timeout_jiff = enc_result.timeout* HZ / 1000; JPEG_MSG("[JPEGDRV]JPEG Encoder Time Jiffies : %ld\n", timeout_jiff); if(jpeg_isr_enc_lisr()<0) { wait_event_interruptible_timeout(enc_wait_queue, _jpeg_enc_int_status, timeout_jiff); JPEG_MSG("[JPEGDRV]JPEG Encoder Wait done !!\n"); } else { JPEG_MSG("[JPEGDRV]JPEG Encoder already done !!\n"); } ret = jpeg_drv_enc_get_result(&file_size); JPEG_MSG("[JPEGDRV]Result : %d, Size : %u!!\n", ret, file_size); if(ret != 0) { jpeg_drv_enc_dump_reg(); } #endif cycle_count = jpeg_drv_enc_get_cycle_count(); if(copy_to_user(enc_result.pFileSize, &file_size, sizeof(unsigned int))) { JPEG_MSG("[JPEGDRV]JPEG Encoder : Copy to user error (file size)\n"); return -EFAULT; } if(copy_to_user(enc_result.pResult, &ret, sizeof(unsigned int))) { JPEG_MSG("[JPEGDRV]JPEG Encoder : Copy to user error (status)\n"); return -EFAULT; } if(copy_to_user(enc_result.pCycleCount, &cycle_count, sizeof(unsigned int))) { JPEG_MSG("[JPEGDRV]JPEG Encoder : Copy to user error (cycle)\n"); return -EFAULT; } break; case JPEG_ENC_IOCTL_DEINIT: JPEG_MSG("[JPEGDRV][IOCTL] JPEG Encoder Deinit!!\n"); // copy input parameters if(*pStatus != JPEG_ENC_PROCESS) { JPEG_WRN("Permission Denied! This process can not access encoder"); return -EFAULT; } if(enc_status == 0) { JPEG_WRN("Encoder status is available, HOW COULD THIS HAPPEN ??"); *pStatus = 0; return -EFAULT; } jpeg_drv_enc_deinit(); *pStatus = 0; break; case JPEG_ENC_IOCTL_DUMP_REG: jpeg_drv_enc_dump_reg(); break; default: JPEG_MSG("[JPEGDRV]JPEG ENC IOCTL NO THIS COMMAND\n"); } return 0; }
static int jpeg_dec_ioctl(unsigned int cmd, unsigned long arg, struct file *file) { unsigned int* pStatus; unsigned int decResult; long timeout_jiff; JPEG_DEC_DRV_IN dec_params; JPEG_DEC_CONFIG_ROW dec_row_params ; unsigned int irq_st = 0; //unsigned int timeout = 0x1FFFFF; JPEG_DEC_DRV_OUT outParams; pStatus = (unsigned int*)file->private_data; if (NULL == pStatus) { JPEG_MSG("[JPEGDRV]JPEG Decoder: Private data is null in flush operation. SOME THING WRONG??\n"); return -EFAULT; } switch(cmd) { // initial and reset JPEG encoder case JPEG_DEC_IOCTL_INIT: /* OT:OK */ JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Init!!\n"); if(jpeg_drv_dec_init() == 0) { *pStatus = JPEG_DEC_PROCESS; } break; case JPEG_DEC_IOCTL_RESET: /* OT:OK */ JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Reset!!\n"); jpeg_drv_dec_reset(); break; case JPEG_DEC_IOCTL_CONFIG: JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Configration!!\n"); if(*pStatus != JPEG_DEC_PROCESS) { JPEG_MSG("[JPEGDRV]Permission Denied! This process can not access decoder\n"); return -EFAULT; } if(dec_status == 0) { JPEG_MSG("[JPEGDRV]JPEG Decoder is unlocked!!"); *pStatus = 0; return -EFAULT; } if(copy_from_user(&dec_params, (void *)arg, sizeof(JPEG_DEC_DRV_IN))) { JPEG_MSG("[JPEGDRV]JPEG Decoder : Copy from user error\n"); return -EFAULT; } //_jpeg_dec_dump_reg_en = dec_params.regDecDumpEn; if(dec_params.decodeMode == JPEG_DEC_MODE_MCU_ROW) _jpeg_dec_mode = 1; else _jpeg_dec_mode = 0; if (jpeg_drv_dec_set_config_data(&dec_params) < 0) return -EFAULT; break; case JPEG_DEC_IOCTL_RESUME: if(*pStatus != JPEG_DEC_PROCESS) { JPEG_MSG("[JPEGDRV]Permission Denied! This process can not access decoder\n"); return -EFAULT; } if(dec_status == 0) { JPEG_MSG("[JPEGDRV]JPEG Decoder is unlocked!!"); *pStatus = 0; return -EFAULT; } if(copy_from_user(&dec_row_params, (void *)arg, sizeof(JPEG_DEC_CONFIG_ROW))) { JPEG_MSG("[JPEGDRV]JPEG Decoder : Copy from user error\n"); return -EFAULT; } JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Resume, [%d] %x %x %x !!\n", dec_row_params.pauseMCU -1,dec_row_params.decRowBuf[0], dec_row_params.decRowBuf[1], dec_row_params.decRowBuf[2]); jpeg_drv_dec_set_dst_bank0( dec_row_params.decRowBuf[0], dec_row_params.decRowBuf[1], dec_row_params.decRowBuf[2]); jpeg_drv_dec_set_pause_mcu_idx(dec_row_params.pauseMCU -1) ; jpeg_drv_dec_resume(BIT_INQST_MASK_PAUSE); break; case JPEG_DEC_IOCTL_START: /* OT:OK */ JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Start!!\n"); //Debug: printk("0xF0: 0x%08x\n", *(volatile unsigned int*)(JPEG_DEC_BASE + 0xF0)); jpeg_drv_dec_start(); break; case JPEG_DEC_IOCTL_WAIT: if(*pStatus != JPEG_DEC_PROCESS) { JPEG_WRN("Permission Denied! This process can not access decoder"); return -EFAULT; } if(dec_status == 0) { JPEG_WRN("Decoder status is available, HOW COULD THIS HAPPEN ??"); *pStatus = 0; return -EFAULT; } if(copy_from_user(&outParams, (void *)arg, sizeof(JPEG_DEC_DRV_OUT))) { JPEG_WRN("JPEG Decoder : Copy from user error\n"); return -EFAULT; } //set timeout timeout_jiff = outParams.timeout* HZ / 1000; //JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Wait Resume Time Jiffies : %ld\n", timeout_jiff); #ifdef FPGA_VERSION //#if 1 JPEG_MSG("[JPEGDRV]Polling JPEG Status"); do { _jpeg_dec_int_status = REG_JPGDEC_INTERRUPT_STATUS; } while(_jpeg_dec_int_status == 0); #else //if(outParams.timeout >= 5000){ // // JPEG_MSG("Polling JPEG Status"); // do // { // _jpeg_dec_int_status = REG_JPGDEC_INTERRUPT_STATUS; // timeout--; // } while(_jpeg_dec_int_status == 0 && timeout != 0); // if(timeout == 0) JPEG_MSG("Polling JPEG Status TIMEOUT!!\n"); //}else if(jpeg_isr_dec_lisr()<0) { //JPEG_MSG("wait JPEG irq\n"); wait_event_interruptible_timeout(dec_wait_queue, _jpeg_dec_int_status, timeout_jiff); JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Enter IRQ Wait Done!!\n"); //printk("[JPEGDRV]wait JPEG irq done\n"); } else { JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Enter IRQ Wait Already Done!!\n"); //printk("[JPEGDRV]JPEG decoder already done\n"); } #endif decResult = jpeg_drv_dec_get_result(); //jpeg_drv_dec_dump_key_reg(); if(decResult >= 2) { JPEG_MSG("[JPEGDRV]Decode Result : %d, status %x!\n", decResult, _jpeg_dec_int_status ); jpeg_drv_dec_dump_key_reg(); //jpeg_drv_dec_dump_reg(); jpeg_drv_dec_reset(); } irq_st = _jpeg_dec_int_status ; decResult = decResult | (irq_st<<8) ; _jpeg_dec_int_status = 0; if(copy_to_user(outParams.result, &decResult, sizeof(unsigned int))) { JPEG_WRN("JPEG Decoder : Copy to user error (result)\n"); return -EFAULT; } break; case JPEG_DEC_IOCTL_BREAK: if (jpeg_drv_dec_break() < 0) return -EFAULT; break; case JPEG_DEC_IOCTL_DUMP_REG: JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder DUMP REGISTER !!\n"); jpeg_drv_dec_dump_reg(); break; case JPEG_DEC_IOCTL_DEINIT: JPEG_MSG("[JPEGDRV][IOCTL] JPEG Decoder Deinit !!\n"); // copy input parameters if(*pStatus != JPEG_DEC_PROCESS) { JPEG_ERR("Permission Denied! This process can not access encoder"); return -EFAULT; } if(dec_status == 0) { JPEG_ERR("Encoder status is available, HOW COULD THIS HAPPEN ??"); *pStatus = 0; return -EFAULT; } jpeg_drv_dec_deinit(); *pStatus = 0; break; #ifdef FOR_COMPILE case JPEG_DEC_IOCTL_RW_REG: /* OT:OK */ jpeg_drv_dec_rw_reg(); break; #endif default: JPEG_ERR("JPEG DEC IOCTL NO THIS COMMAND\n"); break; } return 0; }
void jpeg_drv_dec_dump_key_reg(void) { unsigned int reg_value = 0; unsigned int index = 0; JPEG_WRN("<<<<<= JPEG DEC DUMP KEY =>>>>>\n"); //bank0, bank1 address for(index = 0x140; index <= 0x154 ; index += 4) { IMG_REG_READ(reg_value, JPEG_DEC_BASE + index); //reg_value = ioread32(JPEG_DEC_BASE + index); JPEG_WRN("@0x%x(%d) 0x%08x\n", index, index/4, reg_value); wait_pr(); } //pause index for(index = 0x170; index <= 0x170 ; index += 4){ IMG_REG_READ(reg_value, JPEG_DEC_BASE + index); //reg_value = ioread32(JPEG_DEC_BASE + index); JPEG_WRN("@0x%x(%d) 0x%08x\n", index, index/4, reg_value); wait_pr(); } // decode mode (0x17C) // debug (0x180) for(index = 0x17C; index <= 0x180 ; index += 4){ IMG_REG_READ(reg_value, JPEG_DEC_BASE + index); //reg_value = ioread32(JPEG_DEC_BASE + index); JPEG_WRN("@0x%x(%d) 0x%08x\n", index, index/4, reg_value); wait_pr(); } // RDMA addr (0x200) for(index = 0x200; index <= 0x200 ; index += 4){ IMG_REG_READ(reg_value, JPEG_DEC_BASE + index); //reg_value = ioread32(JPEG_DEC_BASE + index); JPEG_WRN("@0x%x(%d) 0x%08x\n", index, index/4, reg_value); wait_pr(); } // total MCU (0x210) for(index = 0x210; index <= 0x210 ; index += 4){ IMG_REG_READ(reg_value, JPEG_DEC_BASE + index); //reg_value = ioread32(JPEG_DEC_BASE + index); JPEG_WRN("@0x%x(%d) 0x%08x\n", index, index/4, reg_value); wait_pr(); } // file BRP addr (0x248) // file size (0x24C) for(index = 0x248; index <= 0x24C ; index += 4){ IMG_REG_READ(reg_value, JPEG_DEC_BASE + index); //reg_value = ioread32(JPEG_DEC_BASE + index); JPEG_WRN("@0x%x(%d) 0x%08x\n", index, index/4, reg_value); wait_pr(); } //IRQ (0x274) //IRQ FSM (0x278) for(index = 0x274; index <= 0x278 ; index += 4){ IMG_REG_READ(reg_value, JPEG_DEC_BASE + index); //reg_value = ioread32(JPEG_DEC_BASE + index); JPEG_WRN("@0x%x(%d) 0x%08x\n", index, index/4, reg_value); wait_pr(); } //MCU CNT (0x294) for(index = 0x294; index <= 0x294 ; index += 4){ IMG_REG_READ(reg_value, JPEG_DEC_BASE + index); //reg_value = ioread32(JPEG_DEC_BASE + index); JPEG_WRN("@0x%x(%d) 0x%08x\n", index, index/4, reg_value); wait_pr(); } }
static int jpeg_enc_ioctl(unsigned int cmd, unsigned long arg, struct file *file) { int retValue; long timeout_jiff; unsigned int fileSize, encResult; JPEG_ENC_DRV_IN inParams; JPEG_ENC_DRV_OUT outParams; unsigned int *pStatus; pStatus = (unsigned int*)file->private_data; if(NULL == pStatus) { JPEG_WRN("Private data is null in flush operation. HOW COULD THIS HAPPEN ??\n"); return -EFAULT; } switch(cmd) { // initial and reset JPEG encoder case JPEG_ENC_IOCTL_INIT: JPEG_MSG("JPEG Encoder Initial and Lock\n"); retValue = jpeg_drv_enc_init(); if(retValue == 0) { *pStatus = JPEG_ENC_PROCESS; } return retValue; break; // Configure the register case JPEG_ENC_IOCTL_CONFIG: JPEG_MSG("JPEG Encoder Configure Hardware\n"); if(*pStatus != JPEG_ENC_PROCESS) { JPEG_WRN("Permission Denied! This process can not access encoder"); return -EFAULT; } if(enc_status == 0) { JPEG_WRN("Encoder status is available, HOW COULD THIS HAPPEN ??"); *pStatus = 0; return -EFAULT; } // copy input parameters if(copy_from_user(&inParams, (void *)arg, sizeof(JPEG_ENC_DRV_IN))) { JPEG_WRN("JPEG Encoder : Copy from user error\n"); return -EFAULT; } if(inParams.allocBuffer) { dstBufferSize = inParams.dstBufferSize; dstUserVA = inParams.dstBufferAddr; dstBufferVA = dma_alloc_coherent(0, dstBufferSize, &dstBufferPA, GFP_KERNEL); } else { dstBufferSize = 0; dstBufferPA = (unsigned int)inParams.dstBufferAddr; } JPEG_MSG("JPEG Encoder Buffer Address : %d\n", (unsigned int)inParams.dstBufferAddr); JPEG_MSG("JPEG Encoder Buffer Size : %d\n", inParams.dstBufferSize); JPEG_MSG("JPEG Encoder Buffer Width : %d\n", inParams.dstWidth); JPEG_MSG("JPEG Encoder Buffer Height : %d\n", inParams.dstHeight); JPEG_MSG("JPEG Encoder Buffer Format : %d\n", inParams.dstFormat); JPEG_MSG("JPEG Encoder Buffer Quality : %d\n", inParams.dstQuality); // 0. reset jpeg_drv_enc_reset(); // 1. set dst address jpeg_drv_enc_set_dst_buffer_info(dstBufferPA, inParams.dstBufferSize, 0); // 2. set file format jpeg_drv_enc_set_file_format(inParams.enableEXIF); // 3. set quality jpeg_drv_enc_set_quality(inParams.dstQuality); // 4. single run jpeg_drv_enc_set_mode(0, 0); // 5. set sampling factor if(jpeg_drv_enc_set_sample_format_related(inParams.dstWidth, inParams.dstHeight, inParams.dstFormat)) { JPEG_WRN("JPEG Encoder : Unvalid YUV Format\n"); jpeg_drv_enc_deinit(); return -EINVAL; } // 6. set sync reset bit jpeg_drv_enc_set_sync_reset(inParams.enableSyncReset); break; case JPEG_ENC_IOCTL_START: JPEG_MSG("JPEG Encoder Start\n"); if(*pStatus != JPEG_ENC_PROCESS) { JPEG_WRN("Permission Denied! This process can not access encoder"); return -EFAULT; } if(enc_status == 0) { JPEG_WRN("Encoder status is available, HOW COULD THIS HAPPEN ??"); *pStatus = 0; return -EFAULT; } //jpeg_reg_dump(); jpeg_drv_enc_start(); break; case JPEG_ENC_IOCTL_WAIT: if(*pStatus != JPEG_ENC_PROCESS) { JPEG_WRN("Permission Denied! This process can not access encoder"); return -EFAULT; } if(enc_status == 0) { JPEG_WRN("Encoder status is available, HOW COULD THIS HAPPEN ??"); *pStatus = 0; return -EFAULT; } if(copy_from_user(&outParams, (void *)arg, sizeof(JPEG_ENC_DRV_OUT))) { JPEG_WRN("JPEG Encoder : Copy from user error\n"); return -EFAULT; } #ifdef FPGA_VERSION JPEG_MSG("Polling JPEG Encoder Status"); do { _jpeg_enc_int_status = REG_JPEG_ENC_INTERRUPT_STATUS; } while(_jpeg_enc_int_status == 0); #else //set timeout timeout_jiff = outParams.timeout* HZ / 1000; JPEG_MSG("JPEG Encoder Time Jiffies : %ld\n", timeout_jiff); wait_event_interruptible_timeout(enc_wait_queue, _jpeg_enc_int_status, timeout_jiff); #endif encResult = jpeg_drv_enc_get_result(&fileSize); JPEG_MSG("Result : %d, Size : %u, addres : 0x%x\n", encResult, fileSize, ioread32(JPG_CODEC_BASE + 0x120)); if(encResult != 0) { jpeg_reg_dump(); } if(copy_to_user(outParams.fileSize, &fileSize, sizeof(unsigned int))) { JPEG_WRN("JPEG Encoder : Copy to user error (file size)\n"); return -EFAULT; } if(copy_to_user(outParams.result, &encResult, sizeof(unsigned int))) { JPEG_WRN("JPEG Encoder : Copy to user error (result)\n"); return -EFAULT; } if(dstBufferSize != 0) { JPEG_MSG("Copy Data to User\n"); if(copy_to_user(dstUserVA, dstBufferVA, fileSize)) { JPEG_WRN("JPEG Encoder : Copy to user error (dstbuffer)\n"); return -EFAULT; } dma_free_coherent(0, dstBufferSize, dstBufferVA, dstBufferPA); } break; case JPEG_ENC_IOCTL_DEINIT: // copy input parameters if(*pStatus != JPEG_ENC_PROCESS) { JPEG_WRN("Permission Denied! This process can not access encoder"); return -EFAULT; } if(enc_status == 0) { JPEG_WRN("Encoder status is available, HOW COULD THIS HAPPEN ??"); *pStatus = 0; return -EFAULT; } jpeg_drv_enc_deinit(); *pStatus = 0; return 0; } return 0; }
static int jpeg_dec_ioctl(unsigned int cmd, unsigned long arg, struct file *file) { int retValue; unsigned int decResult, i; long timeout_jiff; JPEG_DEC_DRV_IN inParams; JPEG_DEC_DRV_OUT outParams; unsigned int *pStatus; unsigned int samplingFormat; unsigned int check_dec_addr = 0; unsigned int check_end_addr = 0; pStatus = (unsigned int*)file->private_data; if(NULL == pStatus) { JPEG_WRN("Private data is null in flush operation. HOW COULD THIS HAPPEN ??\n"); return -EFAULT; } switch(cmd) { case JPEG_DEC_IOCTL_INIT: JPEG_MSG("JPEG Decoder Initial and Lock\n"); retValue = jpeg_drv_dec_init(); if(retValue != 0) { return -EBUSY; } dec_src_va = 0; dec_src_pa = 0; table_buffer_va = 0; table_buffer_pa = 0; *pStatus = JPEG_DEC_PROCESS; break; case JPEG_DEC_IOCTL_CONFIG: JPEG_MSG("JPEG Decoder Configure Hardware\n"); if(*pStatus != JPEG_DEC_PROCESS) { JPEG_WRN("Permission Denied! This process can not access decoder"); return -EFAULT; } if(dec_status == 0) { JPEG_WRN("Decoder status is available, HOW COULD THIS HAPPEN ??"); *pStatus = 0; return -EFAULT; } // copy input parameters if(copy_from_user(&inParams, (void *)arg, sizeof(JPEG_DEC_DRV_IN))) { JPEG_WRN("JPEG Decoder : Copy from user error\n"); return -EFAULT; } JPEG_MSG("JPEG Decoder src addr : 0x%x\n", inParams.srcStreamAddr); JPEG_MSG("JPEG Decoder src Size : %d\n", inParams.srcStreamSize); JPEG_MSG("JPEG Decoder src format : %d\n", inParams.samplingFormat); JPEG_MSG("JPEG Decoder mcu row : %d\n", inParams.mcuRow); JPEG_MSG("JPEG Decoder mcu column : %d\n", inParams.mcuColumn); dec_src_size = inParams.srcStreamSize; //now_size = inParams.srcStreamSize; dec_src_va = 0; dec_src_pa = inParams.srcStreamAddr; // 0. reset jpeg_drv_dec_reset(); // 1. set source address jpeg_drv_dec_set_file_buffer(dec_src_pa , dec_src_size); // 2. set table address #ifdef USE_SYSRAM //table_buffer_pa = alloc_internal_sram(INTERNAL_SRAM_JPEG_DECODER, 4096, 2048); //table_buffer_pa = MTxxx_SYSRAM_ALLOC(ESysramUser_JPEG_CODEC, TABLE_SIZE, 2048); table_buffer_pa = inParams.table_addr; #else table_buffer_va = dma_alloc_coherent(0, TABLE_SIZE, &table_buffer_pa, GFP_KERNEL); #endif if(table_buffer_pa == 0) { JPEG_WRN("JPEG Decoder : table pa == 0!!!\n"); return -EFAULT; } jpeg_drv_dec_set_table_address(table_buffer_pa); // 3. set sampling factor samplingFormat = inParams.samplingFormat; if(samplingFormat == 422 && inParams.vSamplingFactor[0] == 2) { samplingFormat = 421; } if(1 != jpeg_drv_dec_set_sampling_factor_related(samplingFormat)) { JPEG_WRN("JPEG Decoder : Sampling Factor Unsupported!!!\n"); return -EFAULT; } // 4. set component id if(inParams.componentNum == 1) { jpeg_drv_dec_set_component_id(inParams.componentID[0], 0, 0); } else { jpeg_drv_dec_set_component_id(inParams.componentID[0], inParams.componentID[1], inParams.componentID[2]); } // 5. set tatal mcu number jpeg_drv_dec_set_total_mcu(inParams.mcuRow * inParams.mcuColumn); // set mcu number per row //jpeg_drv_dec_set_mcu_per_row(); // 6. set each DU for(i = 0 ; i < inParams.componentNum ; i++) { jpeg_drv_dec_set_du(i, inParams.totalDU[i], inParams.dummyDU[i], inParams.duPerMCURow[i]); } // 7. set file size jpeg_drv_dec_set_file_size(dec_src_size + 16); // 8. set Q-table id if(inParams.componentNum == 1) { jpeg_drv_dec_set_q_table_id(inParams.qTableSelector[0], 0, 0); } else { jpeg_drv_dec_set_q_table_id(inParams.qTableSelector[0], inParams.qTableSelector[1], inParams.qTableSelector[2]); } break; case JPEG_DEC_IOCTL_START: // copy input parameters JPEG_MSG("JPEG Decoder : JPEG_DEC_IOCTL_START\n"); if(*pStatus != JPEG_DEC_PROCESS) { JPEG_WRN("Permission Denied! This process can not access decoder"); return -EFAULT; } if(dec_status == 0) { JPEG_WRN("Decoder status is available, HOW COULD THIS HAPPEN ??"); *pStatus = 0; return -EFAULT; } // jpeg_reg_dump(); jpeg_drv_dec_start(); return 0; case JPEG_DEC_IOCTL_WAIT: if(*pStatus != JPEG_DEC_PROCESS) { JPEG_WRN("Permission Denied! This process can not access decoder"); return -EFAULT; } if(dec_status == 0) { JPEG_WRN("Decoder status is available, HOW COULD THIS HAPPEN ??"); *pStatus = 0; return -EFAULT; } if(copy_from_user(&outParams, (void *)arg, sizeof(JPEG_DEC_DRV_OUT))) { JPEG_WRN("JPEG Decoder : Copy from user error\n"); return -EFAULT; } //set timeout timeout_jiff = outParams.timeout* HZ / 1000; JPEG_MSG("JPEG Decoder Time Jiffies : %ld\n", timeout_jiff); #ifdef FPGA_VERSION JPEG_MSG("Polling JPEG Status"); do { _jpeg_dec_int_status = REG_JPEG_DEC_INTERRUPT_STATUS; } while(_jpeg_dec_int_status == 0); #else wait_event_interruptible_timeout(dec_wait_queue, _jpeg_dec_int_status, timeout_jiff); #endif decResult = jpeg_drv_dec_get_result(); _jpeg_dec_int_status = 0; #ifndef USE_SYSRAM if(table_buffer_va != 0) { dma_free_coherent(0, TABLE_SIZE, table_buffer_va, table_buffer_pa); table_buffer_va = 0; } #endif #if 1 check_dec_addr = ioread32(JPG_CODEC_BASE + 0x00); check_end_addr = ioread32(JPG_CODEC_BASE + 0x4C); #endif JPEG_MSG("Decode Result : %d, dec_addr %x, f_s %x!\n", decResult, check_dec_addr, check_end_addr); if(decResult != 0) { jpeg_reg_dump(); } if(copy_to_user(outParams.result, &decResult, sizeof(unsigned int))) { JPEG_WRN("JPEG Decoder : Copy to user error (result)\n"); return -EFAULT; } break; case JPEG_DEC_IOCTL_DEINIT: // copy input parameters if(*pStatus != JPEG_DEC_PROCESS) { JPEG_WRN("Permission Denied! This process can not access decoder"); return -EFAULT; } if(dec_status == 0) { JPEG_WRN("Decoder status is available, HOW COULD THIS HAPPEN ??"); *pStatus = 0; return -EFAULT; } jpeg_drv_dec_deinit(); *pStatus = 0; break; } return 0; }