static int s3c_jpeg_release(struct inode *inode, struct file *file) { DWORD ret; S3C6400_JPG_CTX *JPGRegCtx; JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_release", "JPG_Close\n"); ret = LockJPGMutex(); if(!ret){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_release", "DD::JPG Mutex Lock Fail\r\n"); return FALSE; } JPGRegCtx = (S3C6400_JPG_CTX *)file->private_data; if(!JPGRegCtx){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_release", "DD::JPG Invalid Input Handle\r\n"); return FALSE; } if((--instanceNo) < 0) instanceNo = 0; kfree(JPGRegCtx); UnlockJPGMutex(); clk_jpeg_disable(); #ifdef USE_JPEG_DOMAIN_GATING regulator_disable(jpeg_domain); #endif /* USE_JPEG_DOMAIN_GATING */ return 0; }
static void __exit s3c_jpeg_exit(void) { DWORD ret; JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_exit", "JPG_Deinit\n"); ret = LockJPGMutex(); if(!ret){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_exit", "DD::JPG Mutex Lock Fail\r\n"); } JPGMemFree(&JPGMem); UnlockJPGMutex(); DeleteJPGMutex(); platform_driver_unregister(&s3c_jpeg_driver); printk("S3C JPEG driver module exit\n"); }
/*---------------------------------------------------------------------------- *Function: JPGMemMapping *Parameters: dwContext : *Return Value: True/False *Implementation Notes: JPG register mapping from physical addr to virtual addr -----------------------------------------------------------------------------*/ BOOL JPGMemMapping(S3C6400_JPG_CTX *base) { // JPG HOST Register base->v_pJPG_REG = (volatile S3C6400_JPG_HOSTIF_REG *)Phy2VirAddr(JPG_REG_BASE_ADDR, sizeof(S3C6400_JPG_HOSTIF_REG)); if (base->v_pJPG_REG == NULL) { JPEG_LOG_MSG(LOG_ERROR, "JPGMemMapping", "DD::v_pJPG_REG: VirtualAlloc failed!\r\n"); return FALSE; } return TRUE; }
void *MemAlloc(unsigned int size) { void *alloc_mem; alloc_mem = (void *)kmalloc((int)size, GFP_KERNEL); if (alloc_mem == NULL) { JPEG_LOG_MSG(LOG_ERROR, "Mem_Alloc", "memory allocation failed!\r\n"); return NULL; } return alloc_mem; }
/*---------------------------------------------------------------------------- *Function: Phy2VirAddr *Parameters: dwContext : *Return Value: True/False *Implementation Notes: memory mapping from physical addr to virtual addr -----------------------------------------------------------------------------*/ void *Phy2VirAddr(UINT32 phy_addr, int mem_size) { void *reserved_mem; reserved_mem = (void *)ioremap( (unsigned long)phy_addr, (int)mem_size ); if (reserved_mem == NULL) { JPEG_LOG_MSG(LOG_ERROR, "Phy2VirAddr", "DD::Phyical to virtual memory mapping was failed!\r\n"); return NULL; } return reserved_mem; }
static int s3c_jpeg_open(struct inode *inode, struct file *file) { S3C6400_JPG_CTX *JPGRegCtx; DWORD ret; #ifdef USE_JPEG_DOMAIN_GATING regulator_enable(jpeg_domain); #endif /* USE_JPEG_DOMAIN_GATING */ clk_jpeg_enable(); JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_open", "JPG_open \r\n"); ret = LockJPGMutex(); if(!ret){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_open", "DD::JPG Mutex Lock Fail\r\n"); UnlockJPGMutex(); return FALSE; } JPGRegCtx = (S3C6400_JPG_CTX *)MemAlloc(sizeof(S3C6400_JPG_CTX)); memset(JPGRegCtx, 0x00, sizeof(S3C6400_JPG_CTX)); JPGRegCtx->v_pJPG_REG = JPGMem.v_pJPG_REG; if (instanceNo > MAX_INSTANCE_NUM){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_open", "DD::Instance Number error-JPEG is running, instance number is %d\n", instanceNo); UnlockJPGMutex(); return FALSE; } instanceNo++; UnlockJPGMutex(); file->private_data = (S3C6400_JPG_CTX *)JPGRegCtx; return 0; }
static int s3c_jpeg_probe(struct platform_device *pdev) { struct resource *res; static int size; static int ret; HANDLE h_Mutex; #ifdef USE_JPEG_DOMAIN_GATING jpeg_domain = regulator_get(&pdev->dev, "pd"); if (IS_ERR(jpeg_domain)) { printk(KERN_ERR "failed to get power domain regulator\n"); return -ENOENT; } regulator_enable(jpeg_domain); #endif /* USE_JPEG_DOMAIN_GATING */ // JPEG clock enable jpeg_hclk = clk_get(NULL, "jpeg_hclk"); if (IS_ERR(jpeg_hclk)) { printk(KERN_ERR "failed to get jpeg hclk source\n"); return -ENOENT; } // JPEG clock enable jpeg_sclk = clk_get(NULL, "jpeg"); if (IS_ERR(jpeg_sclk)) { printk(KERN_ERR "failed to get jpeg sclk source\n"); return -ENOENT; } clk_jpeg_enable(); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (res == NULL) { printk(KERN_INFO "failed to get memory region resouce\n"); return -ENOENT; } size = (res->end-res->start)+1; jpeg_mem = request_mem_region(res->start, size, pdev->name); if (jpeg_mem == NULL) { printk(KERN_INFO "failed to get memory region\n"); return -ENOENT; } res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (res == NULL) { printk(KERN_INFO "failed to get irq resource\n"); return -ENOENT; } irq_no = res->start; ret = request_irq(res->start, s3c_jpeg_irq, 0, pdev->name, pdev); if (ret != 0) { printk(KERN_INFO "failed to install irq (%d)\n", ret); return ret; } jpeg_base = ioremap(res->start, size); if (jpeg_base == 0) { printk(KERN_INFO "failed to ioremap() region\n"); return -EINVAL; } // Set JPEG clock to 66 MHz clk_set_rate(jpeg_sclk, 66 * 1000 * 1000); JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_probe", "JPG_Init\n"); // Mutex initialization h_Mutex = CreateJPGmutex(); if (h_Mutex == NULL) { JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_probe", "DD::JPG Mutex Initialize error\r\n"); return FALSE; } ret = LockJPGMutex(); if (!ret){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_probe", "DD::JPG Mutex Lock Fail\n"); return FALSE; } // Memory initialization if( !JPGMemMapping(&JPGMem) ){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_probe", "DD::JPEG-HOST-MEMORY Initialize error\r\n"); UnlockJPGMutex(); return FALSE; } /* else { if (!JPGBuffMapping(&JPGMem)){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_probe", "DD::JPEG-DATA-MEMORY Initialize error : %d\n"); UnlockJPGMutex(); return FALSE; } }*/ instanceNo = 0; UnlockJPGMutex(); ret = misc_register(&s3c_jpeg_miscdev); clk_jpeg_disable(); #ifdef USE_JPEG_DOMAIN_GATING regulator_disable(jpeg_domain); #endif /* USE_JPEG_DOMAIN_GATING */ return 0; }
static long s3c_jpeg_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { S3C6400_JPG_CTX *JPGRegCtx; s3c_jpeg_t *s3c_jpeg_buf; JPG_DEC_PROC_PARAM * DecParam; JPG_ENC_PROC_PARAM * EncParam; BOOL result = TRUE; DWORD ret; ret = LockJPGMutex(); if(!ret){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_ioctl", "DD::JPG Mutex Lock Fail\r\n"); return FALSE; } JPGRegCtx = (S3C6400_JPG_CTX *)file->private_data; if(!JPGRegCtx){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_ioctl", "DD::JPG Invalid Input Handle\r\n"); return FALSE; } switch (cmd) { case IOCTL_JPG_DECODE: JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "IOCTL_JPEG_DECODE\n"); DecParam = (JPG_DEC_PROC_PARAM *)arg; //JPEG_Copy_From_User(&DecParam, (JPG_DEC_PROC_PARAM *)arg, sizeof(JPG_DEC_PROC_PARAM)); // JPGRegCtx->v_pJPGData_Buff = JPGMem.v_pJPGData_Buff; // JPGRegCtx->p_pJPGData_Buff = JPGMem.p_pJPGData_Buff; // JPGRegCtx->v_pYUVData_Buff = JPGMem.v_pYUVData_Buff; // JPGRegCtx->p_pYUVData_Buff = JPGMem.p_pYUVData_Buff; result = decodeJPG(JPGRegCtx, DecParam); JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "width : %d hegiht : %d size : %d\n", DecParam->width, DecParam->height, DecParam->dataSize); //JPEG_Copy_To_User((void *)arg, (void *)&DecParam, sizeof(JPG_DEC_PROC_PARAM)); break; case IOCTL_JPG_ENCODE: JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "IOCTL_JPEG_ENCODE\n"); EncParam = (JPG_ENC_PROC_PARAM *)arg; //JPEG_Copy_From_User(&EncParam, (JPG_ENC_PROC_PARAM *)arg, sizeof(JPG_ENC_PROC_PARAM)); JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "width : %d hegiht : %d\n", EncParam->width, EncParam->height); /* if(EncParam.encType == JPG_MAIN) { JPGRegCtx->v_pJPGData_Buff = JPGMem.v_pJPGData_Buff; JPGRegCtx->p_pJPGData_Buff = JPGMem.p_pJPGData_Buff; JPGRegCtx->v_pYUVData_Buff = JPGMem.v_pYUVData_Buff; JPGRegCtx->p_pYUVData_Buff = JPGMem.p_pYUVData_Buff; } else { JPGRegCtx->v_pJPGData_Buff = JPGMem.frmUserThumbBuf; JPGRegCtx->p_pJPGData_Buff = JPGMem.p_frmUserThumbBuf; JPGRegCtx->v_pYUVData_Buff = JPGMem.strUserThumbBuf; JPGRegCtx->p_pYUVData_Buff = JPGMem.p_strUserThumbBuf; } */ result = encodeJPG(JPGRegCtx, EncParam); JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "encoded file size : %d\n", EncParam->fileSize); //JPEG_Copy_To_User((void *)arg, (void *)&EncParam, sizeof(JPG_ENC_PROC_PARAM)); break; case IOCTL_JPG_SET_STRBUF: s3c_jpeg_buf = (s3c_jpeg_t *)arg; //JPEG_Copy_From_User(&s3c_jpeg_buf, (s3c_jpeg_t *)arg, sizeof(s3c_jpeg_t)); //JPGMem.p_pJPGData_Buff = (unsigned int)s3c_jpeg_buf->phys_addr; //JPGMem.v_pJPGData_Buff = (unsigned char *)s3c_jpeg_buf->virt_addr; JPGRegCtx->p_pJPGData_Buff = (unsigned int) s3c_jpeg_buf->phys_addr; JPGRegCtx->v_pJPGData_Buff = (unsigned char *)s3c_jpeg_buf->virt_addr; JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "IOCTL_JPG_GET_STRBUF\n"); break; case IOCTL_JPG_SET_FRMBUF: s3c_jpeg_buf = (s3c_jpeg_t *)arg; //JPEG_Copy_From_User(s3c_jpeg_buf, (s3c_jpeg_t *)arg, sizeof(s3c_jpeg_t)); //JPGMem.p_pYUVData_Buff = (unsigned int) s3c_jpeg_buf->phys_addr; //JPGMem.v_pYUVData_Buff = (unsigned char *)s3c_jpeg_buf->virt_addr; JPGRegCtx->p_pYUVData_Buff = (unsigned int) s3c_jpeg_buf->phys_addr; JPGRegCtx->v_pYUVData_Buff = (unsigned char *)s3c_jpeg_buf->virt_addr; JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "IOCTL_JPG_GET_FRMBUF\n"); break; case IOCTL_JPG_SET_THUMB_STRBUF: s3c_jpeg_buf = (s3c_jpeg_t *)arg; //JPEG_Copy_From_User(s3c_jpeg_buf, (s3c_jpeg_t *)arg, sizeof(s3c_jpeg_t)); //JPGMem.p_strUserThumbBuf = (unsigned int)s3c_jpeg_buf->phys_addr; //JPGMem.strUserThumbBuf = (unsigned char *)s3c_jpeg_buf->virt_addr; JPGRegCtx->p_strUserThumbBuf = (unsigned int) s3c_jpeg_buf->phys_addr; JPGRegCtx->strUserThumbBuf = (unsigned char *)s3c_jpeg_buf->virt_addr; JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "IOCTL_JPG_GET_STRBUF\n"); break; case IOCTL_JPG_SET_THUMB_FRMBUF: s3c_jpeg_buf = (s3c_jpeg_t *)arg; //JPEG_Copy_From_User(s3c_jpeg_buf, (s3c_jpeg_t *)arg, sizeof(s3c_jpeg_t)); //JPGMem.p_frmUserThumbBuf = (unsigned int)s3c_jpeg_buf->phys_addr; //JPGMem.frmUserThumbBuf = (unsigned char *)s3c_jpeg_buf->virt_addr; JPGRegCtx->p_frmUserThumbBuf = (unsigned int) s3c_jpeg_buf->phys_addr; JPGRegCtx->frmUserThumbBuf = (unsigned char *)s3c_jpeg_buf->virt_addr; JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "IOCTL_JPG_GET_STRBUF\n"); break; default : JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_ioctl", "DD::JPG Invalid ioctl : 0x%X\r\n", cmd); } UnlockJPGMutex(); return result; }