//#define //Main jobs: // 1.check for device-specified errors, device not ready. // 2.Initialize the device if it is opened for the first time. static int CAM_CAL_Open(struct inode * a_pstInode, struct file * a_pstFile) { CAM_CALDB("[S24CAM_CAL] CAM_CAL_Open\n"); spin_lock(&g_CAM_CALLock); if(g_u4Opened) { spin_unlock(&g_CAM_CALLock); return -EBUSY; } else { g_u4Opened = 1; atomic_set(&g_CAM_CALatomic,0); } spin_unlock(&g_CAM_CALLock); #if defined(MT6572) // do nothing #else if(TRUE != hwPowerOn(MT65XX_POWER_LDO_VCAMA, VOL_2800, "S24CS64A")) { CAM_CALDB("[CAM_CAL] Fail to enable analog gain\n"); return -EIO; } #endif return 0; }
static int CAM_CAL_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { int i4RetValue = 0; CAM_CALDB("[S24CAM_CAL] Attach I2C \n"); // spin_lock_init(&g_CAM_CALLock); //get sensor i2c client spin_lock(&g_CAM_CALLock); //for SMP g_pstI2Cclient = client; g_pstI2Cclient->timing = 200;//200k g_pstI2Cclient->addr = ov16825OTP_AWBAF_DEVICE_ID>>1; spin_unlock(&g_CAM_CALLock); // for SMP CAM_CALDB("[CAM_CAL] g_pstI2Cclient->addr = 0x%8x \n",g_pstI2Cclient->addr); //Register char driver i4RetValue = RegisterCAM_CALCharDrv(); if(i4RetValue){ CAM_CALDB("[S24CAM_CAL] register char device failed!\n"); return i4RetValue; } CAM_CALDB("[S24CAM_CAL] Attached!! \n"); return 0; }
static int CAM_CAL_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { int i4RetValue = 0; CAM_CALDB("[imx219otp_CAL] Attach I2C \n"); // spin_lock_init(&g_CAM_CALLock); //get sensor i2c client spin_lock(&g_CAM_CALLock); //for SMP g_pstI2Cclient = client; g_pstI2Cclient->addr = HI551QTECHV2_EEPROM_DEVICE_ID>>1; spin_unlock(&g_CAM_CALLock); // for SMP CAM_CALDB("[CAM_CAL] g_pstI2Cclient->addr = 0x%8x \n",g_pstI2Cclient->addr); //Register char driver i4RetValue = RegisterCAM_CALCharDrv(); if(i4RetValue){ CAM_CALDB("[imx219otp_CAL] register char device failed!\n"); return i4RetValue; } CAM_CALDB("[imx219otp_CAL] Attached!! \n"); return 0; }
//Burst Read Data static int iReadData(unsigned int ui4_offset, unsigned int ui4_length, unsigned char * pinputdata) { int i4RetValue = 0; int i4ResidueDataLength; u32 u4IncOffset = 0; u32 u4CurrentOffset; u8 * pBuff; u8 * pOneByteBuff = NULL; pOneByteBuff = (u8 *)kmalloc(I2C_UNIT_SIZE, GFP_KERNEL); CAM_CALDB("ui4_offset=%0x,ui4_length=%d\n",ui4_offset,ui4_length); i4ResidueDataLength = (int)ui4_length; u4CurrentOffset = ui4_offset; pBuff = pinputdata; do { i4RetValue = iReadCAM_CAL(u4CurrentOffset, 1, pBuff); //* pBuff = HI704_read_cmos_sensor(u4CurrentOffset); CAM_CALDB("[CAM_CAL][iReadData] Read 0x%x=0x%x \n", u4CurrentOffset, pBuff[0]); if (i4RetValue != 0) { CAM_CALDB("[CAM_CAL] I2C iReadData failed!! \n"); return -1; } u4IncOffset++; i4ResidueDataLength --; u4CurrentOffset = ui4_offset + u4IncOffset; pBuff = pinputdata + u4IncOffset; }while (i4ResidueDataLength > 0); // CAM_CALDB("[S24EEPORM] iReadData finial address is %d length is %d buffer address is 0x%x\n",u4CurrentOffset, i4ResidueDataLength, pBuff); // CAM_CALDB("[S24EEPORM] iReadData done\n" ); return 0; }
int iReadCAM_CAL_8(u8 a_u2Addr, u8 * a_puBuff, u16 i2c_id) { int i4RetValue = 0; char puReadCmd[1] = {(char)(a_u2Addr)}; spin_lock(&g_CAM_CALLock); //for SMP g_pstI2Cclient->addr = i2c_id>>1; g_pstI2Cclient->timing=400; g_pstI2Cclient->addr = g_pstI2Cclient->addr & (I2C_MASK_FLAG | I2C_WR_FLAG); spin_unlock(&g_CAM_CALLock); // for SMP i4RetValue = i2c_master_send(g_pstI2Cclient, puReadCmd, 1); if (i4RetValue != 1) { CAM_CALDB("[CAM_CAL] I2C send read address failed!! \n"); CAM_CALDB("[CAMERA SENSOR] I2C send failed, addr = 0x%x, data = 0x%x !! \n", a_u2Addr, *a_puBuff ); return -1; } i4RetValue = i2c_master_recv(g_pstI2Cclient, (char *)a_puBuff, 1); CAM_CALDB("[CAM_CAL][iReadCAM_CAL] Read 0x%x=0x%x \n", a_u2Addr, a_puBuff[0]); if (i4RetValue != 1) { CAM_CALDB("[CAM_CAL] I2C read data failed!! \n"); return -1; } return 0; }
static int CAM_CAL_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { int i4RetValue = 0; CAM_CALDB("[CAM_CAL] Attach I2C\n"); /* spin_lock_init(&g_CAM_CALLock); */ /* get sensor i2c client */ spin_lock(&g_CAM_CALLock); /* for SMP */ g_pstI2Cclient = client; g_pstI2Cclient->addr = S24CS64A_DEVICE_ID >> 1; spin_unlock(&g_CAM_CALLock); /* for SMP */ CAM_CALDB("[CAM_CAL] g_pstI2Cclient->addr = 0x%8x\n", g_pstI2Cclient->addr); /* Register char driver */ i4RetValue = RegisterCAM_CALCharDrv(); if (i4RetValue) { CAM_CALDB("[CAM_CAL] register char device failed!\n"); return i4RetValue; } CAM_CALDB("[CAM_CAL] Attached!!\n"); return 0; }
static kal_uint8 OV5670_ReadOtp(u8 address,unsigned char *iBuffer,unsigned int buffersize) { kal_uint16 i = 0; u8 readbuff = 0; int ret ; u16 i2c_id = 0; CAM_CALDB("[CAM_CAL_SUB]ENTER address:0x%x buffersize:%d\n ", address, buffersize); if (get_module_type() == SUNNY_MODULE) { *(iBuffer) =(unsigned char)sunny_otp_data->module_id; *(iBuffer+1) =(unsigned char)sunny_otp_data->awb_rg_msb; *(iBuffer+2) =(unsigned char)sunny_otp_data->awb_bg_msb; *(iBuffer+3) =(unsigned char)sunny_otp_data->awb_lsb; } else if (get_module_type() == OFILM_MODULE) { *(iBuffer) =(unsigned char)ofilm_otp_data->module_id; *(iBuffer+1) =(unsigned char)ofilm_otp_data->awb_rg_msb; *(iBuffer+2) =(unsigned char)ofilm_otp_data->awb_bg_msb; *(iBuffer+3) =(unsigned char)ofilm_otp_data->awb_lsb; } else if (get_module_type() == QTECH_MODULE) { *(iBuffer) =(unsigned char)qtech_otp_data->module_id; *(iBuffer+1) =(unsigned char)qtech_otp_data->awb_rg_msb; *(iBuffer+2) =(unsigned char)qtech_otp_data->awb_bg_msb; *(iBuffer+3) =(unsigned char)qtech_otp_data->awb_lsb; }else return 0; for(i = 0; i<4; i++) CAM_CALDB("[CAM_CAL_SUB]ov5670 otp readbuff[%d] = 0x%x\n",i,*(iBuffer+i)); }
static kal_uint8 check_IMX135_otp_valid_AWBPage(void) { kal_uint8 Pagemax = 12; kal_uint8 Pagemin = 9; kal_uint8 page = 0; kal_uint8 AWB_OK = 0x00; u8 readbuff; int ret; for(page = Pagemax ; page>=Pagemin;page--) { if (IMX135_GotoPage(page)) { ret = iReadCAM_CAL(0x3b04,1,&readbuff); AWB_OK = readbuff; if (AWB_OK != 0) { CAM_CALDB("AWB otp is exist\n"); break; } } } if ( page<Pagemin) { CAM_CALDB("No AWB OTP data!"); return 0; } return page; }
static int __init CAM_CAL_init(void) { int i4RetValue = 0; CAM_CALDB("CAM_CAL_i2C_init\n"); //Register char driver i4RetValue = RegisterCAM_CALCharDrv(); if(i4RetValue){ CAM_CALDB(" register char device failed!\n"); return i4RetValue; } CAM_CALDB(" Attached!! \n"); // i2c_register_board_info(CAM_CAL_I2C_BUSNUM, &kd_cam_cal_dev, 1); if(platform_driver_register(&g_stCAM_CAL_Driver)){ CAM_CALERR("failed to register 135otp driver\n"); return -ENODEV; } if (platform_device_register(&g_stCAM_CAL_Device)) { CAM_CALERR("failed to register 135otp driver, 2nd time\n"); return -ENODEV; } return 0; }
//#define //Main jobs: // 1.check for device-specified errors, device not ready. // 2.Initialize the device if it is opened for the first time. static int CAM_CAL_Open(struct inode * a_pstInode, struct file * a_pstFile) { CAM_CALDB("[S24CAM_CAL] CAM_CAL_Open\n"); spin_lock(&g_CAM_CALLock); if(g_u4Opened) { spin_unlock(&g_CAM_CALLock); CAM_CALDB("[S24CAM_CAL] Opened, return -EBUSY\n"); return -EBUSY; } else { g_u4Opened = 1; atomic_set(&g_CAM_CALatomic,0); } spin_unlock(&g_CAM_CALLock); if(TRUE != hwPowerOn(MT65XX_POWER_LDO_VCAMA, VOL_2800, CAM_CAL_DRVNAME)) { CAM_CALDB("[S24CAM_CAL] Fail to enable analog gain\n"); return -EIO; } return 0; }
//Burst Write Data static int iWriteData(unsigned int ui4_offset, unsigned int ui4_length, unsigned char * pinputdata) { int i4RetValue = 0; int i4ResidueDataLength; u32 u4IncOffset = 0; u32 u4CurrentOffset; u8 * pBuff; CAM_CALDB("[S24CAM_CAL] iWriteData\n" ); i4ResidueDataLength = (int)ui4_length; u4CurrentOffset = ui4_offset; pBuff = pinputdata; CAM_CALDB("[CAM_CAL] iWriteData u4CurrentOffset is %d \n",u4CurrentOffset); do { CAM_CALDB("[CAM_CAL][iWriteData] Write 0x%x=0x%x \n",u4CurrentOffset, pBuff[0]); i4RetValue = iWriteCAM_CAL((u16)u4CurrentOffset, 1, pBuff[0]); if (i4RetValue != 0) { CAM_CALDB("[CAM_CAL] I2C iWriteData failed!! \n"); return -1; } u4IncOffset ++; i4ResidueDataLength --; u4CurrentOffset = ui4_offset + u4IncOffset; pBuff = pinputdata + u4IncOffset; }while (i4ResidueDataLength > 0); CAM_CALDB("[S24CAM_CAL] iWriteData done\n" ); return 0; }
//Address: 1Byte, Data: 1Byte int iReadCAM_CAL(u8 a_u2Addr, u32 ui4_length, u8 * a_puBuff, u8 i2c_id) { int i4RetValue = 0; char puReadCmd[1] = {a_u2Addr}; spin_lock(&g_CAM_CALLock); //for SMP g_pstI2Cclient->addr = i2c_id >> 1; spin_unlock(&g_CAM_CALLock); // for SMP //CAM_CALDB("[CAM_CAL] iReadCAM_CAL!! \n"); //CAM_CALDB("[CAM_CAL] i2c_master_send \n"); i4RetValue = i2c_master_send(g_pstI2Cclient, puReadCmd, 1); if (i4RetValue != 1) { CAM_CALDB("[CAM_CAL] I2C send read address failed!! \n"); return -1; } //CAM_CALDB("[CAM_CAL] i2c_master_recv \n"); i4RetValue = i2c_master_recv(g_pstI2Cclient, (char *)a_puBuff, ui4_length); // CAM_CALDB("[CAM_CAL][iReadCAM_CAL] Read 0x%x=0x%x \n", a_u2Addr, a_puBuff[0]); if (i4RetValue != ui4_length) { CAM_CALDB("[CAM_CAL] I2C read data failed!! \n"); return -1; } //CAM_CALDB("[CAM_CAL] iReadCAM_CAL done!! \n"); return 0; }
/* maximun read length is limited at "I2C_FIFO_SIZE" in I2c-mt65xx.c which is 8 bytes */ int iReadCAM_CAL(u16 a_u2Addr, u32 ui4_length, u8 *a_puBuff) { int i4RetValue = 0; char puReadCmd[2] = {(char)(a_u2Addr >> 8) , (char)(a_u2Addr & 0xFF)}; /* CAM_CALDB("[CAM_CAL] iReadCAM_CAL!!\n"); */ if (ui4_length > 8) { CAM_CALDB("[CAM_CAL] exceed I2c-mt65xx.c 8 bytes limitation\n"); return -1; } spin_lock(&g_CAM_CALLock); /* for SMP */ g_pstI2Cclient->addr = g_pstI2Cclient->addr & (I2C_MASK_FLAG | I2C_WR_FLAG); spin_unlock(&g_CAM_CALLock); /* for SMP */ /* CAM_CALDB("[EERPOM] i2c_master_send\n"); */ i4RetValue = i2c_master_send(g_pstI2Cclient, puReadCmd, 2); if (i4RetValue != 2) { CAM_CALDB("[CAM_CAL] I2C send read address failed!!\n"); return -1; } /* CAM_CALDB("[EERPOM] i2c_master_recv\n"); */ i4RetValue = i2c_master_recv(g_pstI2Cclient, (char *)a_puBuff, ui4_length); if (i4RetValue != ui4_length) { CAM_CALDB("[CAM_CAL] I2C read data failed!!\n"); return -1; } spin_lock(&g_CAM_CALLock); /* for SMP */ g_pstI2Cclient->addr = g_pstI2Cclient->addr & I2C_MASK_FLAG; spin_unlock(&g_CAM_CALLock); /* for SMP */ /* CAM_CALDB("[CAM_CAL] iReadCAM_CAL done!!\n"); */ return 0; }
//Address: 2Byte, Data: 1Byte int iReadCAM_CAL(u16 a_u2Addr, u32 ui4_length, u8 * a_puBuff) { int i4RetValue = 0; char puReadCmd[2] = {(char)(a_u2Addr >> 8) , (char)(a_u2Addr & 0xFF)}; //CAM_CALDB("[CAM_CAL] iReadCAM_CAL!! \n"); //CAM_CALDB("[CAM_CAL] i2c_master_send \n"); i4RetValue = i2c_master_send(g_pstI2Cclient, puReadCmd, 2); if (i4RetValue != 2) { CAM_CALDB("[CAM_CAL] I2C send read address failed!! \n"); return -1; } //CAM_CALDB("[CAM_CAL] i2c_master_recv \n"); i4RetValue = i2c_master_recv(g_pstI2Cclient, (char *)a_puBuff, ui4_length); CAM_CALDB("[CAM_CAL][iReadCAM_CAL] Read 0x%x=0x%x \n", a_u2Addr, a_puBuff[0]); if (i4RetValue != ui4_length) { CAM_CALDB("[CAM_CAL] I2C read data failed!! \n"); return -1; } //CAM_CALDB("[CAM_CAL] iReadCAM_CAL done!! \n"); return 0; }
static int get_module_type() { int ret = 0; u8 module_id = 0; u8 program_id = 0; u16 puSendCmd = 0x09; /* module id reg addr = 0x09 for s5k3l2xx liteon module */ ret = iReadCAM_CAL(0x02 , 1, &program_id, S5K3L2XXOTP_LITEON_DEVICE_ID); //read 0x02,if equal to 0x4d,primax module,otherwise,liteon module ret = iReadCAM_CAL(puSendCmd , 1, &module_id, S5K3L2XXOTP_LITEON_DEVICE_ID); if (!((ret < 0) || (module_id != 0x01) || (program_id == 0x4D))){ CAM_CALDB("[CAM_CAL]Get s5k3l2xx module type: liteon\n"); return LITEON_MODULE; } /* module id reg addr = 0x01 for s5k3l2xx primax module */ puSendCmd = 0x01; ret = iReadCAM_CAL(puSendCmd ,1, &module_id, S5K3L2XXOTP_PRIMAX_DEVICE_ID); if (!((ret < 0) || (module_id != 0x03) || (program_id != 0x4D))){ CAM_CALDB("[CAM_CAL]Get s5k3l2xx module type: primax\n"); return PRIMAX_MODULE; } CAM_CALDB("[CAM_CAL] get module type: no support main camera module! \n"); return -ENODEV; }
//Address: 2Byte, Data: 1Byte static int iWriteCAM_CAL(u16 a_u2Addr , u32 a_u4Bytes, u8 puDataInBytes) { #if 0 int i4RetValue = 0; int retry = 3; char puSendCmd[3] = {(char)(a_u2Addr >> 8) , (char)(a_u2Addr & 0xFF) ,puDataInBytes}; g_pstI2Cclient->addr = (IMX214OTP_DEVICE_ID>> 1); do { CAM_CALDB("[CAM_CAL][iWriteCAM_CAL] Write 0x%x=0x%x \n",a_u2Addr, puDataInBytes); i4RetValue = i2c_master_send(g_pstI2Cclient, puSendCmd, 3); if (i4RetValue != 3) { CAM_CALDB("[CAM_CAL] I2C send failed!!\n"); } else { break; } mdelay(10); } while ((retry--) > 0); //CAM_CALDB("[CAM_CAL] iWriteCAM_CAL done!! \n"); #else CAM_CALDB("[CAM_CAL][iWriteCAM_CAL] Write 0x%x=0x%x \n",a_u2Addr, puDataInBytes); iWriteReg(a_u2Addr,puDataInBytes,1,IMX214OTP_DEVICE_ID); #endif return 0; }
// maximun read length is limited at "I2C_FIFO_SIZE" in I2c-mt65xx.c which is 8 bytes int iWriteCAM_CAL(u16 a_u2Addr , u32 a_u4Bytes, u8 * puDataInBytes) { int i4RetValue = 0; u32 u4Index = 0; char puSendCmd[8] = {(char)(a_u2Addr >> 8) , (char)(a_u2Addr & 0xFF) , 0, 0, 0, 0, 0, 0}; if(a_u4Bytes + 2 > 8) { CAM_CALDB("[CAM_CAL] exceed I2c-mt65xx.c 8 bytes limitation (include address 2 Byte)\n"); return -1; } for(u4Index = 0 ; u4Index < a_u4Bytes ; u4Index += 1 ) { puSendCmd[(u4Index + 2)] = puDataInBytes[u4Index]; } i4RetValue = i2c_master_send(g_pstI2Cclient, puSendCmd, (a_u4Bytes + 2)); if (i4RetValue != (a_u4Bytes + 2)) { CAM_CALDB("[CAM_CAL] I2C write failed!! \n"); return -1; } mdelay(10); //for tWR singnal --> write data form buffer to memory. //CAM_CALDB("[CAM_CAL] iWriteCAM_CAL done!! \n"); return 0; }
inline static int RegisterCAM_CALCharDrv(void) { struct device* CAM_CAL_device = NULL; #if CAM_CAL_DYNAMIC_ALLOCATE_DEVNO if( alloc_chrdev_region(&g_CAM_CALdevno, 0, 1,S5K3M2_CAM_CAL_DRVNAME) ) { CAM_CALDB("[S5K3M2_CAL] Allocate device no failed\n"); return -EAGAIN; } #else if( register_chrdev_region( g_CAM_CALdevno , 1 , S5K3M2_CAM_CAL_DRVNAME) ) { CAM_CALDB("[S5K3M2_CAL] Register device no failed\n"); return -EAGAIN; } #endif //Allocate driver g_pCAM_CAL_CharDrv = cdev_alloc(); if(NULL == g_pCAM_CAL_CharDrv) { unregister_chrdev_region(g_CAM_CALdevno, 1); CAM_CALDB("[S5K3M2_CAL] Allocate mem for kobject failed\n"); return -ENOMEM; } //Attatch file operation. cdev_init(g_pCAM_CAL_CharDrv, &g_stCAM_CAL_fops); g_pCAM_CAL_CharDrv->owner = THIS_MODULE; //Add to system if(cdev_add(g_pCAM_CAL_CharDrv, g_CAM_CALdevno, 1)) { CAM_CALDB("[S5K3M2_CAL] Attatch file operation failed\n"); unregister_chrdev_region(g_CAM_CALdevno, 1); return -EAGAIN; } CAM_CAL_class = class_create(THIS_MODULE, "S5K3M2_CAM_CALdrv"); if (IS_ERR(CAM_CAL_class)) { int ret = PTR_ERR(CAM_CAL_class); CAM_CALDB("Unable to create class, err = %d\n", ret); return ret; } CAM_CAL_device = device_create(CAM_CAL_class, NULL, g_CAM_CALdevno, NULL, S5K3M2_CAM_CAL_DRVNAME); return 0; }
kal_bool IMX214_Read_LSC_Otp(kal_uint8 pagestart,kal_uint8 pageend,u16 Outdatalen,unsigned char * pOutputdata) { kal_uint8 page = 0; kal_uint16 byteperpage = 256; kal_uint16 number = 0; kal_uint16 LSCOTPaddress = 0x00 ; u8 readbuff; int i = 0; if(otp_flag){ for(i=0;i<Outdatalen;i++) pOutputdata[i]=OTPData[i]; } else{ if (!check_IMX214_otp_valid_LSC_Page(page)) { CAM_CALDB("check_IMX214_otp_valid_LSC_Page fail!\n"); return KAL_FALSE; } for(page = pagestart; page<=pageend; page++) { CAM_CALDB("read page=%d\n",page); if(page==0){ for(i = 49; i < byteperpage;i++) { iReadCAM_CAL_8(LSCOTPaddress+i,&readbuff,0xA0); pOutputdata[number]=readbuff; number+=1; } } else{ for(i = 0; i <=244;i++) { iReadCAM_CAL_8(LSCOTPaddress+i,&readbuff,0xA2); pOutputdata[number]=readbuff; number+=1; } } } } CAM_CALDB("LSC read finished number= %d\n",--number); otp_flag=0; return KAL_TRUE; }
//int iReadData(stCAM_CAL_INFO_STRUCT * st_pOutputBuffer) static int iReadData(unsigned int ui4_offset, unsigned int ui4_length, unsigned char * pinputdata) { int i4RetValue = 0; int i4ResidueDataLength; u32 u4IncOffset = 0; u32 u4CurrentOffset; u8 * pBuff; CAM_CALDB("[CAM_CAL] iReadData \n" ); if (ui4_offset + ui4_length >= 0x2000) { CAM_CALDB("[CAM_CAL] Read Error!! S-24CS64A not supprt address >= 0x2000!! \n" ); return -1; } i4ResidueDataLength = (int)ui4_length; u4CurrentOffset = ui4_offset; pBuff = pinputdata; do { if(i4ResidueDataLength >= 8) { i4RetValue = iReadCAM_CAL((u16)u4CurrentOffset, 8, pBuff); if (i4RetValue != 0) { CAM_CALDB("[CAM_CAL] I2C iReadData failed!! \n"); return -1; } u4IncOffset += 8; i4ResidueDataLength -= 8; u4CurrentOffset = ui4_offset + u4IncOffset; pBuff = pinputdata + u4IncOffset; } else { i4RetValue = iReadCAM_CAL((u16)u4CurrentOffset, i4ResidueDataLength, pBuff); if (i4RetValue != 0) { CAM_CALDB("[CAM_CAL] I2C iReadData failed!! \n"); return -1; } u4IncOffset += 8; i4ResidueDataLength -= 8; u4CurrentOffset = ui4_offset + u4IncOffset; pBuff = pinputdata + u4IncOffset; //break; } }while (i4ResidueDataLength > 0); //fix warning MSG CAM_CALDB("[CAM_CAL] iReadData finial address is %d length is %d buffer address is 0x%x\n",u4CurrentOffset, i4ResidueDataLength, pBuff); CAM_CALDB("[CAM_CAL] iReadData done\n" ); return 0; }
//Burst Read Data static int iReadData(u8 ui4_offset, unsigned int ui4_length, unsigned char * pinputdata) { int i4RetValue = 0; kal_uint8 page = 0; /* read otp */ OV5670_ReadOtp(ui4_offset,pinputdata, ui4_length); #if 0 for(i4RetValue = 0;i4RetValue<ui4_length;i4RetValue++){ CAM_CALDB( "[[CAM_CAL]]pinputdata[%d]=%d\n", i4RetValue,*(pinputdata+i4RetValue));} CAM_CALDB(" [[CAM_CAL]]page = %d,ui4_length = %d,ui4_offset =%d\n ",page,ui4_length,ui4_offset); CAM_CALDB("[S24EEPORM] iReadData done\n" ); #endif return 0; }
static int CAM_CAL_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { //int i4RetValue = 0; CAM_CALDB("Attach I2C \n"); // spin_lock_init(&g_CAM_CALLock); //get sensor i2c client spin_lock(&g_CAM_CALLock); //for SMP g_pstI2Cclient = client; g_pstI2Cclient->addr = IMX135_OTP_DEVICE_ID>>1; spin_unlock(&g_CAM_CALLock); // for SMP CAM_CALDB("g_pstI2Cclient->addr = 0x%x \n",g_pstI2Cclient->addr); return 0; }
static void Enb_OTP_Read(int enb){ u8 * pOneByteBuff = NULL; pOneByteBuff = (u8 *)kmalloc(I2C_UNIT_SIZE, GFP_KERNEL); //Enable Reading OTP CAM_CALDB("[CAM_CAL]Enb_OTP_Read=%d\n",enb); iReadData(0x3d21, I2C_UNIT_SIZE, pOneByteBuff); CAM_CALDB("[CAM_CAL]0x3d21=0x%x\n",*pOneByteBuff); if(enb){ *pOneByteBuff = (*pOneByteBuff | 0x01); iWriteData(0x3d21, I2C_UNIT_SIZE, pOneByteBuff ); } else { *pOneByteBuff = (*pOneByteBuff & 0xFE); iWriteData(0x3d21, I2C_UNIT_SIZE, pOneByteBuff ); } }
static int __init CAM_CAL_i2C_init(void) { i2c_register_board_info(CAM_CAL_I2C_BUSNUM, &kd_cam_cal_dev, 1); if (platform_driver_register(&g_stCAM_CAL_Driver)) { CAM_CALDB("failed to register CAM_CAL driver\n"); return -ENODEV; } if (platform_device_register(&g_stCAM_CAL_Device)) { CAM_CALDB("failed to register CAM_CAL driver\n"); return -ENODEV; } return 0; }
static kal_uint8 S5K3L2XX_ReadOtp(u8 address,unsigned char *iBuffer,unsigned int buffersize) { kal_uint16 i = 0; u8 readbuff = 0; int ret ; u16 i2c_id = 0; CAM_CALDB("[CAM_CAL]ENTER address:0x%x buffersize:%d\n ", address, buffersize); if (get_module_type() == LITEON_MODULE) { i2c_id = S5K3L2XXOTP_LITEON_DEVICE_ID; if (address == LITEON_LSC_START_ADDR ) { memcpy(iBuffer, liteon_lsc_data, LITEON_LSC_SIZE); return 0; } } else if (get_module_type() == PRIMAX_MODULE) { i2c_id = S5K3L2XXOTP_PRIMAX_DEVICE_ID; if (address == PRIMAX_LSC_START_ADDR ) { /* * lsc data had been read out in sensor driver, * so just copy it to user. */ memcpy(iBuffer, primax_lsc_data, PRIMAX_LSC_SIZE); return 0; } } for(i = 0; i<buffersize; i++) { ret= iReadCAM_CAL(address+i,1, &readbuff, i2c_id); //CAM_CALDB("[CAM_CAL]address+i = 0x%x,readbuff = 0x%x\n",(address+i),readbuff ); *(iBuffer+i) =(unsigned char)readbuff; } return 0; }
/* 2.Initialize the device if it is opened for the first time. */ static int CAM_CAL_Open(struct inode *a_pstInode, struct file *a_pstFile) { CAM_CALDB("[S24CAM_CAL] CAM_CAL_Open\n"); spin_lock(&g_CAM_CALLock); if (g_u4Opened) { spin_unlock(&g_CAM_CALLock); return -EBUSY; } /*else {*//*LukeHu--150720=For check fo*/ if (!g_u4Opened) {/*LukeHu++150720=For check fo*/ g_u4Opened = 1; atomic_set(&g_CAM_CALatomic, 0); } spin_unlock(&g_CAM_CALLock); /* #if defined(MT6572) */ /* do nothing */ /* #else */ /* if(TRUE != hwPowerOn(MT65XX_POWER_LDO_VCAMA, VOL_2800, "S24CS64A")) */ /* { */ /* CAM_CALDB("[CAM_CAL] Fail to enable analog gain\n"); */ /* return -EIO; */ /* } */ /* #endif */ return 0; }
static kal_uint8 IMX135_ReadOtp(kal_uint8 page,kal_uint16 address,unsigned char *iBuffer,unsigned int buffersize) { kal_uint16 i = 0; u8 readbuff ; int ret ; CAM_CALDB("[CAM_CAL]ENTER page:0x%x address:0x%x buffersize:%d\n ",page, address, buffersize); if (IMX135_GotoPage(page)) { for(i = 0; i<buffersize; i++) { ret= iReadCAM_CAL(address+i,1,&readbuff); CAM_CALDB("[CAM_CAL]address+i = 0x%x,readbuff = 0x%x\n",(address+i),readbuff ); *(iBuffer+i) =(unsigned char)readbuff; } } return 0; }
int read_imx219_eeprom(u8 slv_id, u16 offset, u8* data) { int ret = 0; ret = read_cmos_sensor(slv_id,offset,data); CAM_CALDB("OTP read slv_id 0x%x offset 0x%x data 0x%x\n", slv_id,offset,*data); return ret; }
void IMX214_ReadOtp(kal_uint8 page,kal_uint16 address,unsigned char *iBuffer,unsigned int buffersize) { kal_uint16 i = 0; u8 readbuff, base_add; int ret ; //base_add=(address/10)*16+(address%10); CAM_CALDB("[CAM_CAL]ENTER page:0x%x address:0x%x buffersize:%d\n ",page, address, buffersize); if (IMX214_GotoPage(page)) { for(i = 0; i<buffersize; i++) { ret= iReadCAM_CAL_8(address+i,&readbuff,0xA0); CAM_CALDB("[CAM_CAL]address+i = 0x%x,readbuff = 0x%x\n",(address+i),readbuff ); *(iBuffer+i) =(unsigned char)readbuff; } } }
//#define //Main jobs: // 1.check for device-specified errors, device not ready. // 2.Initialize the device if it is opened for the first time. static int CAM_CAL_Open(struct inode * a_pstInode, struct file * a_pstFile) { CAM_CALDB("[S5K3M2_CAL] CAM_CAL_Open\n"); spin_lock(&g_CAM_CALLock); if(g_u4Opened) { spin_unlock(&g_CAM_CALLock); CAM_CALDB("[S5K3M2_CAL] Opened, return -EBUSY\n"); return -EBUSY; } else { g_u4Opened = 1; atomic_set(&g_CAM_CALatomic,0); } spin_unlock(&g_CAM_CALLock); mdelay(2); return 0; }