From 9ea4a68985bc022fd1ddf7a05fb5b07fc2b9ee81 Mon Sep 17 00:00:00 2001 From: lw Date: Fri, 30 Mar 2012 13:13:23 +0800 Subject: [PATCH] rk30:modify light sensor slave address and add config --- arch/arm/configs/rk30_sdk_defconfig | 1 + arch/arm/mach-rk30/board-rk30-sdk.c | 2 +- drivers/input/lightsensor/cm3217.c | 26 +++++++++++++++----------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/arch/arm/configs/rk30_sdk_defconfig b/arch/arm/configs/rk30_sdk_defconfig index 3655c2ba9b92..5beaf941fdf0 100755 --- a/arch/arm/configs/rk30_sdk_defconfig +++ b/arch/arm/configs/rk30_sdk_defconfig @@ -232,6 +232,7 @@ CONFIG_G_SENSOR_DEVICE=y CONFIG_GYRO_SENSOR_DEVICE=y CONFIG_GYRO_L3G4200D=y CONFIG_LIGHT_SENSOR_DEVICE=y +CONFIG_LS_CM3217=y # CONFIG_SERIO is not set # CONFIG_CONSOLE_TRANSLATIONS is not set # CONFIG_LEGACY_PTYS is not set diff --git a/arch/arm/mach-rk30/board-rk30-sdk.c b/arch/arm/mach-rk30/board-rk30-sdk.c index 8859ac03582b..fe44cc9b1a95 100755 --- a/arch/arm/mach-rk30/board-rk30-sdk.c +++ b/arch/arm/mach-rk30/board-rk30-sdk.c @@ -1036,7 +1036,7 @@ static struct i2c_board_info __initdata i2c2_info[] = { #if defined (CONFIG_LS_CM3217) { .type = "lightsensor", - .addr = 0x20, + .addr = 0x10, .flags = 0, .irq = CM3217_IRQ_PIN, .platform_data = &cm3217_info, diff --git a/drivers/input/lightsensor/cm3217.c b/drivers/input/lightsensor/cm3217.c index 5dcbb0d1952a..461b7faf8276 100755 --- a/drivers/input/lightsensor/cm3217.c +++ b/drivers/input/lightsensor/cm3217.c @@ -33,12 +33,12 @@ #endif #define CM3217_I2C_RATE (200*1000) -#define CM3217_ADDR_COM1 0x20 -#define CM3217_ADDR_COM2 0x22 -#define CM3217_ADDR_DATA_MSB 0x21 -#define CM3217_ADDR_DATA_LSB 0x23 +#define CM3217_ADDR_COM1 0x10 +#define CM3217_ADDR_COM2 0x11 +#define CM3217_ADDR_DATA_MSB 0x10 +#define CM3217_ADDR_DATA_LSB 0x11 -#define CM3217_COM1_VALUE 0xA4 // (GAIN1:GAIN0)=10, (IT_T1:IT_TO)=01,WMD=0,SD=0, +#define CM3217_COM1_VALUE 0xA7 // (GAIN1:GAIN0)=10, (IT_T1:IT_TO)=01,WMD=1,SD=1, #define CM3217_COM2_VALUE 0xA0 //100ms @@ -74,7 +74,7 @@ static int cm3217_command_set(struct i2c_client *client, char *buf, int num) static int cm3217_command_get(struct i2c_client *client, char *buf, int num) { int ret = 0; - ret = i2c_master_normal_send(client, buf, num, CM3217_I2C_RATE); + ret = i2c_master_normal_recv(client, buf, num, CM3217_I2C_RATE); return (ret == num) ? 0 : ret; } @@ -90,7 +90,8 @@ static int cm3217_start(struct cm3217_data *data) //if(cm3217->power_pin != INVALID_GPIO) //gpio_direction_output(cm3217->power_pin,0);//level = 0 Sensor ON - buf = CM3217_COM1_VALUE | 0x01 ; //SD=1 + buf = CM3217_COM1_VALUE & 0xfe ; //SD=0 + cm3217->client->addr = CM3217_ADDR_COM1; cm3217_command_set(cm3217->client, &buf, 1); cm3217->status = SENSOR_ON; @@ -110,7 +111,8 @@ static int cm3217_stop(struct cm3217_data *data) //if(cm3217->power_pin != INVALID_GPIO) //gpio_direction_output(cm3217->power_pin,1);//level = 1 Sensor OFF - buf = CM3217_COM1_VALUE & 0xfe ; //SD=0 + buf = CM3217_COM1_VALUE | 0x01 ; //SD=1 + cm3217->client->addr = CM3217_ADDR_COM1; cm3217_command_set(cm3217->client, &buf, 1); cm3217->status = SENSOR_OFF; @@ -270,7 +272,9 @@ static int cm3217_probe(struct i2c_client *client, const struct i2c_device_id *i glight = cm3217; //init cm3217 - cm3217_command_set(client, &com1, 1); + client->addr = CM3217_ADDR_COM1; + cm3217_command_set(client, &com1, 1); + client->addr = CM3217_ADDR_COM2; cm3217_command_set(client, &com2, 1); cm3217->input = input_allocate_device(); @@ -281,7 +285,7 @@ static int cm3217_probe(struct i2c_client *client, const struct i2c_device_id *i } set_bit(EV_ABS, cm3217->input->evbit); /* light sensor data */ - input_set_abs_params(cm3217->input, ABS_MISC, 0, 0x3ff, 0, 0); + input_set_abs_params(cm3217->input, ABS_MISC, 0, 10, 0, 0); cm3217->input->name = "lightsensor"; err = input_register_device(cm3217->input); @@ -304,7 +308,7 @@ static int cm3217_probe(struct i2c_client *client, const struct i2c_device_id *i goto exit_misc_register_fail; } printk("lightsensor cm3217 driver created !\n"); - //cm3217_start(light); + //cm3217_start(cm3217); #ifdef CONFIG_HAS_EARLYSUSPEND cm3217_early_suspend.suspend = cm3217_suspend; cm3217_early_suspend.resume = cm3217_resume; -- 2.34.1