static int sensor_flip_cb(struct i2c_client *client, int flip) { char val; int err = 0; SENSOR_DG("flip: %d",flip); if (flip) { sensor_write(client, 0xfe, 0); err = sensor_read(client, 0x17, &val); val-=4; if (err == 0) { if((val & 0x2) == 0){ err = sensor_write(client, 0x17, ((val |0x2)+4)); } else { err = sensor_write(client, 0x17, ((val & 0xfc)+4)); } } } else { //do nothing } return err; }
/* Purpose: This fucntion only for SVGA Camera : 4BA */ static int change_sensor_size(struct i2c_client *client, int size) { int i; switch (size) { #if defined(CONFIG_VIDEO_SAMSUNG_S5K4BA) case SENSOR_QSVGA: for (i = 0; i < S5K4BA_QSVGA_REGS; i++) { sensor_write(client, s5k4ba_reg_qsvga[i].subaddr, s5k4ba_reg_qsvga[i].value); } break; case SENSOR_SVGA: for (i = 0; i < S5K4BA_SVGA_REGS; i++) { sensor_write(client, s5k4ba_reg_svga[i].subaddr, s5k4ba_reg_svga[i].value); } break; #else #error No samsung CIS moudule ! #endif default: panic("4xa_sensor.c: unexpect value \n"); } return 0; }
static void sensor_poll_work(struct work_struct *work) { int ret; int delay; u8 val; struct sensor_data *data = container_of(to_delayed_work(work), struct sensor_data, work_ps); SENSOR_DBG(DBG_LEVEL1, "%s", data->client->name); mutex_lock(&data->lock); if ((data->state & PS_STATE_FLAG) != PS_ENABLE) goto out; /*exit when get far event*/ ret = sensor_read(data, REG_PROX_DATA, 1, &val); if (ret < 0) goto out; if (val <= data->ps_threshold) { SENSOR_DBG(DBG_LEVEL2, "PS far %02x", val); input_report_abs(data->input_ps, ABS_X, 1); input_sync(data->input_ps); sensor_write(data, REG_PROX_HT, data->ps_threshold); goto out; } delay = msecs_to_jiffies(data->interval); schedule_delayed_work(&data->work_ps, delay); out: mutex_unlock(&data->lock); }
void AR0330_SetSharpness(int32_t sharpness) { CyU3PDebugPrint(4, "AR0330_SetSharpness: %d\r\n", sharpness); if (sharpness < SHARPNESS_MINIMUM && sharpness > SHARPNESS_MAXIMUM) { return; // ignore invalid values } current_sharpness = sharpness; sensor_write(0x305e, (uint16_t)(sharpness)); // global_gain }
void AR0330_SetBrightness(int32_t brightness) { CyU3PDebugPrint(4, "AR0330_SetBrightness: %d\r\n", brightness); if (brightness < BRIGHTNESS_MINIMUM && brightness > BRIGHTNESS_MAXIMUM) { return; // ignore invalid values } current_brightness = brightness; sensor_write(0x301e, (uint16_t)(brightness)); // data_pedestal }
/*used to detect ps far event*/ struct delayed_work work_ps; #define PS_WORK_INTERVAL 500 int interval; #define PS_NEAR_FAR_THRESHOLD 0xc8 int ps_threshold; int gpio_int; int irq; #define PS_DISABLE (0<<0) #define PS_ENABLE (1<<0) #define PS_STATE_FLAG (1<<0) #define ALS_DISABLE (0<<1) #define ALS_ENABLE (1<<1) #define ALS_STATE_FLAG (1<<1) int state; int state_suspend; }jsa1212_data; static int sensor_read(struct sensor_data *data, u8 reg, u8 len, u8 *val) { int ret; if (len > 1) { ret = i2c_smbus_read_i2c_block_data(data->client, reg, len, val); if (ret < 0) dev_err(&data->client->dev, "Err: read reg %02x=%02x\n", reg, ret); return ret; } else { ret = i2c_smbus_read_byte_data(data->client, reg); if (ret >= 0) { SENSOR_DBG(DBG_LEVEL3, "read i2c reg %02x=%02x", reg, ret); *val = ret; return 0; } else { dev_err(&data->client->dev, "Err: return %d when read i2c reg %02x\n", ret, reg); return ret; } } } static int sensor_write(struct sensor_data *data, u8 reg, u8 val) { int ret; SENSOR_DBG(DBG_LEVEL3, "write i2c reg %02x=%02x", reg, val); ret = i2c_smbus_write_byte_data(data->client, reg, val); if (ret < 0) { dev_err(&data->client->dev, "Err: return %d when write i2c reg %02x=%02x\n", ret, reg, val); } return ret; } #define PS_ENABLE_FLAG (1 << 7) #define PS_DISABLE_FLAG (0 << 7) #define PULSES_INTERVAL_200MS (0b010 << 4) #define PULSES_INTERVAL_100MS (0b011 << 4) #define PULSES_INTERVAL_75MS (0b100 << 4) #define PULSED_CURRENT_100MA (0 << 3) #define PULSED_CURRENT_200MA (1 << 3) #define ALS_ENABLE_FLAG (1 << 2) #define ALS_DISABLE_FLAG (0 << 2) #define PXS_CONVERSION_4 (0b01 << 1) #define PXS_CONVERSION_8 (0b10 << 1) #define PXS_CONVERSION_16 (0b11 << 1) #define ALS_CONVERSION_4 (0b01 << 5) #define ALS_CONVERSION_8 (0b10 << 5) #define ALS_CONVERSION_16 (0b11 << 5) #define ALS_LUX_2048 (0b000 << 0) /* 0.50 lux/count */ #define ALS_LUX_1024 (0b001 << 0) /* 0.25 lux/count */ static int sensor_init(struct sensor_data *data) { int ret = 0; SENSOR_DBG(DBG_LEVEL1, "%s", data->client->name); ret = sensor_write(data, REG_CONFIGURE, PS_DISABLE_FLAG | PULSES_INTERVAL_100MS | PULSED_CURRENT_100MA | ALS_DISABLE_FLAG); if (ret < 0) return ret; ret = sensor_write(data, REG_INTERRUPT, PXS_CONVERSION_4|ALS_CONVERSION_4); if (ret < 0) return ret; return sensor_write(data, REG_ALS_RNG, ALS_LUX_2048); }
void AR0330_SetContrast(int32_t contrast) { CyU3PDebugPrint(4, "AR0330_SetContrast %d\r\n", contrast); if (contrast < CONTRAST_MINIMUM && contrast > CONTRAST_MAXIMUM) { return; // ignore invalid values } current_contrast = contrast; uint16_t gain = analog_gain[contrast] & 0x3f; // 6 bit fields: cb=13..8 ca=5..0 sensor_write(0x3060, (gain << 8) | gain); // analog_gain_cb | analog_gain }
void inline sensor_init(struct i2c_client *sam_client) { int i; i = (sizeof(s5k4ba_reg)/sizeof(s5k4ba_reg[0])); for (i = 0; i < S5K4BA_INIT_REGS; i++) { sensor_write(sam_client, s5k4ba_reg[i].subaddr, s5k4ba_reg[i].value); } }
void GYRO_Init() { I2C_ITConfig(SENSOR_I2C_BUS, I2C_IT_BUF|I2C_IT_EVT|I2C_IT_ERR, DISABLE); sensor_write(GYRO_address, CTRL_REG1_G, 0xAF); //0xEF sensor_write(GYRO_address, CTRL_REG2_G, 0x00); sensor_write(GYRO_address, CTRL_REG3_G, 0x08); sensor_write(GYRO_address, CTRL_REG4_G, 0x10); sensor_write(GYRO_address, CTRL_REG5_G, 0x00); /**/sensor_write(ACCER_address, CTRL_REG1_A, 0x2F); sensor_write(ACCER_address, CTRL_REG2_A, 0x00); sensor_write(ACCER_address, CTRL_REG3_A, 0x10); //0x1A sensor_write(ACCER_address, CTRL_REG4_A, 0x00); sensor_write(ACCER_address, CTRL_REG5_A, 0x00); printf("\nGYRO_init DONE!\n"); I2C_ITConfig(SENSOR_I2C_BUS, I2C_IT_EVT|I2C_IT_ERR, ENABLE); }
void inline sensor_init(struct i2c_client *sam_client) { int i; i = (sizeof(s5k3aa_reg)/sizeof(s5k3aa_reg[0])); for (i = 0; i < S5K3AA_INIT_REGS; i++) { sensor_write(sam_client, s5k3aa_reg[i].subaddr, s5k3aa_reg[i].value); #if 0 printk(KERN_ERR "Page:[%03d] Subaddr %02x = 0x%02x\n",i, s5k3aa_reg[i].subaddr, s5k3aa_reg[i].value); #endif } #ifdef YOU_WANT_TO_CHECK_IMG_SENSOR for (i = 0; i < S5K3AA_INIT_REGS; i++) { if (s5k3aa_reg[i].subaddr == PAGE_ADDRESS) { sensor_write(sam_client, s5k3aa_reg[i].subaddr, s5k3aa_reg[i].value); printk(KERN_ERR "Page: Subaddr %02x = 0x%02x\n", s5k3aa_reg[i].subaddr, s5k3aa_reg[i].value); } else { s5k3aa_regs_mirror[i].subaddr = s5k3aa_reg[i].subaddr; s5k3aa_regs_mirror[i].value = s5k3aa_read(sam_client, s5k3aa_reg[i].subaddr); printk(KERN_ERR "Subaddr %02x = 0x%02x\n", s5k3aa_reg[i].subaddr, s5k3aa_regs_mirror[i].value); } } #endif }
static int change_sensor_wb(struct i2c_client *client, int type) { printk("[ *** Page 0, 3XA Sensor White Balance Mode ***]\n"); #if defined(CONFIG_VIDEO_SAMSUNG_S5K3AA) sensor_write(client, 0xEC, 0x0); sensor_write(client, 0x30, type); #elif defined(CONFIG_VIDEO_SAMSUNG_S5K3BA) sensor_write(client, 0xFC, 0x0); sensor_write(client, 0x30, type); #endif switch(type){ case 0: default: printk(" -> AWB auto mode ]\n"); break; case 1: printk(" -> Indoor 3100 mode ]\n"); break; case 2: printk(" -> Outdoor 5100 mode ]\n"); break; case 3: printk(" -> Indoor 2000 mode ]\n"); break; case 4: printk(" -> AE/AWB halt ]\n"); break; case 5: printk(" -> Cloudy(6000) mode ]\n"); break; case 6: printk(" -> Sunny(8000) mode ]\n"); break; } return 0; }
static int sensor_mirror_cb (struct i2c_client *client, int mirror) { char val; int err = 0; SENSOR_DG("mirror: %d",mirror); if (mirror) { err = sensor_read(client, 0x3022, &val); if (err == 0) { val |= 0x02; err = sensor_write(client, 0x3022, val); } } else { err = sensor_read(client, 0x3022, &val); if (err == 0) { val &= 0xfd; err = sensor_write(client, 0x3022, val); } } return err; }
static int sensor_flip_cb(struct i2c_client *client, int flip) { char val; int err = 0; SENSOR_DG("flip: %d",flip); if (flip) { err = sensor_read(client, 0x3022, &val); if (err == 0) { val |= 0x01; err = sensor_write(client, 0x3022, val); } } else { err = sensor_read(client, 0x3022, &val); if (err == 0) { val &= 0xfe; err = sensor_write(client, 0x3022, val); } } return err; }
static int sensor_init( struct v4l2_subdev *sd, u32 val ) { printk("%s\n", __FUNCTION__); sensor_write(0x05, 0x01); sensor_write(0x05, 0x00); sensor_write(0x02, 0x00); sensor_write(0xD0, 0xFF); sensor_write(0x0f, 0x0a); sensor_write(0x03, 0x6d); return sensor_write(0x0d, 0x47); }
static int sensor_s_vflip(struct cmos_subdev *sd, int value) { int data; data = sensor_read(sd, 0x14); switch (value) { case 0: data &= ~0x02; break; case 1: data |= 0x02; break; default: return -EINVAL; } return sensor_write(sd, 0x14, data); }
/* * Write a list of register settings; */ int sensor_write_array(struct v4l2_subdev *sd, struct regval_list *regs, int array_size) { int ret = 0, i = 0; struct cci_driver *cci_drv = v4l2_get_subdevdata(sd); if(!regs) return -EINVAL; while(i < array_size) { if(regs->addr == REG_DLY) { msleep(regs->data); } else { ret = sensor_write(sd, regs->addr, regs->data); if(ret < 0) printk("%s sensor write array error!!\n",cci_drv->name); } i++; regs++; } return 0; }
int nuvoton_vin_probe(struct nuvoton_vin_device* cam) { int i,ret = 0; __u8 SensorID[4]; struct OV_RegValue *psRegValue; ENTRY(); nuvoton_vin_attach_sensor(cam, &ov7725); // if i2c module isn't loaded at this time if(!sensor_inited) return -1; psRegValue=RegValue; for(i=0;i<_REG_TABLE_SIZE(RegValue); i++, psRegValue++) { int32_t ret; printk("."); ret = sensor_write((psRegValue->uRegAddr), (psRegValue->uValue)); if(ret<0) { VDEBUG("Wrong to write register addr = 0x%x, write data = 0x%x , ret = %d\n", (psRegValue->uRegAddr), (psRegValue->uValue), ret); } } //----------Read sensor id------------------------------------- SensorID[0]=sensor_read(0x0A); /* PID 0x77 */ SensorID[1]=sensor_read(0x0B); /* VER 0x21 */ SensorID[2]=sensor_read(0x1C); /* Manufacturer ID Byte - High 0x7F */ SensorID[3]=sensor_read(0x1D); /* Manufacturer ID Byte - Low 0xA2 */ printk("Sensor PID = 0x%02x(0x77) VER = 0x%02x(0x21) MIDH = 0x%02x(0x7F) MIDL = 0x%02x(0xA2)\n", SensorID[0],SensorID[1],SensorID[2],SensorID[3]); //------------------------------------------------------------- printk("\n"); if(ret>=0) printk("driver i2c initial done\n"); else printk("driver i2c initial fail\n"); LEAVE(); return ret; }
void ACCER_Test() { int value1=0,value2=0,value3=0,STATUS_RES_A=0; sensor_write(ACCER_address, CTRL_REG1_A, 0x3F); value1= sensor_read(ACCER_address, OUT_X_H_A)*0x100 + sensor_read(ACCER_address, OUT_X_L_A); if(value1 > 0x7FFF) value1=value1-0x10000; value2= sensor_read(ACCER_address, OUT_Y_H_A)*0x100 + sensor_read(ACCER_address, OUT_Y_L_A); if(value2 > 0x7FFF) value2=value2-0x10000; value3= sensor_read(ACCER_address, OUT_Z_H_A)*0x100 + sensor_read(ACCER_address, OUT_Z_L_A); if(value3 > 0x7FFF) value3=value3-0x10000; /* STATUS_RES_A=sensor_read(ACCER_address,0x20); printf("CTRL1_RES_A: 0x%x ", STATUS_RES_A); STATUS_RES_A=sensor_read(ACCER_address,0x21); printf("CTRL2_RES_A: 0x%x ", STATUS_RES_A); STATUS_RES_A=sensor_read(ACCER_address,0x22); printf("CTRL3_RES_A: 0x%x ", STATUS_RES_A); STATUS_RES_A=sensor_read(ACCER_address,0x23); printf("CTRL4_RES_A: 0x%x ", STATUS_RES_A); STATUS_RES_A=sensor_read(ACCER_address,0x24); printf("CTRL5_RES_A: 0x%x ", STATUS_RES_A); */ printf("accer:%d %d %d\n",value1,value2,value3); // printf("accer:0x%x 0x%x 0x%x\n",value1,value2,value3); }
static int sensor_s_ctrl( struct v4l2_subdev *sd, struct v4l2_control *ctrl ) { unsigned char data; int nRet = 0; switch(ctrl->id) { case V4L2_CID_AUTO_WHITE_BALANCE: printk("WBAUTO = %d\n", ctrl->value); nRet = sensor_write(0xff, 0x00); nRet = sensor_read(0xc7,(unsigned char *)&data); if(ctrl->value) { // Enable Auto AWB nRet = sensor_write(0xc7,data& ~0x40); }else{ // Disable Auto AWB } break; case V4L2_CID_POWER_LINE_FREQUENCY: printk("PL = %d\n", ctrl->value); if(ctrl->value == V4L2_CID_POWER_LINE_FREQUENCY_DISABLED) { }else if(ctrl->value == V4L2_CID_POWER_LINE_FREQUENCY_50HZ) { nRet = sensor_write(0xff, 0x01); nRet = sensor_write(0x0c, 0x38); if(select_fmt == 0){ // previre mode and capture mode nRet = sensor_write(0x46, 0x3f); }else if(select_fmt == 2){ // record mode nRet = sensor_write(0x46, 0x87); } }else if(ctrl->value == V4L2_CID_POWER_LINE_FREQUENCY_60HZ) { nRet = sensor_write(0xff, 0x01); nRet = sensor_write(0x0c, 0x3c); nRet = sensor_write(0x46, 0x00); }else { return -EINVAL; } break; case V4L2_CID_WHITE_BALANCE_TEMPERATURE: printk("WB = %d\n", ctrl->value); nRet = sensor_write(0xff, 0x00); nRet = sensor_read(0xc7, (unsigned char *)&data); if(ctrl->value == 0) { //SUNSHINE nRet = sensor_write(0xc7, data|0x40); nRet = sensor_write(0xCC, 0x4e); nRet = sensor_write(0xCD, 0x40); nRet = sensor_write(0xCE, 0x48); }else if(ctrl->value == 1) { //CLOUDY nRet = sensor_write(0xc7,data|0x40); // Manual AWB mode nRet = sensor_write(0xCC, 0x38); nRet = sensor_write(0xCD, 0x40); nRet = sensor_write(0xCE, 0x58); }else if(ctrl->value == 2) { //FLUORESCENCE nRet = sensor_write(0xc7,data|0x40); // Manual AWB mode nRet = sensor_write(0xCC, 0x40); nRet = sensor_write(0xCD, 0x40); nRet = sensor_write(0xCE, 0x50); }else if(ctrl->value == 3) { //INCANDESCENCE nRet = sensor_write(0xc7,data|0x40); nRet = sensor_write(0xCC, 0x30); nRet = sensor_write(0xCD, 0x40); nRet = sensor_write(0xCE, 0x66); } break; case V4L2_CID_BACKLIGHT_COMPENSATION: printk("NightMode = %d\n", ctrl->value); if(ctrl->value) { nRet = sensor_write(0xff, 0x01); nRet = sensor_write(0x0f, 0x4b); nRet = sensor_write(0x03, 0x4f); }else { nRet = sensor_write(0xff, 0x01); nRet = sensor_write(0x0f, 0x43); nRet = sensor_write(0x03, 0x0f); nRet = sensor_write(0x2d, 0x00); nRet = sensor_write(0x2e, 0x00); } break; default: return -EINVAL; } return nRet; }
static int sensor_s_ctrl( struct v4l2_subdev *sd, struct v4l2_control *ctrl ) { unsigned char data; int nRet = 0; switch(ctrl->id) { case V4L2_CID_AUTO_WHITE_BALANCE: printk("WBAUTO = %d\n", ctrl->value); if(ctrl->value) { // Enable Auto AWB nRet = sensor_read(0x22, (unsigned char *)&data); nRet = sensor_write(0x5a, 0x56); //for AWB can adjust back nRet = sensor_write(0x5b, 0x40); nRet = sensor_write(0x5c, 0x4a); nRet = sensor_write(0x22, data|0x02); // Enable AWB }else{ // Disable Auto AWB } break; case V4L2_CID_POWER_LINE_FREQUENCY: printk("PL = %d\n", ctrl->value); if(ctrl->value == V4L2_CID_POWER_LINE_FREQUENCY_DISABLED) { } else if(ctrl->value == V4L2_CID_POWER_LINE_FREQUENCY_50HZ) { nRet = sensor_write(0x01 ,0x32); nRet = sensor_write(0x02 ,0x70); nRet = sensor_write(0x0f ,0x01); nRet = sensor_write(0xe2 ,0x00); //anti-flicker step [11:8] nRet = sensor_write(0xe3 ,0x78); //anti-flicker step [7:0] nRet = sensor_write(0xe4 ,0x02); //exp level 0 12.5fps nRet = sensor_write(0xe5 ,0x58); }else if(ctrl->value == V4L2_CID_POWER_LINE_FREQUENCY_60HZ) { nRet = sensor_write(0x01 ,0x6a); nRet = sensor_write(0x02 ,0x89); nRet = sensor_write(0x0f ,0x00); nRet = sensor_write(0xe2 ,0x00); //anti-flicker step [11:8] nRet = sensor_write(0xe3 ,0x7d); //anti-flicker step [7:0] nRet = sensor_write(0xe4 ,0x02); //exp level 0 12.00fps nRet = sensor_write(0xe5 ,0x71); } else { return -EINVAL; } break; case V4L2_CID_WHITE_BALANCE_TEMPERATURE: printk("WB = %d\n", ctrl->value); if(ctrl->value == 0) { // SUNSHINE nRet = sensor_read(0x22, (unsigned char *)&data); nRet = sensor_write(0x22, data&~0x02); nRet = sensor_write(0x5a, 0x74); // 50 45 40 nRet = sensor_write(0x5b, 0x52); nRet = sensor_write(0x5c, 0x40); }else if(ctrl->value == 1) { // CLOUDY nRet = sensor_read(0x22, (unsigned char *)&data); nRet = sensor_write(0x22, data&~0x02); // Disable AWB nRet = sensor_write(0x5a, 0x8c); // WB_manual_gain // 5a 42 40 nRet = sensor_write(0x5b, 0x50); nRet = sensor_write(0x5c, 0x40); }else if(ctrl->value == 2) { // FLUORESCENCE nRet = sensor_read(0x22, (unsigned char *)&data); nRet = sensor_write(0x22, data&~0x02); nRet = sensor_write(0x5a, 0x40); nRet = sensor_write(0x5b, 0x42); nRet = sensor_write(0x5c, 0x50); }else if(ctrl->value == 3) { // INCANDESCENCE nRet = sensor_read(0x22, (unsigned char *)&data); nRet = sensor_write(0x22, data&~0x02); nRet = sensor_write(0x5a, 0x48); nRet = sensor_write(0x5b, 0x40); nRet = sensor_write(0x5c, 0x5c); } break; case V4L2_CID_BACKLIGHT_COMPENSATION: printk("NightMode = %d\n", ctrl->value); nRet = sensor_read(0x20, (unsigned char *)&data); if(ctrl->value) { // NIGH MODE ON nRet = sensor_write(0x01 ,0x32); nRet = sensor_write(0x02 ,0xc8); nRet = sensor_write(0x0f ,0x21); nRet = sensor_write(0xe2 ,0x00); //anti-flicker step [11:8] nRet = sensor_write(0xe3 ,0x78); //anti-flicker step [7:0] nRet = sensor_write(0xe4 ,0x04); //exp level 0 10fps nRet = sensor_write(0xe5 ,0xb0); nRet = sensor_write(0xec, 0x00); nRet = sensor_write(0x20, data&0x5f); // close cc nRet = sensor_write(0x3c, 0x08); nRet = sensor_write(0x3d, 0x08); nRet = sensor_write(0x3e, 0x08); nRet = sensor_write(0x3f, 0x08); } else{ // NIGH MODE OFF nRet = sensor_write(0x01 ,0x32); nRet = sensor_write(0x02 ,0x70); nRet = sensor_write(0x0f ,0x01); nRet = sensor_write(0xe2 ,0x00); //anti-flicker step [11:8] nRet = sensor_write(0xe3 ,0x78); //anti-flicker step [7:0] nRet = sensor_write(0xe4 ,0x02); //exp level 0 20fps nRet = sensor_write(0xe5 ,0x58); nRet = sensor_write(0xec, 0x00); nRet = sensor_write(0x20, data|0x20); nRet = sensor_write(0x3c, 0x02); nRet = sensor_write(0x3d, 0x02); nRet = sensor_write(0x3e, 0x02); nRet = sensor_write(0x3f, 0x02); } break; default: return -EINVAL; } return nRet; }
static int sensor_capture(void) { printk("%s\n", __FUNCTION__); select_fmt = 1; sensor_write(0xff, 0x00); // page 0 sensor_write(0xc0, 0xc8); sensor_write(0xc1, 0x96); sensor_write(0x86, 0x3d); sensor_write(0x50, 0x00); sensor_write(0x51, 0x90); sensor_write(0x52, 0x2c); sensor_write(0x53, 0x00); sensor_write(0x54, 0x00); sensor_write(0x55, 0x88); sensor_write(0x57, 0x00); sensor_write(0x5a, 0x90); sensor_write(0x5b, 0x2c); sensor_write(0x5c, 0x05); return sensor_write(0xd3, 0x82); }
static int sensor_record(void) { printk("%s\n", __FUNCTION__); select_fmt = 2; sensor_write(0xff, 0x01); sensor_write(0x13, 0xf7); //turn on AGC/AEC sensor_write(0x12, 0x40); sensor_write(0x11, 0x00); sensor_write(0x17, 0x11); sensor_write(0x18, 0x43); sensor_write(0x19, 0x00); sensor_write(0x1a, 0x4b); sensor_write(0x32, 0x09); sensor_write(0x37, 0xc0); //sensor_write(0x46, 0x5e); //22.8m sensor_write(0x46, 0x87); //24m sensor_write(0x4f, 0xca); sensor_write(0x50, 0xa8); sensor_write(0x5a, 0x34); sensor_write(0x6d, 0x00); sensor_write(0x3d, 0x38); sensor_write(0x39, 0x12); sensor_write(0x35, 0xda); sensor_write(0x22, 0x19); sensor_write(0x37, 0xc3); sensor_write(0x23, 0x00); sensor_write(0x34, 0xc0); sensor_write(0x36, 0x1a); sensor_write(0x06, 0x88); sensor_write(0x07, 0xc0); sensor_write(0x0d, 0x87); sensor_write(0x0e, 0x41); sensor_write(0x4c, 0x00); sensor_write(0xff, 0x00); sensor_write(0xe0, 0x04); sensor_write(0xc0, 0x64); sensor_write(0xc1, 0x4B); sensor_write(0x8c, 0x00); sensor_write(0x86, 0x1D); sensor_write(0x50, 0x00); sensor_write(0x51, 0xC8); sensor_write(0x52, 0x96); sensor_write(0x53, 0x00); sensor_write(0x54, 0x00); sensor_write(0x55, 0x00); sensor_write(0x5a, 0xC8); sensor_write(0x5b, 0x96); sensor_write(0x5c, 0x00); sensor_write(0xd3, 0x82); return sensor_write(0xe0, 0x00); }
/* ********************************************************** * Following is local code: * * Please codeing your program here ********************************************************** */ static int sensor_parameter_record(struct i2c_client *client) { u8 ret_l,ret_h; int tp_l,tp_h; struct generic_sensor *sensor = to_generic_sensor(client); struct specific_sensor *spsensor = to_specific_sensor(sensor); sensor_read(client, 0x3200, &ret_l); sensor_write(client, 0x3200, ret_l&0xf9); sensor_read(client, 0x3201, &ret_l); sensor_write(client, 0x3201, ret_l&0xcf); //stop ae awb //read back ae sensor_read(client,0x3012,&ret_h); sensor_read(client,0x3013, &ret_l); tp_l = ret_l; tp_h = ret_h; spsensor->parameter.preview_exposure = ((tp_h<<8) & 0xF0) |((tp_l) & 0x0F); //Read back AGC Gain for preview sensor_read(client,0x3014, &ret_l); spsensor->parameter.preview_gain_dr = ret_l; sensor_read(client,0x3015, &ret_l); spsensor->parameter.preview_gain_ar = ret_l; sensor_read(client,0x3016, &ret_l); spsensor->parameter.preview_gain_dgr = ret_l; sensor_read(client,0x3017, &ret_l); spsensor->parameter.preview_gain_agr = ret_l; sensor_read(client,0x3018, &ret_l); spsensor->parameter.preview_gain_dgb = ret_l; sensor_read(client,0x3019, &ret_l); spsensor->parameter.preview_gain_agb = ret_l; sensor_read(client,0x301a, &ret_l); spsensor->parameter.preview_gain_db = ret_l; sensor_read(client,0x301b, &ret_l); spsensor->parameter.preview_gain_ab = ret_l; sensor_read(client,0x301c, &ret_l); spsensor->parameter.preview_gain_dglobal= ret_l; sensor_read(client,0x301d, &ret_l); spsensor->parameter.preview_gain_aglobal= ret_l; spsensor->parameter.CapturePclk = 48000; spsensor->parameter.PreviewPclk = 48000; sensor_read(client,0x300a, &ret_h); sensor_read(client,0x300b, &ret_l); tp_l = ret_l; tp_h = ret_h; spsensor->parameter.PreviewDummyPixels = (tp_l&0x0F) | ((tp_h<<8)&0xF0); spsensor->parameter.CaptureDummyPixels = 0; #if 0 sensor_read(client,0x3290, &ret_h); sensor_read(client,0x3291, &ret_l); tp_l = ret_l; tp_h = ret_h; spsensor->parameter.preview_awb_r = (tp_l&0x0F) | ((tp_h<<8)&0x10); sensor_read(client,0x3296, &ret_h); sensor_read(client,0x3297, &ret_l); tp_l = ret_l; tp_h = ret_h; spsensor->parameter.preview_awb_b = (tp_l&0x0F) | ((tp_h<<8)&0x10); #endif return 0; }
static int sensor_init( struct v4l2_subdev *sd, u32 val ) { printk("%s\n", __FUNCTION__); sensor_write(0xff, 0x01); // page 0 sensor_write(0x12, 0x80); msleep(10); sensor_write(0xff, 0x00); sensor_write(0xeb, 0x2a); sensor_write(0x2c, 0xff); sensor_write(0x2e, 0xdf); sensor_write(0xff, 0x01); // page 1 sensor_write(0x3c, 0x32); sensor_write(0x11, 0x00); sensor_write(0x09, 0x02); sensor_write(0x04, 0x28); sensor_write(0x13, 0xe5); sensor_write(0x14, 0x28); sensor_write(0x2c, 0x0c); sensor_write(0x33, 0x78); sensor_write(0x3a, 0x33); sensor_write(0x3b, 0xfb); sensor_write(0x3e, 0x00); sensor_write(0x43, 0x11); sensor_write(0x16, 0x10); sensor_write(0x39, 0x02); sensor_write(0x35, 0xda); sensor_write(0x22, 0x19); sensor_write(0x37, 0x40); sensor_write(0x23, 0x00); sensor_write(0x34, 0xc0); sensor_write(0x36, 0x1a); sensor_write(0x06, 0x88); sensor_write(0x07, 0xc0); sensor_write(0x0d, 0x87); sensor_write(0x0e, 0x41); sensor_write(0x4c, 0x00); sensor_write(0x4a, 0x81); sensor_write(0x21, 0x99); sensor_write(0x24, 0x40); sensor_write(0x25, 0x38); sensor_write(0x26, 0x82); sensor_write(0x5c, 0x00); sensor_write(0x63, 0x00); sensor_write(0x46, 0x3f); // dummy line sensor_write(0x0c, 0x3c); sensor_write(0x61, 0x70); sensor_write(0x62, 0x80); sensor_write(0x7c, 0x05); sensor_write(0x20, 0x80); sensor_write(0x28, 0x30); sensor_write(0x6c, 0x00); sensor_write(0x6d, 0x80); sensor_write(0x6e, 0x00); sensor_write(0x70, 0x02); sensor_write(0x71, 0x94); sensor_write(0x73, 0xc1); sensor_write(0x3d, 0x36); sensor_write(0x5a, 0x57); // banding sensor_write(0x4f, 0xbb); // 50hz sensor_write(0x50, 0x9c); // 60hz sensor_write(0xff, 0x00); // page 0 sensor_write(0xe5, 0x7f); sensor_write(0xf9, 0xc0); sensor_write(0x41, 0x24); sensor_write(0xe0, 0x14); sensor_write(0x76, 0xff); sensor_write(0x33, 0xa0); sensor_write(0x42, 0x20); sensor_write(0x43, 0x18); sensor_write(0x4c, 0x00); sensor_write(0x87, 0xd0); sensor_write(0x88, 0x3f); sensor_write(0xd7, 0x03); sensor_write(0xd9, 0x10); sensor_write(0xd3, 0x82); sensor_write(0xc8, 0x08); sensor_write(0xc9, 0x80); sensor_write(0xff, 0x00); //contrast value sensor_write(0x7c, 0x00); sensor_write(0x7d, 0x04); sensor_write(0x7c, 0x07); sensor_write(0x7d, 0x20); sensor_write(0x7d, 0x24); sensor_write(0x7d, 0x16); sensor_write(0x7d, 0x06); sensor_write(0x90, 0x00); // gamma sensor_write(0x91, 0x0e); sensor_write(0x91, 0x1a); sensor_write(0x91, 0x31); sensor_write(0x91, 0x5a); sensor_write(0x91, 0x69); sensor_write(0x91, 0x75); sensor_write(0x91, 0x7e); sensor_write(0x91, 0x88); sensor_write(0x91, 0x8f); sensor_write(0x91, 0x96); sensor_write(0x91, 0xa3); sensor_write(0x91, 0xaf); sensor_write(0x91, 0xc4); sensor_write(0x91, 0xd7); sensor_write(0x91, 0xe8); sensor_write(0x91, 0x20); sensor_write(0x92, 0x00); sensor_write(0x93, 0x06); sensor_write(0x93, 0xe3); sensor_write(0x93, 0x03); sensor_write(0x93, 0x06); sensor_write(0x93, 0x00); sensor_write(0x93, 0x04); sensor_write(0x93, 0x00); sensor_write(0x93, 0x00); sensor_write(0x93, 0x00); sensor_write(0x93, 0x00); sensor_write(0x93, 0x00); sensor_write(0x93, 0x00); sensor_write(0x93, 0x00); sensor_write(0x96, 0x00); sensor_write(0x97, 0x08); sensor_write(0x97, 0x19); sensor_write(0x97, 0x02); sensor_write(0x97, 0x0c); sensor_write(0x97, 0x24); sensor_write(0x97, 0x30); sensor_write(0x97, 0x28); sensor_write(0x97, 0x26); sensor_write(0x97, 0x02); sensor_write(0x97, 0x98); sensor_write(0x97, 0x80); sensor_write(0x97, 0x00); sensor_write(0x97, 0x00); sensor_write(0xc3, 0xed); sensor_write(0xa4, 0x00); sensor_write(0xa8, 0x00); sensor_write(0xbf, 0x00); sensor_write(0xba, 0xdc); sensor_write(0xbb, 0x08); sensor_write(0xb6, 0x20); sensor_write(0xb8, 0x30); sensor_write(0xb7, 0x20); sensor_write(0xb9, 0x30); sensor_write(0xb3, 0xb4); sensor_write(0xb4, 0xca); sensor_write(0xb5, 0x34); sensor_write(0xb0, 0x46); sensor_write(0xb1, 0x46); sensor_write(0xb2, 0x06); sensor_write(0xc7, 0x00); sensor_write(0xc6, 0x51); sensor_write(0xc5, 0x11); sensor_write(0xc4, 0x5c); sensor_write(0xc0, 0xc8); sensor_write(0xc1, 0x96); sensor_write(0x86, 0x3d); sensor_write(0x50, 0x89); sensor_write(0x51, 0x90); sensor_write(0x52, 0x2c); sensor_write(0x53, 0x00); sensor_write(0x54, 0x00); sensor_write(0x55, 0x88); sensor_write(0x57, 0x00); sensor_write(0x5a, 0xa0); sensor_write(0x5b, 0x78); sensor_write(0x5c, 0x00); sensor_write(0xc3, 0xed); sensor_write(0x7f, 0x00); sensor_write(0xda, 0x00); sensor_write(0xe5, 0x1f); sensor_write(0xe1, 0x67); sensor_write(0xe0, 0x00); sensor_write(0xdd, 0x7f); sensor_write(0x05, 0x00); sensor_write(0xff, 0x01); // page 1 sensor_write(0x3d, 0x34); // pll sensor_write(0xff, 0x00); // page 0 return sensor_write(0xeb, 0x3a); }
static irqreturn_t sensor_interrupt_handler(int irq, void *pri) { int ret; u8 status; struct sensor_data *data = (struct sensor_data *)pri; SENSOR_DBG(DBG_LEVEL1, "%s", data->client->name); mutex_lock(&data->lock); ret = sensor_read(data, REG_INTERRUPT, 1, &status); if (ret < 0) goto out; if (status & PS_FLAG) { u8 val; int delay; SENSOR_DBG(DBG_LEVEL3, "PS irq:%02x", status); ret = sensor_read(data, REG_PROX_DATA, 1, &val); if (ret < 0) goto out; if (val > data->ps_threshold) { SENSOR_DBG(DBG_LEVEL3, "PS near:%02x", val); input_report_abs(data->input_ps, ABS_X, 0); input_sync(data->input_ps); /*change threshold to avoid interrupt and schedule delaywork to poll near event*/ ret = sensor_write(data, REG_PROX_HT, 0xff); if (ret < 0) goto out; delay = msecs_to_jiffies(data->interval); schedule_delayed_work(&data->work_ps, delay); } else { SENSOR_DBG(DBG_LEVEL3, "Why here PS far:%02x", val); input_report_abs(data->input_ps, ABS_X, 1); input_sync(data->input_ps); sensor_write(data, REG_PROX_HT, data->ps_threshold); } } if (status & ALS_FLAG) { u8 raw[2]; int val, low, high; SENSOR_DBG(DBG_LEVEL3, "ALS irq:%02x", status); ret = sensor_read(data, REG_ALSIR_DT1, 2, raw); if (ret < 0) goto out; val = raw[0] + ((raw[1] & 0xf) << 8); low = val * 98 /100; high = val * 102 /100; if (high == val) high += 1; ret = sensor_write(data, REG_ALSIR_TH1, low & 0xff); if (ret < 0) goto out; ret = sensor_write(data, REG_ALSIR_TH2, ((low >> 8) & 0xf) | ((high & 0xf) << 4)); if (ret < 0) goto out; ret = sensor_write(data, REG_ALSIR_TH3, high >> 4); if (ret < 0) goto out; SENSOR_DBG(DBG_LEVEL2, "ALS data:%08x", val); input_report_abs(data->input_als, ABS_X, val); input_sync(data->input_als); }
static int sensor_ae_transfer(struct i2c_client *client) { //unsigned int prev_line_len,cap_line_len,shutter; struct generic_sensor *sensor = to_generic_sensor(client); struct specific_sensor *spsensor = to_specific_sensor(sensor); int preview_ae_integration, capture_ae_integration; int capture_pixel; u8 ret_h,ret_l; int val_h, val_l; mdelay(100); sensor_read(client, 0x3200, &ret_h); val_h=ret_h; sensor_write(client, 0x3200, ret_h&0xfd); sensor_read(client, 0x3201, &ret_l); val_l=ret_l; sensor_write(client, 0x3201, ret_l&0xdf); //stop ae awb sensor_read(client,0x300a, &ret_h); sensor_read(client,0x300b, &ret_l); capture_pixel = (ret_l&0x0F) | ((ret_h<<8)&0xF0); preview_ae_integration = spsensor->parameter.preview_exposure*spsensor->parameter.PreviewDummyPixels; capture_ae_integration = preview_ae_integration/capture_pixel; //write back ae sensor_write(client,0x3012,(capture_ae_integration>>8)&0x0F); sensor_write(client,0x3013,capture_ae_integration&0x0F); //write back AGC Gain for preview sensor_write(client,0x3014, spsensor->parameter.preview_gain_dr); sensor_write(client,0x3015, spsensor->parameter.preview_gain_ar); sensor_write(client,0x3016, spsensor->parameter.preview_gain_dgr); sensor_write(client,0x3017, spsensor->parameter.preview_gain_agr); sensor_write(client,0x3018, spsensor->parameter.preview_gain_dgb); sensor_write(client,0x3019, spsensor->parameter.preview_gain_agb); sensor_write(client,0x301a, spsensor->parameter.preview_gain_db); sensor_write(client,0x301b, spsensor->parameter.preview_gain_ab); sensor_write(client,0x301c, spsensor->parameter.preview_gain_dglobal); sensor_write(client,0x301d, spsensor->parameter.preview_gain_aglobal); #if 0 sensor_write(client,0x3290, (spsensor->parameter.preview_awb_r>>8)&0x01); sensor_write(client,0x3291, spsensor->parameter.preview_awb_r&0x0F); sensor_write(client,0x3296, (spsensor->parameter.preview_awb_b>>8)&0x01 ); sensor_write(client,0x3297, spsensor->parameter.preview_awb_b&0x0F ); #endif //sensor_write(client, 0x3200, val_h); //sensor_write(client, 0x3201, val_l); //enable ae awb return 0; }
static int sensor_set_mode(struct sensor_data *data, int state) { int ret = 0; u8 val; SENSOR_DBG(DBG_LEVEL2, "%s change state from %08x to %08x", data->client->name, data->state, state); if ((data->state & PS_STATE_FLAG) != (state & PS_STATE_FLAG)) { if ((state & PS_STATE_FLAG) == PS_ENABLE) { SENSOR_DBG(DBG_LEVEL3, "enable ps"); //ret = sensor_write(data, REG_PROX_LT, 0x64); ret = sensor_write(data, REG_PROX_LT, data->ps_threshold); if (ret < 0) goto out; //ret = sensor_write(data, REG_PROX_HT, 0x08); ret = sensor_write(data, REG_PROX_HT, data->ps_threshold); if (ret < 0) goto out; ret = sensor_read(data, REG_CONFIGURE, 1, &val); if (ret < 0) goto out; ret = sensor_write(data, REG_CONFIGURE, val | 0x80); if (ret < 0) goto out; data->state |= PS_ENABLE; } else { SENSOR_DBG(DBG_LEVEL3, "disable ps"); ret = sensor_read(data, REG_CONFIGURE, 1, &val); if (ret < 0) goto out; ret = sensor_write(data, REG_CONFIGURE, val & 0x7f); if (ret < 0) goto out; data->state &= (~PS_ENABLE); } } if ((data->state & ALS_STATE_FLAG) != (state & ALS_STATE_FLAG)) { if ((state & ALS_STATE_FLAG) == ALS_ENABLE) { SENSOR_DBG(DBG_LEVEL3, "enable als"); ret = sensor_write(data, REG_ALSIR_TH1, 0x64); if (ret < 0) goto out; ret = sensor_write(data, REG_ALSIR_TH2, 0x08); if (ret < 0) goto out; ret = sensor_write(data, REG_ALSIR_TH3, 0x3e); if (ret < 0) goto out; ret = sensor_read(data, REG_CONFIGURE, 1, &val); if (ret < 0) goto out; ret = sensor_write(data, REG_CONFIGURE, val | 0x04); if (ret < 0) goto out; data->state |= ALS_ENABLE; } else { SENSOR_DBG(DBG_LEVEL3, "disable als"); ret = sensor_read(data, REG_CONFIGURE, 1, &val); if (ret < 0) goto out; ret = sensor_write(data, REG_CONFIGURE, val & 0xfb); if (ret < 0) goto out; data->state &= (~ALS_ENABLE); } } out: return ret; }
static int sensor_flip_cb(struct i2c_client *client, int flip) { char val1,val2,val3; int err = 0; SENSOR_DG("flip: %d",flip); if (flip) { sensor_write(client, 0xf0, 0); err = sensor_read(client,0x0f,&val1); err = sensor_read(client,0x45,&val2); err = sensor_read(client,0x47,&val3); if(err ==0){ if((val1 == 0xb2) && (val2 == 0x27) && (val3 == 0x2c)){//normal err = sensor_write(client, 0x0f, 0x92); err = sensor_write(client, 0x45, 0x25); err = sensor_write(client, 0x47, 0x24); }else if((val1 == 0xa2) && (val2 == 0x26) && (val3 == 0x28)){//h_mir err = sensor_write(client, 0x0f, 0x82); err = sensor_write(client, 0x45, 0x24); err = sensor_write(client, 0x47, 0x20); }else if((val1 == 0x92) && (val2 == 0x25) && (val3 == 0x24)){//v_flip err = sensor_write(client, 0x0f, 0xb2); err = sensor_write(client, 0x45, 0x27); err = sensor_write(client, 0x47, 0x2c); }else if((val1 == 0x82) && (val2 == 0x24) && (val3 == 0x20)){//h_v_mir err = sensor_write(client, 0x0f, 0xa2); err = sensor_write(client, 0x45, 0x26); err = sensor_write(client, 0x47, 0x28); } } } else { //do nothing } return err; }
ret = sensor_write(data, REG_ALSIR_TH2, ((low >> 8) & 0xf) | ((high & 0xf) << 4)); if (ret < 0) goto out; ret = sensor_write(data, REG_ALSIR_TH3, high >> 4); if (ret < 0) goto out; SENSOR_DBG(DBG_LEVEL2, "ALS data:%08x", val); input_report_abs(data->input_als, ABS_X, val); input_sync(data->input_als); } /*clear both ps and als flag bit7, bit3*/ ret = sensor_write(data, REG_INTERRUPT, status & 0x77); if (ret < 0) { dev_err(&data->client->dev, "sensor_write returns %d\n", ret); } out: mutex_unlock(&data->lock); return IRQ_HANDLED; } static int sensor_get_data_init(struct sensor_data *data) { int ret; SENSOR_DBG(DBG_LEVEL1, "%s", data->client->name); ret = gpio_request(data->gpio_int, DRIVER_NAME);