From 08fecff12c6e1bbd743a88ec7021234f28c64aa4 Mon Sep 17 00:00:00 2001 From: "lw@rock-chips.com" Date: Fri, 15 Jun 2012 20:52:40 +0800 Subject: [PATCH] fix sensor stk3171's problem --- drivers/input/sensors/lsensor/ls_stk3171.c | 55 +++++++++++++++------- drivers/input/sensors/psensor/ps_stk3171.c | 39 ++++++++------- drivers/input/sensors/sensor-dev.c | 6 ++- 3 files changed, 65 insertions(+), 35 deletions(-) diff --git a/drivers/input/sensors/lsensor/ls_stk3171.c b/drivers/input/sensors/lsensor/ls_stk3171.c index 307e148291f5..ef4f1fc3f048 100755 --- a/drivers/input/sensors/lsensor/ls_stk3171.c +++ b/drivers/input/sensors/lsensor/ls_stk3171.c @@ -62,8 +62,8 @@ #define ALS_2T_200MS (1<<2) #define ALS_4T_400MS (2<<2) #define ALS_8T_800MS (3<<2) -#define ALS_RANGE_57671 (0<<5) -#define ALS_RANGE_28836 (1<<5) +#define ALS_RANGE_57671 (0<<6) +#define ALS_RANGE_28836 (1<<6) //PS_CMD #define PS_SD_ENABLE (0<<0) @@ -74,18 +74,19 @@ #define PS_15T_3MS (1<<2) #define PS_20T_4MS (2<<2) #define PS_25T_5MS (3<<2) -#define PS_CUR_100MA (0<<3) -#define PS_CUR_200MA (1<<3) -#define PS_SLP_10MS (0<<4) -#define PS_SLP_30MS (1<<4) -#define PS_SLP_90MS (2<<4) -#define PS_SLP_270MS (3<<4) -#define TRIG_PS_OR_LS (0<<5) -#define TRIG_PS_AND_LS (1<<5) +#define PS_CUR_100MA (0<<4) +#define PS_CUR_200MA (1<<4) +#define PS_SLP_10MS (0<<5) +#define PS_SLP_30MS (1<<5) +#define PS_SLP_90MS (2<<5) +#define PS_SLP_270MS (3<<5) +#define TRIG_PS_OR_LS (0<<7) +#define TRIG_PS_AND_LS (1<<7) //STA_TUS -#define STA_PS_INT (1<<4) -#define STA_ALS_INT (1<<3) +#define STA_PS_INT (1<<5) +#define STA_ALS_INT (1<<4) + /****************operate according to sensor chip:start************/ @@ -116,6 +117,9 @@ static int sensor_active(struct i2c_client *client, int enable, int rate) if(result) printk("%s:fail to active sensor\n",__func__); + if(enable) + sensor->ops->report(sensor->client); + return result; } @@ -143,8 +147,21 @@ static int sensor_init(struct i2c_client *client) return result; } + result = sensor_write_reg(client, ALS_THDH1, 0);//it is important,if not then als can not trig intterupt + if(result) + { + printk("%s:line=%d,error\n",__func__,__LINE__); + return result; + } - sensor->ops->ctrl_data |= (ALS_1T_100MS | ALS_RANGE_28836); + result = sensor_write_reg(client, ALS_THDH2, 0); + if(result) + { + printk("%s:line=%d,error\n",__func__,__LINE__); + return result; + } + + sensor->ops->ctrl_data |= ALS_1T_100MS; if(sensor->pdata->irq_enable) sensor->ops->ctrl_data |= ALS_INT_ENABLE; @@ -165,7 +182,7 @@ static int sensor_init(struct i2c_client *client) static int light_report_value(struct input_dev *input, int data) { unsigned char index = 0; - if(data <= 10){ + if(data <= 100){ index = 0;goto report; } else if(data <= 1600){ @@ -215,15 +232,20 @@ static int sensor_report_value(struct i2c_client *client) memset(buffer, 0, 2); - result = sensor_rx_data(client, buffer, sensor->ops->read_len); + 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 = (short) (((buffer[1]) << 8) | buffer[0]); + 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) { @@ -244,7 +266,6 @@ static int sensor_report_value(struct i2c_client *client) } } - DBG("%s:%s result=0x%x,index=%d\n",__func__,sensor->ops->name, value,index); return result; } diff --git a/drivers/input/sensors/psensor/ps_stk3171.c b/drivers/input/sensors/psensor/ps_stk3171.c index e5b39eedc97e..c7ce75dd7861 100755 --- a/drivers/input/sensors/psensor/ps_stk3171.c +++ b/drivers/input/sensors/psensor/ps_stk3171.c @@ -62,8 +62,8 @@ #define ALS_2T_200MS (1<<2) #define ALS_4T_400MS (2<<2) #define ALS_8T_800MS (3<<2) -#define ALS_RANGE_57671 (0<<5) -#define ALS_RANGE_28836 (1<<5) +#define ALS_RANGE_57671 (0<<6) +#define ALS_RANGE_28836 (1<<6) //PS_CMD #define PS_SD_ENABLE (0<<0) @@ -74,18 +74,18 @@ #define PS_15T_3MS (1<<2) #define PS_20T_4MS (2<<2) #define PS_25T_5MS (3<<2) -#define PS_CUR_100MA (0<<3) -#define PS_CUR_200MA (1<<3) -#define PS_SLP_10MS (0<<4) -#define PS_SLP_30MS (1<<4) -#define PS_SLP_90MS (2<<4) -#define PS_SLP_270MS (3<<4) -#define TRIG_PS_OR_LS (0<<5) -#define TRIG_PS_AND_LS (1<<5) +#define PS_CUR_100MA (0<<4) +#define PS_CUR_200MA (1<<4) +#define PS_SLP_10MS (0<<5) +#define PS_SLP_30MS (1<<5) +#define PS_SLP_90MS (2<<5) +#define PS_SLP_270MS (3<<5) +#define TRIG_PS_OR_LS (0<<7) +#define TRIG_PS_AND_LS (1<<7) //STA_TUS -#define STA_PS_INT (1<<4) -#define STA_ALS_INT (1<<3) +#define STA_PS_INT (1<<5) +#define STA_ALS_INT (1<<4) /****************operate according to sensor chip:start************/ @@ -116,6 +116,9 @@ static int sensor_active(struct i2c_client *client, int enable, int rate) if(result) printk("%s:fail to active sensor\n",__func__); + if(enable) + sensor->ops->report(sensor->client); + return result; } @@ -144,7 +147,8 @@ static int sensor_init(struct i2c_client *client) } - sensor->ops->ctrl_data |= (PS_15T_3MS| PS_SLP_90MS | TRIG_PS_OR_LS); + sensor->ops->ctrl_data |= PS_15T_3MS| PS_SLP_90MS; + sensor->ops->ctrl_data &= ~TRIG_PS_AND_LS; if(sensor->pdata->irq_enable) sensor->ops->ctrl_data |= PS_INT_ENABLE; @@ -179,17 +183,20 @@ static int sensor_report_value(struct i2c_client *client) memset(buffer, 0, 1); - result = sensor_rx_data(client, buffer, sensor->ops->read_len); + 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]; - input_report_abs(sensor->input_dev, ABS_DISTANCE, value?0:1); + input_report_abs(sensor->input_dev, ABS_DISTANCE, (value>>2)?0:1); input_sync(sensor->input_dev); - DBG("%s:%s result=0x%x,index=%d\n",__func__,sensor->ops->name, value,value?0:1); + DBG("%s:%s result=0x%x,index=%d\n",__func__,sensor->ops->name, value,(value>>2)?0:1); if(sensor->pdata->irq_enable) { diff --git a/drivers/input/sensors/sensor-dev.c b/drivers/input/sensors/sensor-dev.c index 43673c49065f..3b20fcbb33ff 100755 --- a/drivers/input/sensors/sensor-dev.c +++ b/drivers/input/sensors/sensor-dev.c @@ -293,8 +293,8 @@ static int sensor_irq_init(struct i2c_client *client) gpio_pull_updown(client->irq, PullEnable); irq = gpio_to_irq(client->irq); - //result = request_irq(irq, sensor_interrupt, sensor->ops->trig, client->dev.driver->name, sensor); - result = request_threaded_irq(irq, NULL, sensor_interrupt, sensor->ops->trig, client->dev.driver->name, sensor); + //result = request_irq(irq, sensor_interrupt, sensor->ops->trig, sensor->ops->name, sensor); + result = request_threaded_irq(irq, NULL, sensor_interrupt, sensor->ops->trig, sensor->ops->name, sensor); if (result) { printk(KERN_ERR "%s:fail to request irq = %d, ret = 0x%x\n",__func__, irq, result); goto error; @@ -1284,9 +1284,11 @@ static const struct i2c_device_id sensor_id[] = { /*light sensor*/ {"lightsensor", LIGHT_ID_ALL}, {"light_al3006", LIGHT_ID_AL3006}, + {"ls_stk3171", LIGHT_ID_STK3171}, /*proximity sensor*/ {"psensor", PROXIMITY_ID_ALL}, {"proximity_al3006", PROXIMITY_ID_AL3006}, + {"ps_stk3171", PROXIMITY_ID_STK3171}, /*temperature*/ {"temperature", TEMPERATURE_ID_ALL}, {}, -- 2.34.1