static int sensor_report_value(struct i2c_client *client) { struct sensor_private_data *sensor = (struct sensor_private_data *) i2c_get_clientdata(client); int result = 0; char msb = 0, lsb = 0; int index = 0; sensor->client->addr = CM3217_ADDR_DATA_LSB; sensor_rx_data_normal(sensor->client, &lsb, 1); sensor->client->addr = CM3217_ADDR_DATA_MSB; sensor_rx_data_normal(sensor->client, &msb, 1); result = ((msb << 8) | lsb) & 0xffff; index = light_report_value(sensor->input_dev, result); DBG("%s:%s result=0x%x,index=%d\n",__func__,sensor->ops->name, result,index); if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0)) //read sensor intterupt status register { result= sensor_read_reg(client, sensor->ops->int_status_reg); if(result) { printk("%s:fail to clear sensor int status,ret=0x%x\n",__func__,result); } } return result; }
static int sensor_init(struct i2c_client *client) { struct sensor_private_data *sensor = (struct sensor_private_data *) i2c_get_clientdata(client); int result = 0; char info = 0; this_client = client; result = sensor->ops->active(client,0,0); if(result) { printk("%s:line=%d,error\n",__func__,__LINE__); return result; } sensor->status_cur = SENSOR_OFF; info = sensor_read_reg(client, AK8963_REG_INFO); if((info & (0x0f<<3)) != AK8963_INFO_DATA) { printk("%s:info=0x%x,it is not %s\n",__func__, info, sensor->ops->name); return -1; } result = misc_register(&compass_dev_device); if (result < 0) { printk("%s:fail to register misc device %s\n", __func__, compass_dev_device.name); result = -1; } DBG("%s:status_cur=%d\n",__func__, sensor->status_cur); return result; }
static ssize_t i2c_get_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { int len; int arg = 0; if (*ppos) return 0; /* the end */ //+ parsing...... len=(count > DBG_TXT_BUF_SIZE-1)?(DBG_TXT_BUF_SIZE-1):(count); if (copy_from_user(debugTxtBuf,buf,len)) return -EFAULT; debugTxtBuf[len]=0; //add string end sscanf(debugTxtBuf, "%x", &arg); *ppos=len; sensor_read_reg(imx219_asus_s_ctrl.sensor_i2c_client->client, arg, (u16 *)&i2c_get_value); CDBG("the value is 0x%x\n", i2c_get_value); return len; /* the end */ }
static int sensor_report_value(struct i2c_client *client) { struct sensor_private_data *sensor = (struct sensor_private_data *) i2c_get_clientdata(client); int result = 0; char msb = 0, lsb = 0; char data[2] = {0}; unsigned short value = 0; //sensor->client->addr = CM3232_ADDR_DATA; data[0] = CM3232_ADDR_DATA; sensor_rx_data(sensor->client, data, 2); value = (data[1] << 8) | data[0] ; DBG("%s:result=%d\n",__func__,value); //printk("%s:result=%d\n",__func__,value); light_report_value(sensor->input_dev, value); if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0)) //read sensor intterupt status register { result= sensor_read_reg(client, sensor->ops->int_status_reg); if(result) { printk("%s:fail to clear sensor int status,ret=0x%x\n",__func__,result); } } return result; }
static int sensor_active(struct i2c_client *client, int enable, int rate) { struct sensor_private_data *sensor = (struct sensor_private_data *) i2c_get_clientdata(client); int result = 0; int status = 0; sensor->ops->ctrl_data = sensor_read_reg(client, sensor->ops->ctrl_reg); //register setting according to chip datasheet if(enable) { sensor->ops->ctrl_data &= 0x1f; sensor->ops->ctrl_data |= COMMMAND1_OPMODE_ALS_CONTINUE; } else { sensor->ops->ctrl_data &= 0x1f; //sensor->ops->ctrl_data |= COMMMAND1_OPMODE_POWER_DOWN; } DBG("%s:reg=0x%x,reg_ctrl=0x%x,enable=%d\n",__func__,sensor->ops->ctrl_reg, sensor->ops->ctrl_data, enable); result = sensor_write_reg(client, sensor->ops->ctrl_reg, sensor->ops->ctrl_data); if(result) printk("%s:fail to active sensor\n",__func__); if(enable) sensor->ops->report(sensor->client); return result; }
static int sensor_active(struct i2c_client *client, int enable, int rate) { struct sensor_private_data *sensor = (struct sensor_private_data *) i2c_get_clientdata(client); int result = 0; int status = 0; sensor->ops->ctrl_data = sensor_read_reg(client, sensor->ops->ctrl_reg); //register setting according to chip datasheet if(!enable) { status = PS_SD_DISABLE; sensor->ops->ctrl_data |= status; } else { status = ~PS_SD_DISABLE; sensor->ops->ctrl_data &= status; } DBG("%s:reg=0x%x,reg_ctrl=0x%x,enable=%d\n",__func__,sensor->ops->ctrl_reg, sensor->ops->ctrl_data, enable); result = sensor_write_reg(client, sensor->ops->ctrl_reg, sensor->ops->ctrl_data); if(result) printk("%s:fail to active sensor\n",__func__); if(enable) sensor->ops->report(sensor->client); return result; }
int ov7690_set_effect_negative(struct i2c_client *client) { unsigned char temp; temp = sensor_read_reg(client, 0x81); temp |= 0x20; sensor_write_reg(client, 0x81, temp); sensor_write_reg(client, 0x28, 0x80); sensor_write_reg(client, 0xd2, 0x00); return 0; }
static int sensor_report_value(struct i2c_client *client) { struct sensor_private_data *sensor = (struct sensor_private_data *) i2c_get_clientdata(client); int result = 0; int value = 0; char buffer[2] = {0}; char index = 0; if(sensor->ops->read_len < 2) //sensor->ops->read_len = 2 { printk("%s:lenth is error,len=%d\n",__func__,sensor->ops->read_len); return -1; } memset(buffer, 0, 2); buffer[0] = sensor->ops->read_reg; result = sensor_rx_data(client, buffer, sensor->ops->read_len); if(result) { printk("%s:line=%d,error\n",__func__,__LINE__); return result; } value = (buffer[0] << 8) | buffer[1]; index = light_report_value(sensor->input_dev, value); DBG("%s:%s result=0x%x,index=%d\n",__func__,sensor->ops->name, value,index); if(sensor->pdata->irq_enable) { if(sensor->ops->int_status_reg) { value = sensor_read_reg(client, sensor->ops->int_status_reg); } if(value & STA_ALS_INT) { value &= ~STA_ALS_INT; result = sensor_write_reg(client, sensor->ops->int_status_reg,value); //clear int if(result) { printk("%s:line=%d,error\n",__func__,__LINE__); return result; } } } return result; }
int ov7690_set_effect_green(struct i2c_client *client) { unsigned char temp; temp = sensor_read_reg(client, 0x81); temp |= 0x20; sensor_write_reg(client, 0x81, temp); sensor_write_reg(client, 0x28, 0x00); sensor_write_reg(client, 0xd2, 0x18); sensor_write_reg(client, 0xda, 0x60); sensor_write_reg(client, 0xdb, 0x60); return 0; }
static int sensor_active(struct i2c_client *client, int enable, int rate) { struct sensor_private_data *sensor = (struct sensor_private_data *) i2c_get_clientdata(client); int result = 0; char value = 0; if(enable) sensor_power_updown(client, 1); value = sensor_read_reg(client, sensor->ops->ctrl_reg); //register setting according to chip datasheet if(enable) { if( (value & 0x03) == ONLY_PROX_EN ) { value &= ~0x03; value |= ALL_PROX_ALS_EN; } else if((value & 0x03) == ALL_IDLE ) { value &= ~0x03; value |= ONLY_ALS_EN; } } else { if( (value & 0x03) == ONLY_ALS_EN ) { value &= ~0x03; value |= ALL_IDLE; } else if((value & 0x03) == ALL_PROX_ALS_EN ) { value &= ~0x03; value |= ONLY_PROX_EN; } } sensor->ops->ctrl_data = value; DBG("%s:reg=0x%x,reg_ctrl=0x%x,enable=%d\n",__func__,sensor->ops->ctrl_reg, sensor->ops->ctrl_data, enable); result = sensor_write_reg(client, sensor->ops->ctrl_reg, sensor->ops->ctrl_data); if(result) printk("%s:fail to active sensor\n",__func__); return result; }
static int sensor_report_value(struct i2c_client *client) { struct sensor_private_data *sensor = (struct sensor_private_data *) i2c_get_clientdata(client); int result = 0; char value = 0; char index = 0; if(sensor->pdata->irq_enable) { if(sensor->ops->int_status_reg) { value = sensor_read_reg(client, sensor->ops->int_status_reg); } } value = sensor_read_reg(client, sensor->ops->read_reg); index = light_report_value(sensor->input_dev, value&0x3f); // bit0-5 is ls data; DBG("%s:%s result=0x%x,index=%d\n",__func__,sensor->ops->name, value,index); return result; }
static int sensor_init(struct i2c_client *client) { struct sensor_private_data *sensor = (struct sensor_private_data *) i2c_get_clientdata(client); int result = 0; unsigned char buf[5]; unsigned char data = 0; int i = 0; result = sensor->ops->active(client,0,0); if(result) { printk("%s:line=%d,error\n",__func__,__LINE__); return result; } sensor->status_cur = SENSOR_OFF; buf[0] = 0x07; //27 buf[1] = 0x00; buf[2] = 0x00; buf[3] = 0x20; //0x00 buf[4] = 0x00; for(i=0; i<5; i++) { result = sensor_write_reg(client, sensor->ops->ctrl_reg+i, buf[i]); if(result) { printk("%s:line=%d,error\n",__func__,__LINE__); return result; } } result = sensor_read_reg(client, sensor->ops->ctrl_reg); if (result >= 0) data = result & 0x000F; sensor->ops->ctrl_data = data + ODR100_BW12_5; result = sensor_write_reg(client, sensor->ops->ctrl_reg, sensor->ops->ctrl_data); if(result) { printk("%s:line=%d,error\n",__func__,__LINE__); return result; } return result; }
int cm3511_sensor_probe(void) { int sensor_id=0; cm3511_power_up(); cm3511_reset(); sensor_write_reg(cm3511.client,0x03, 0x00);// sensor_write_reg(cm3511.client,0x01, 0xC1); sensor_write_reg(cm3511.client,0x01, 0xC3);// sensor_write_reg(cm3511.client,0x01, 0xC1); mdelay(50); sensor_write_reg(cm3511.client,0x03, 0x00);// sensor_id = sensor_read_reg(cm3511.client,0x04); cm3511_power_down(); if(sensor_id == 0x81) return 0; dprintk("sensor read is %d",sensor_id); return -1; }
static int sensor_report_value(struct i2c_client *client) { struct sensor_private_data *sensor = (struct sensor_private_data *) i2c_get_clientdata(client); int result = 0; int index = 0; cm3218_read_lux(client,&result); index = light_report_value(sensor->input_dev, result); DBG("%s:%s result=0x%x,index=%d\n",__func__,sensor->ops->name, result,index); if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0)) //read sensor intterupt status register { result= sensor_read_reg(client, sensor->ops->int_status_reg); if(result) { printk("%s:fail to clear sensor int status,ret=0x%x\n",__func__,result); } } return result; }
static int init_read_otp(void){ int i=0; u16 opt_start_addr=imx219_opt_start; int block=2; int bank=0; //static u32 otp_get_value; sensor_write_reg(imx219_asus_s_ctrl.sensor_i2c_client->client,0x0100,0x00);//write standby mode //sensor_read_reg(imx219_asus_s_ctrl.sensor_i2c_client->client, 0x0100, (u16 *)&otp_get_value); //pr_err("init_read_otp +0x0100++ otp_get_value =%x\n",otp_get_value); sensor_write_reg(imx219_asus_s_ctrl.sensor_i2c_client->client,0x3302,0x02);//write OTP write clock //sensor_read_reg(imx219_asus_s_ctrl.sensor_i2c_client->client, 0x3302, (u16 *)&otp_get_value); //pr_err("init_read_otp +0x3302++ otp_get_value =%x\n",otp_get_value); sensor_write_reg(imx219_asus_s_ctrl.sensor_i2c_client->client,0x3303,0x58);//write OTP write clock //sensor_read_reg(imx219_asus_s_ctrl.sensor_i2c_client->client, 0x3303, (u16 *)&otp_get_value); //pr_err("init_read_otp +0x3303++ otp_get_value =%x\n",otp_get_value); sensor_write_reg(imx219_asus_s_ctrl.sensor_i2c_client->client,0x012A,0x18);//write INCK //sensor_read_reg(imx219_asus_s_ctrl.sensor_i2c_client->client, 0x012A, (u16 *)&otp_get_value); //pr_err("init_read_otp +0x012A++ otp_get_value =%x\n",otp_get_value); sensor_write_reg(imx219_asus_s_ctrl.sensor_i2c_client->client,0x012B,0x00);//write INCK //sensor_read_reg(imx219_asus_s_ctrl.sensor_i2c_client->client, 0x012B, (u16 *)&otp_get_value); //pr_err("init_read_otp +0x012B++ otp_get_value =%x\n",otp_get_value); sensor_write_reg(imx219_asus_s_ctrl.sensor_i2c_client->client,0x3300,0x08);//write ECC //sensor_read_reg(imx219_asus_s_ctrl.sensor_i2c_client->client, 0x3300, (u16 *)&otp_get_value); //pr_err("init_read_otp +0x3300++ otp_get_value =%x\n",otp_get_value); sensor_write_reg(imx219_asus_s_ctrl.sensor_i2c_client->client,0x3200,1); sensor_write_reg(imx219_asus_s_ctrl.sensor_i2c_client->client,0x3202,block); sensor_read_reg(imx219_asus_s_ctrl.sensor_i2c_client->client, opt_start_addr+8, (u16 *)&i2c_get_value); pr_err("init_read_otp +++ i2c_get_value =%x\n",i2c_get_value); if( i2c_get_value!=0xa){ block=1; sensor_write_reg(imx219_asus_s_ctrl.sensor_i2c_client->client,0x3200,1); sensor_write_reg(imx219_asus_s_ctrl.sensor_i2c_client->client,0x3202,block); sensor_read_reg(imx219_asus_s_ctrl.sensor_i2c_client->client, opt_start_addr+8, (u16 *)&i2c_get_value); if(i2c_get_value!=0xa){ block=0; sensor_write_reg(imx219_asus_s_ctrl.sensor_i2c_client->client,0x3200,1); sensor_write_reg(imx219_asus_s_ctrl.sensor_i2c_client->client,0x3202,block); sensor_read_reg(imx219_asus_s_ctrl.sensor_i2c_client->client, opt_start_addr+8, (u16 *)&i2c_get_value); if(i2c_get_value!=0xa) return -1; } } for(bank=0;bank<3;bank++){ sensor_write_reg(imx219_asus_s_ctrl.sensor_i2c_client->client,0x3200,1); sensor_write_reg(imx219_asus_s_ctrl.sensor_i2c_client->client,0x3202,block); for(i=0;i<8;i++){ sensor_read_reg(imx219_asus_s_ctrl.sensor_i2c_client->client, opt_start_addr+(bank*8+i), (u16 *)&i2c_get_value); pr_err("init_read_otp page = %d bank=%x addr=%x value=%x\n",block,bank,opt_start_addr+(bank*8+i),i2c_get_value); imx219_asus_otp_value[bank*8+i]=i2c_get_value; } } #ifdef CONFIG_MSMB_CAMERA_DEBUG for(i=0;i<opt_size;i++) printk("imx219_asus_otp_value i=%d =%x\n",i,imx219_asus_otp_value[i]); #endif return 0; }
static int sensor_report_value(struct i2c_client *client) { struct sensor_private_data *sensor = (struct sensor_private_data *) i2c_get_clientdata(client); struct sensor_platform_data *pdata = sensor->pdata; int ret = 0; int x = 0, y = 0, z = 0; struct sensor_axis axis; char buffer[6] = {0}; int i = 0; int value = 0; if(sensor->ops->read_len < 6) //sensor->ops->read_len = 6 { printk("%s:lenth is error,len=%d\n",__func__,sensor->ops->read_len); return -1; } memset(buffer, 0, 6); #if 0 /* Data bytes from hardware xL, xH, yL, yH, zL, zH */ do { buffer[0] = sensor->ops->read_reg; ret = sensor_rx_data(client, buffer, sensor->ops->read_len); if (ret < 0) return ret; } while (0); #else for(i=0; i<6; i++) { //buffer[i] = sensor->ops->read_reg + i; buffer[i] = sensor_read_reg(client, sensor->ops->read_reg + i); } #endif x = (short) (((buffer[1]) << 8) | buffer[0]); y = (short) (((buffer[3]) << 8) | buffer[2]); z = (short) (((buffer[5]) << 8) | buffer[4]); DBG("%s: x=%d y=%d z=%d \n",__func__, x,y,z); if(pdata && pdata->orientation) { axis.x = (pdata->orientation[0])*x + (pdata->orientation[1])*y + (pdata->orientation[2])*z; axis.y = (pdata->orientation[3])*x + (pdata->orientation[4])*y + (pdata->orientation[5])*z; axis.z = (pdata->orientation[6])*x + (pdata->orientation[7])*y + (pdata->orientation[8])*z; } else { axis.x = x; axis.y = y; axis.z = z; } //filter gyro data if((abs(axis.x) > pdata->x_min)||(abs(axis.y) > pdata->y_min)||(abs(axis.z) > pdata->z_min)) { gyro_report_value(client, &axis); /* »¥³âµØ»º´æÊý¾Ý. */ mutex_lock(&(sensor->data_mutex) ); sensor->axis = axis; mutex_unlock(&(sensor->data_mutex) ); } if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0)) //read sensor intterupt status register { value = sensor_read_reg(client, sensor->ops->int_status_reg); DBG("%s:sensor int status :0x%x\n",__func__,value); } return ret; }
static int sensor_report_value(struct i2c_client *client) { struct sensor_private_data *sensor = (struct sensor_private_data *) i2c_get_clientdata(client); char buffer[8] = {0}; unsigned char *stat; unsigned char *stat2; int ret = 0; char value = 0; #ifdef SENSOR_DEBUG_TYPE int i; #endif if(sensor->ops->read_len < 8) //sensor->ops->read_len = 8 { printk("%s:lenth is error,len=%d\n",__func__,sensor->ops->read_len); return -1; } memset(buffer, 0, 8); /* Data bytes from hardware xL, xH, yL, yH, zL, zH */ do { *buffer = sensor->ops->read_reg; ret = sensor_rx_data(client, buffer, sensor->ops->read_len); if (ret < 0) return ret; } while (0); stat = &buffer[0]; stat2 = &buffer[7]; /* * ST : data ready - * Measurement has been completed and data is ready to be read. */ if ((*stat & 0x01) != 0x01) { DBG(KERN_ERR "%s:ST is not set\n",__func__); return -1; } /* * ST2 : data error - * occurs when data read is started outside of a readable period; * data read would not be correct. * Valid in continuous measurement mode only. * In single measurement mode this error should not occour but we * stil account for it and return an error, since the data would be * corrupted. * DERR bit is self-clearing when ST2 register is read. */ if (*stat2 & 0x04) { DBG(KERN_ERR "%s:compass data error\n",__func__); return -2; } /* * ST2 : overflow - * the sum of the absolute values of all axis |X|+|Y|+|Z| < 2400uT. * This is likely to happen in presence of an external magnetic * disturbance; it indicates, the sensor data is incorrect and should * be ignored. * An error is returned. * HOFL bit clears when a new measurement starts. */ if (*stat2 & 0x08) { DBG(KERN_ERR "%s:compass data overflow\n",__func__); return -3; } /* »¥³âµØ»º´æÊý¾Ý. */ mutex_lock(&sensor->data_mutex); memcpy(sensor->sensor_data, buffer, sensor->ops->read_len); mutex_unlock(&sensor->data_mutex); #ifdef SENSOR_DEBUG_TYPE DBG("%s:",__func__); for(i=0; i<sensor->ops->read_len; i++) DBG("%d,",buffer[i]); DBG("\n"); #endif if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0)) //read sensor intterupt status register { value = sensor_read_reg(client, sensor->ops->int_status_reg); DBG("%s:sensor int status :0x%x\n",__func__,value); } //trigger next measurement ret = sensor_write_reg(client, sensor->ops->ctrl_reg, sensor->ops->ctrl_data); if(ret) { printk(KERN_ERR "%s:fail to set ctrl_data:0x%x\n",__func__,sensor->ops->ctrl_data); return ret; } return ret; }