📄 ov7725.c
字号:
else if(scene == DC_VAL_INDOOR) { gpio_i2c_write(I2C_OV7725, 0x13, 0xfd); gpio_i2c_write(I2C_OV7725, 0x01, 0x84); gpio_i2c_write(I2C_OV7725, 0x02, 0x4c); gpio_i2c_write(I2C_OV7725, 0x0e, 0x65); gpio_i2c_write(I2C_OV7725, 0x2d, 0x00); gpio_i2c_write(I2C_OV7725, 0x2e, 0x00); s_s32Scene = DC_VAL_INDOOR; } else if(scene == DC_VAL_MANUAL) { s_s32Scene = DC_VAL_MANUAL; } else { printk("scene_set_error.\n"); return -1; } break; } case DC_SET_POWERFREQ: { unsigned int powerfreq_dy = val; if(powerfreq_dy == DC_VAL_50HZ) { gpio_i2c_write(I2C_OV7725, 0x2b, 0xff); powerfreq = DC_VAL_50HZ; } else if(powerfreq_dy == DC_VAL_60HZ) { gpio_i2c_write(I2C_OV7725, 0x2b, 0x00); powerfreq = DC_VAL_60HZ; } else { printk("powerfreq_set_error.\n"); return -1; } break; } case DC_SET_FLIP: { unsigned int flip = val; regvalue = gpio_sccb_read(I2C_OV7725, 0x0c); if(flip == DC_VAL_ON) { gpio_i2c_write(I2C_OV7725, 0x0c, (regvalue&0x7f)); } else if(flip == DC_VAL_OFF) { gpio_i2c_write(I2C_OV7725, 0x0c, (regvalue|0x80)); } else { printk("flip_set_error.\n"); return -1; } break; } case DC_SET_MIRROR: { unsigned int mirror = val; regvalue = gpio_sccb_read(I2C_OV7725, 0x0c); if(mirror == DC_VAL_ON) { gpio_i2c_write(I2C_OV7725, 0x0c, (regvalue&0xbf)); } else if(mirror == DC_VAL_OFF) { gpio_i2c_write(I2C_OV7725, 0x0c, (regvalue|0x40)); } else { printk("mirror_set_error.\n"); return -1; } break; } case DC_GET_IMAGESIZE: { unsigned int imagesize,dc_size; imagesize = gpio_sccb_read(I2C_OV7725, 0x29); if(imagesize == 0xa0) { dc_size = DC_VAL_VGA; } if(imagesize == 0x50) { dc_size = DC_VAL_QVGA; } if(imagesize == 0x25) { dc_size = DC_VAL_QQVGA; } return copy_to_user(argp, &dc_size, 1)?-EFAULT : 0; } case DC_GET_BRIGHT: { unsigned int birght; birght = gpio_sccb_read(I2C_OV7725, 0x9b); return copy_to_user(argp, &birght, 1)?-EFAULT : 0; } case DC_GET_CONTRACT: { unsigned int contrast; contrast = gpio_sccb_read(I2C_OV7725, 0x9c); return copy_to_user(argp, &contrast, 1)?-EFAULT : 0; } case DC_GET_HUE: { unsigned int hue; hue = gpio_sccb_read(I2C_OV7725, 0xaa); if(hue < 0x80) { hue = !hue; } else { hue = hue - 0x80; } return copy_to_user(argp, &hue, 1)?-EFAULT : 0; } case DC_GET_SATURATION: { unsigned int saturation; saturation = gpio_sccb_read(I2C_OV7725, 0xa7); return copy_to_user(argp, &saturation, 1)?-EFAULT : 0; } case DC_GET_SHARPNESS: { unsigned int sharpness; sharpness = gpio_sccb_read(I2C_OV7725, 0x8f); return copy_to_user(argp, &sharpness, 1)?-EFAULT : 0; } case DC_GET_ADNSWITCH: { unsigned int adnswitch, adnswitch_value; adnswitch = gpio_sccb_read(I2C_OV7725, 0xac); adnswitch = adnswitch&0x40; if(adnswitch == 0x40) { adnswitch_value = DC_VAL_ON; } else { adnswitch_value = DC_VAL_OFF; } return copy_to_user(argp, &adnswitch_value, 1)?-EFAULT : 0; } case DC_GET_DNT: { unsigned int dnt; dnt = gpio_sccb_read(I2C_OV7725, 0x8e); return copy_to_user(argp, &dnt, 1)?-EFAULT : 0; } case DC_GET_AWBSWITCH: { unsigned int awbswitch,awbswitch_value; awbswitch = gpio_sccb_read(I2C_OV7725, 0x13); awbswitch = awbswitch&0x02; if(awbswitch == 0x02) { awbswitch_value = DC_VAL_ON; } else { awbswitch_value = DC_VAL_OFF; } return copy_to_user(argp, &awbswitch_value, 1)?-EFAULT : 0; } case DC_GET_WBR: { unsigned int wbr; gpio_i2c_write(I2C_OV7725, 0x13, 0xfd); wbr = gpio_sccb_read(I2C_OV7725, 0x02); return copy_to_user(argp, &wbr, 1)?-EFAULT : 0; } case DC_GET_WBB: { unsigned int wbb; wbb = gpio_sccb_read(I2C_OV7725, 0x01); return copy_to_user(argp, &wbb, 1)?-EFAULT : 0; } case DC_GET_AECSWITCH: { unsigned int aecswitch,aecswitch_value; aecswitch = gpio_sccb_read(I2C_OV7725, 0x13); aecswitch = aecswitch&0x01; if(aecswitch == 0x01) { aecswitch_value = DC_VAL_ON; } else { aecswitch_value = DC_VAL_OFF; } return copy_to_user(argp, &aecswitch_value, 1)?-EFAULT : 0; } case DC_GET_EC: { unsigned int aecswitch_lower,aecswitch_upper,aecswitch_value; aecswitch_lower = gpio_sccb_read(I2C_OV7725, 0x10); aecswitch_upper = gpio_sccb_read(I2C_OV7725, 0x08); if(aecswitch_lower == 0xff) { aecswitch_value = aecswitch_upper%2 + 0x80; } else { aecswitch_value = aecswitch_lower%2; } return copy_to_user(argp, &aecswitch_value, 1)?-EFAULT : 0; } case DC_GET_AGCSWITCH: { unsigned int agcswitch,agcswitch_value; agcswitch = gpio_sccb_read(I2C_OV7725, 0x13); agcswitch = agcswitch&0x04; if(agcswitch == 0x04) { agcswitch_value = DC_VAL_ON; } else { agcswitch_value = DC_VAL_OFF; } return copy_to_user(argp, &agcswitch_value, 1)?-EFAULT : 0; } case DC_GET_GC: { unsigned int gc; gc = gpio_sccb_read(I2C_OV7725, 0x00); return copy_to_user(argp, &gc, 1)?-EFAULT : 0; } case DC_GET_ABLCSWITCH: { unsigned int ablcswitch,ablcswitch_value; ablcswitch = gpio_sccb_read(I2C_OV7725, 0x3e); ablcswitch = ablcswitch&0x04; if(ablcswitch == 0x04) { ablcswitch_value = DC_VAL_ON; } else { ablcswitch_value = DC_VAL_OFF; } return copy_to_user(argp, &ablcswitch_value, 1)?-EFAULT : 0; } case DC_GET_COLOR: { unsigned int color,color_value; color = gpio_sccb_read(I2C_OV7725, 0x64); color = color&0x10; if(color == 0x10) { color_value = DC_VAL_ON; } else { color_value = DC_VAL_OFF; } return copy_to_user(argp, &color_value, 1)?-EFAULT : 0; } case DC_GET_SCENE: { return copy_to_user(argp, &s_s32Scene, 1)?-EFAULT : 0; } case DC_GET_POWERFREQ: { return copy_to_user(argp, &powerfreq, 1)?-EFAULT : 0; } case DC_GET_FLIP: { unsigned int reg_flip; reg_flip = dc_flip_get(); return copy_to_user(argp, ®_flip, 1)?-EFAULT : 0; } case DC_GET_MIRROR: { unsigned int reg_mirror1; reg_mirror1 = dc_mirror_get(); return copy_to_user(argp, ®_mirror1, 1)?-EFAULT : 0; } default: return -1; } return 0;}/*static int check_reg(void) { unsigned char temp_exposure, temp_light, auto_man; temp_exposure = gpio_sccb_read(I2C_OV7725, 0x10); auto_man = gpio_sccb_read(I2C_OV7725, 0x13); if(temp_exposure<0x80) { if((auto_man & 0x01) == 0x01) { gpio_i2c_write(I2C_OV7725, 0x13, 0xfe); } gpio_i2c_write(I2C_OV7725, 0x10, 0x80); gpio_i2c_write(I2C_OV7725, 0x08, 0x00); } temp_light = gpio_sccb_read(I2C_OV7725, 0x5); if(temp_light < 0x60) { if((auto_man & 0x01) == 0x0) { gpio_i2c_write(I2C_OV7725, 0x13, 0xff); } } cycle_timer.expires = jiffies + msecs_to_jiffies(40); add_timer(&cycle_timer); return 0;}*/#if 0void gpio_i2c_test(void){ unsigned char regvalue,loop1; regvalue = gpio_sccb_read(I2C_OV7725, 0x9); printk("zoom regvalue = %x\n",regvalue); for(loop1=0;loop1<=0x7f;loop1++) { gpio_i2c_write(I2C_OV7725, DC_COM7, loop1); regvalue = gpio_sccb_read(I2C_OV7725, DC_COM7); printk("after write, regvalue = %x\n",regvalue); }}#endif/* * The various file operations we support. */ static struct file_operations ov7725_fops = { .owner = THIS_MODULE, .ioctl = ov7725_ioctl, .open = ov7725_open, .release = ov7725_close};static struct miscdevice ov7725_dev = { MISC_DYNAMIC_MINOR, "ov7725", &ov7725_fops,};static int ov7725_device_init(void){ unsigned char regvalue; int loop1; #if 0 regvalue = HW_REG(GPIO_0_DIR); regvalue |= 0x04; HW_REG(GPIO_0_DIR) = regvalue; HW_REG(GPIO_0_2_REG) = 0x0;#endif /* reset */ rst_ov7725(); gpio_i2c_write(I2C_OV7725, DC_COM7, 0x80); for(loop1=0;loop1 < 5000;loop1++) { ; } regvalue = gpio_sccb_read(I2C_OV7725, DC_COM7); regvalue &=0x7f; gpio_i2c_write(I2C_OV7725, DC_COM7, regvalue); regvalue = gpio_sccb_read(I2C_OV7725,DC_PIDH); loop1 = gpio_sccb_read(I2C_OV7725,DC_PIDL); if((regvalue != PIDH) || (loop1 != PIDL)) { printk("read Prodect ID Number MSB is %x\n",regvalue); printk("read Prodect ID Number LSB is %x\n",loop1); printk("check ov7725 ID error.\n"); return -EFAULT; }#if 0 gpio_i2c_write(I2C_OV7725, DC_COM7, 0x80); for(loop1=0;loop1 < 5000;loop1++) { ; } regvalue = gpio_sccb_read(I2C_OV7725, DC_COM7); regvalue &=0x7f; gpio_i2c_write(I2C_OV7725, DC_COM7, regvalue); #endif if(out_mode == 1) ov7725_vga_init(); else ov7725_qvga_init(); #if 0//auto exposure init_timer(&cycle_timer); cycle_timer.function = (void *)check_reg; cycle_timer.expires = jiffies + msecs_to_jiffies(40); add_timer(&cycle_timer); #endif return 0;}static int __init ov7725_init(void){ int ret = 0; ret = misc_register(&ov7725_dev); if(ret) { printk("could not register ov7725 devices. \n"); return ret; } if(ov7725_device_init()<0){ misc_deregister(&ov7725_dev); printk("ov7725 driver init fail for device init error!\n"); return -1; } printk("ov7725 driver init successful!\n"); return ret;}static void __exit ov7725_exit(void){#if 0 del_timer(&cycle_timer);#endif misc_deregister(&ov7725_dev);}module_init(ov7725_init);module_exit(ov7725_exit);#ifdef MODULE#include <linux/compile.h>#endifmodule_param(out_mode, int, S_IRUGO);module_param(s_s32Scene, int, S_IRUGO);MODULE_INFO(build, UTS_VERSION);MODULE_LICENSE("GPL");MODULE_AUTHOR("hisilicon");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -