⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ovcamerachip.c

📁 ov2640驱动开发
💻 C
字号:
/* 
    ovcamerachip - OmniVsion CAMERACHIP(R) driver

    Copyright (C) 2006, OmniVsion

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
 * OmniVision is a trademark of OmniVision Technologies, Inc. 
 *
 *  Version 1.00   Jun.30.2006   david zhu
 *					      david@ovt.com.cn
 */ 

#include 	<linux/types.h>
#include 	<linux/config.h>
#include	<linux/module.h>
#include	<linux/version.h>
#include	<linux/init.h>
#include	<linux/delay.h>
#include	<linux/ctype.h>

#include	<asm/pgtable.h>
#include	<asm/dma.h>
#include	<asm/irq.h>
#include	<asm/io.h>
#include	<asm/hardware.h>
#include 	<asm/mach-types.h>
#include	<asm/arch/pxa-regs.h>
#include "ci_ov.h"
#include "pxaovcamera.h"
#include "ovcamerachip.h"

#define OV2640
#ifdef OV2640
#include 	"ov2640.h"
extern 	ovcamerachip g_ovcamerachip;
#endif

#define DEBUG

#ifdef DEBUG
#define camerachipprint(fmt,args...) printk(KERN_WARNING "pax-ov-camerachip:" fmt, ## args)
#else
#define camerachipprint(fmt,args...) 
#endif

ovcamera_function_t camerachip_func = {
	.init	= 	camerachip_func_init,
	.deinit	=	camerachip_func_deinit,
	.capture_set_format	= camerachip_func_capture_set_format,
	.capture_start = camerachip_func_capture_start,
	.capture_stop = camerachip_func_capture_stop,
	.command = camerachip_func_command,
	.power_management = camerachip_func_power_management,
};

void ovcamerachip_power_down(int powerdown)
{
	//50 down, 19, rst
	GPDR1 |= GPIO_bit(36);
	GPDR3 |= GPIO_bit(96); 
	
	if ( 1==powerdown )
	{		
		GPSR1 = GPIO_bit(36);	
	}
	else
	{
		// 1 Turn on M_VCC and wait for 20 ms.
		// initilization on Board Level
		// In MiscWrite Reg1(Phys Addr: 0x0800_0080):
		//   Bit 15: CAMERA_ON (1:On  0: Off)
		//   Bit 14: CAMERA_SEL (1:Routed to Camera Interface  0: To SSP1, USIM, PWM1)
	//	MST_MSCWR1 |= (MSCWR1_CAMERA_ON | MSCWR1_CAMERA_SEL);
	//	mdelay(20);
		
		GPCR1 = GPIO_bit(36);
		//GPSR3 = GPIO_bit(96);
		//mdelay(20);
		//GPCR3 = GPIO_bit(96);
		
	}
	mdelay(100);
}

int camerachip_func_init ( p_ovcamera_context_t ovcam_ctx )
{
	int ret;
	
	ovcamerachip *pov=&g_ovcamerachip;
	memset (pov, 0, sizeof(ovcamerachip) );
	camerachipprint("camerachip_func_init ( + ) \n");		

	// Configure CI according to CAMERACHIP's hardware        
	// master parallel with 8 data pins
	ci_set_mode(CI_MODE_MP, CI_DATA_WIDTH8);
	// enable pixel clock(sensor will provide pclock) and master clock = 10075*10000/6MHZ
	ci_set_clock(ovcam_ctx->ui_clk_reg_base, 1, 1, 1679);
	pov->mclock = 100750000/6    ; //Hz
	
	// data sample on rising and h,vsync active high
	ci_set_polarity(0, 0, 0);
	
	//fifo
	ci_set_fifo(0,CI_FIFO_THL_32,1,1);
	
	//sensor power on
	ovcamerachip_power_down(0);
	mdelay(1);


	//Turn on M_CLK using xx MHz and wait for 150 ms.
	ci_enable(1);
	mdelay (150);
		
	//init i2c
	ret = i2c_ovcamerachip_init();
	if ( ret )
	{
		camerachipprint("camerachip_func_init ( -1 ) \n");		
		return ret;
	}
		
	//set sensor type
	ovcam_ctx->sensor_type = 0x2640;
	
	
	//sensor software reset and initialize
	camerachip_ip_init();	
		
	return 0;
}

int camerachip_func_deinit ( p_ovcamera_context_t ovcam_ctx)
{
	
	ovcamerachip_power_down(1);
	i2c_ovcamerachip_cleanup();
	return 0;
}

int camerachip_func_capture_set_format ( p_ovcamera_context_t ovcam_ctx)
{
        CI_MP_TIMING timing;
        int status = -1;
        u32 chipFormat;
        
        // Set the current mode
        switch(ovcam_ctx->cf.in) 
	{
	        case CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR:
	        case CAMERA_IMAGE_FORMAT_YCBCR422_PACKED:
                	chipFormat = OVCAMERACHIP_SFT_YUV422;
                	break;
        	case CAMERA_IMAGE_FORMAT_RGB565:
                	chipFormat = OVCAMERACHIP_SFT_RGB565;
                	break;
                case CAMERA_IMAGE_FORMAT_JPEG:
                	chipFormat = OVCAMERACHIP_SFT_JPEG;
                	break;                	
        	default:
                	printk (KERN_INFO "The Format doesn't support by OV2640 Sensor \n");
			return status;                
        }
        
        status = camerachip_ip_set_format (ovcam_ctx->vw.width,ovcam_ctx->vw.height,chipFormat);
 	if (status)
 	{
		return -1;
	}
	
        return status;
}

int camerachip_func_capture_start ( p_ovcamera_context_t ovcam_ctx, unsigned int frames)
{
	camerachipprint("camerachip_func_capture_start ( + ) \n");	
	g_ovcamerachip.stream = frames>0 ? 1 : 0;
	camerachip_ip_stream_on( );
	camerachipprint("camerachip_func_capture_start ( - ) \n");		
	return 0;
}

int camerachip_func_capture_stop ( p_ovcamera_context_t ovcam_ctx )
{
	camerachipprint("camerachip_func_capture_stop ( + ) \n");		
	camerachip_ip_stream_off( );
	camerachipprint("camerachip_func_capture_stop ( - ) \n");		
	return 0;
}

int camerachip_func_command ( p_ovcamera_context_t ovcam_ctx, unsigned int cmd, void *param)
{
	int ret = 0;
	u8 temp;
	u8 address,value;
	camerachip_protocol_t *p_cp = (camerachip_protocol_t *) param;
	switch (p_cp->cmd)
	{
		case OVCAMCHIP_CMD_REG_GET:		//get register
			address = p_cp->para1;
			ret= ovcamerachip_reg8_read(address,&value);
			p_cp->para2 = ret;
			break;
			
		case OVCAMCHIP_CMD_REG_SET:		//set register
			address = p_cp->para1;
			value = p_cp->para2;
			ret= ovcamerachip_reg8_write(address,value);
			break;
			
		case OVCAMCHIP_CMD_DIGITALZOOM:	//digital continue zoom
			if(p_cp->para1 == OVCAM_PROPERTY_SET)
			{
				temp = p_cp->para2;
				ret = camerachip_ip_zoom(temp);
			}
			p_cp->para2 = g_ovcamerachip.zoom;
			break;		
	
		case OVCAMCHIP_CMD_BRIGHTNESS: //brightness
			if(p_cp->para1 == OVCAM_PROPERTY_SET)
			{
				ret = camerachip_ip_brightness(p_cp->para2);
			};
			p_cp->para2 = g_ovcamerachip.brightness;
			break;
			
		case OVCAMCHIP_CMD_CONTRAST: //contrast
			if(p_cp->para1 == OVCAM_PROPERTY_SET)
			{
				ret = camerachip_ip_contrast(p_cp->para2);
			}
			p_cp->para2 = g_ovcamerachip.contrast;			
			break;
			
		case OVCAMCHIP_CMD_HUE: //hue
			if(p_cp->para1 == OVCAM_PROPERTY_SET)
			{
				ret = camerachip_ip_hue(p_cp->para2);
			};
			p_cp->para2 = g_ovcamerachip.hue;
			break;
			
		case OVCAMCHIP_CMD_SHARPNESS: //sharpness
			if(p_cp->para1 == OVCAM_PROPERTY_SET)
			{
				ret = camerachip_ip_sharpness(p_cp->para2);
			}
			p_cp->para2 = g_ovcamerachip.sharpness;
			break;
			
		case OVCAMCHIP_CMD_SATURATION:  //saturation
			if(p_cp->para1 == OVCAM_PROPERTY_SET)
			{
				ret = camerachip_ip_saturation(p_cp->para2);
			}
			p_cp->para2 = g_ovcamerachip.saturation;
			break;
	
		case OVCAMCHIP_CMD_GAMMA:
			if(p_cp->para1 == OVCAM_PROPERTY_SET)
			{
				temp = p_cp->para2;
				ret = camerachip_ip_gamma(temp);
			}
			p_cp->para2 = g_ovcamerachip.gamma;
			break;
			
		case OVCAMCHIP_CMD_WHITEBALANCE:
			if(p_cp->para1 == OVCAM_PROPERTY_SET)
			{
				ret = camerachip_ip_whitebalance( p_cp->para2);
			}
			p_cp->para2 = g_ovcamerachip.whitebalance;
			break;

		case OVCAMCHIP_CMD_SPECIALEFFECT:
			if(p_cp->para1 == OVCAM_PROPERTY_SET)
			{
				ret = camerachip_ip_specialeffect( p_cp->para2);
			}
			p_cp->para2 = g_ovcamerachip.specialeffect;
			break;
			
		case OVCAMCHIP_CMD_LIGHTFREQUENCY:	
			if(p_cp->para1 == OVCAM_PROPERTY_SET)
			{
				temp = p_cp->para2;
				ret = camerachip_ip_brightness(temp);
			}
			p_cp->para2 = g_ovcamerachip.brightness;
			break;
			
		case OVCAMCHIP_CMD_FRAMERATE:	
			if(p_cp->para1 == OVCAM_PROPERTY_SET)
			{
				temp = p_cp->para2;
				ret = camerachip_ip_framerate(temp);
			}
			p_cp->para2 = g_ovcamerachip.framerate;
			break;
			
		case OVCAMCHIP_CMD_FLIP:			//flip
			if(p_cp->para1 == OVCAM_PROPERTY_SET)
			{
				ret = camerachip_ip_flip(p_cp->para2);
			}
			p_cp->para2 = g_ovcamerachip.flip;
			break;
			
		case OVCAMCHIP_CMD_MIRROR: 		//mirror
			if(p_cp->para1 == OVCAM_PROPERTY_SET)
			{
				ret = camerachip_ip_mirror(p_cp->para2);
			}
			p_cp->para2 = g_ovcamerachip.mirror;
			break;
			
		default:
			break;	
	}
	
	return ret;
}

int camerachip_func_power_management ( p_ovcamera_context_t ovcam_ctx, int suspend )
{

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -