コード例 #1
0
ファイル: s3c-jpeg.c プロジェクト: voku/I5700-kernel-2.6.32.9
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;
}
コード例 #2
0
ファイル: jpgdriver.c プロジェクト: blueskycoco/w7
/*----------------------------------------------------------------------------
*Function: JPG_Init

*Parameters:         dwContext        :
*Return Value:        True/False
*Implementation Notes: Initialize JPEG Hardware
-----------------------------------------------------------------------------*/
DWORD
JPG_Init(
    DWORD dwContext
    )
{
    S3C6410_JPG_CTX *JPGRegCtx;
    HANDLE            h_Mutex;
    DWORD            ret;

    RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_Init().\r\n")));

    // PWM clock Virtual alloc
    s6410PWR = (S3C6410_SYSCON_REG *)Phy2VirAddr(S3C6410_BASE_REG_PA_SYSCON, sizeof(S3C6410_SYSCON_REG));
    if (s6410PWR == NULL)
    {
        RETAILMSG(ZONE_ERROR, (TEXT("JPEG::For s6410PWR: MmMapIoSpace failed!\r\n")));
        return FALSE;;
    }

    hPwrControl = CreateFile( L"PWC0:", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
    if (INVALID_HANDLE_VALUE == hPwrControl )
    {
        RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::PWC0 Open Device Failed\r\n")));
        FreeVirAddr(s6410PWR, sizeof(S3C6410_SYSCON_REG));
        return FALSE;
    }

    if(JPGSetClkDiv(JPG_CLOCK_DIVIDER_RATIO_QUARTER) == FALSE)
    {
        RETAILMSG(ZONE_ERROR, (TEXT("JPEG :: Set Clock Divider Failed\r\n")));
        CloseHandle(hPwrControl);
        FreeVirAddr(s6410PWR, sizeof(S3C6410_SYSCON_REG));
        return FALSE;
    }

    // Mutex initialization
    h_Mutex = CreateJPGmutex();
    if (h_Mutex == NULL)
    {
        RETAILMSG(ZONE_ERROR,(TEXT("JPG_Init:  JJPG Mutex Initialize error : %d\n"),GetLastError()));
        CloseHandle(hPwrControl);
        FreeVirAddr(s6410PWR, sizeof(S3C6410_SYSCON_REG));
        return FALSE;
    }

    ret = LockJPGMutex();
    if(!ret)
    {
        RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::JPG Mutex Lock Fail\r\n")));                        
        DeleteJPGMutex();
        CloseHandle(hPwrControl);
        FreeVirAddr(s6410PWR, sizeof(S3C6410_SYSCON_REG));
        return FALSE;
    }

    // Register/Memory initialization
    JPGRegCtx = (S3C6410_JPG_CTX *)malloc(sizeof(S3C6410_JPG_CTX));
    if (!JPGRegCtx)
    {
        RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::JPG Memory Context Allocation Fail\r\n")));
        UnlockJPGMutex();
        DeleteJPGMutex();
        CloseHandle(hPwrControl);
        FreeVirAddr(s6410PWR, sizeof(S3C6410_SYSCON_REG));
        return FALSE;
    }
    memset(JPGRegCtx, 0x00, sizeof(S3C6410_JPG_CTX));

    if( !JPGMemMapping(JPGRegCtx) )
    {
        RETAILMSG(ZONE_ERROR,(TEXT("JPG_Init:  JPEG-HOST-MEMORY Initialize error : %d\r\n"),GetLastError()));
        free(JPGRegCtx);
        UnlockJPGMutex();
        DeleteJPGMutex();
        CloseHandle(hPwrControl);
        FreeVirAddr(s6410PWR, sizeof(S3C6410_SYSCON_REG));
        return FALSE;
    }
    else
    {
        if(!JPGBuffMapping(JPGRegCtx))
        {
            RETAILMSG(ZONE_ERROR,(TEXT("JPG_Init:  JPEG-DATA-MEMORY Initialize error : %d\r\n"),GetLastError()));
            JPGMemFree(JPGRegCtx);
            free(JPGRegCtx);
            UnlockJPGMutex();
            DeleteJPGMutex();
            CloseHandle(hPwrControl);
            FreeVirAddr(s6410PWR, sizeof(S3C6410_SYSCON_REG));
            return FALSE;
        }
    }

    instanceNo = 0;

    UnlockJPGMutex();
    return (DWORD)JPGRegCtx;
}