static int jpeg_drv_dec_init(void) { int retValue; spin_lock(&jpeg_dec_lock); if(dec_status != 0) { JPEG_WRN("JPEG Decoder is busy\n"); retValue = -EBUSY; } else { dec_status = 1; retValue = 0; } spin_unlock(&jpeg_dec_lock); if(retValue == 0) { jpeg_drv_dec_power_on(); jpeg_drv_dec_reset(); } return retValue; }
static void jpeg_drv_dec_deinit(void) { if(dec_status != 0) { spin_lock(&jpeg_dec_lock); dec_status = 0; spin_unlock(&jpeg_dec_lock); jpeg_drv_dec_reset(); jpeg_drv_dec_power_off(); } }
static void jpeg_drv_dec_deinit(void) { if(dec_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 spin_lock(&jpeg_dec_lock); dec_status = 0; spin_unlock(&jpeg_dec_lock); jpeg_drv_dec_reset(); jpeg_drv_dec_power_off(); } }
static void jpeg_drv_dec_deinit(void) { if(dec_status != 0) { #ifdef USE_SYSRAM if(table_buffer_pa != 0) { MT6573_SYSRAM_FREE(MT6573SYSRAMUSR_JPGDECODER); table_buffer_pa = 0; } #else if(table_buffer_va != 0) { dma_free_coherent(0, TABLE_SIZE, table_buffer_va, table_buffer_pa); table_buffer_va = 0; } #endif spin_lock(&jpeg_dec_lock); dec_status = 0; spin_unlock(&jpeg_dec_lock); jpeg_drv_dec_reset(); jpeg_drv_dec_power_off(); } }
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; }
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; }