From: lw@rock-chips.com Date: Wed, 8 Aug 2012 06:59:10 +0000 (+0800) Subject: modify sensors driver to support selecting all items one time X-Git-Tag: firefly_0821_release~8922^2~47 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=3403ddf5b23539e42c9cf1788b5d18f2985c0bd0;p=firefly-linux-kernel-4.4.55.git modify sensors driver to support selecting all items one time --- diff --git a/drivers/input/sensors/accel/kxtik.c b/drivers/input/sensors/accel/kxtik.c index ba131f729536..d251f44c0a8b 100755 --- a/drivers/input/sensors/accel/kxtik.c +++ b/drivers/input/sensors/accel/kxtik.c @@ -216,7 +216,7 @@ static int sensor_report_value(struct i2c_client *client) return ret; } -struct sensor_operate gsensor_ops = { +struct sensor_operate gsensor_kxtik_ops = { .name = "kxtik", .type = SENSOR_TYPE_ACCEL, //sensor type and it should be correct .id_i2c = ACCEL_ID_KXTIK, //i2c id number @@ -237,14 +237,13 @@ struct sensor_operate gsensor_ops = { /****************operate according to sensor chip:end************/ //function name should not be changed -struct sensor_operate *gsensor_get_ops(void) +static struct sensor_operate *gsensor_get_ops(void) { - return &gsensor_ops; + return &gsensor_kxtik_ops; } -EXPORT_SYMBOL(gsensor_get_ops); -static int __init gsensor_init(void) +static int __init gsensor_kxtik_init(void) { struct sensor_operate *ops = gsensor_get_ops(); int result = 0; @@ -254,7 +253,7 @@ static int __init gsensor_init(void) return result; } -static void __exit gsensor_exit(void) +static void __exit gsensor_kxtik_exit(void) { struct sensor_operate *ops = gsensor_get_ops(); int type = ops->type; @@ -262,7 +261,7 @@ static void __exit gsensor_exit(void) } -module_init(gsensor_init); -module_exit(gsensor_exit); +module_init(gsensor_kxtik_init); +module_exit(gsensor_kxtik_exit); diff --git a/drivers/input/sensors/accel/lis3dh.c b/drivers/input/sensors/accel/lis3dh.c index ac9c059f71ad..8ce14bbe6cd6 100755 --- a/drivers/input/sensors/accel/lis3dh.c +++ b/drivers/input/sensors/accel/lis3dh.c @@ -293,7 +293,7 @@ static int sensor_report_value(struct i2c_client *client) return ret; } -struct sensor_operate gsensor_ops = { +struct sensor_operate gsensor_lis3dh_ops = { .name = "lis3dh", .type = SENSOR_TYPE_ACCEL, //sensor type and it should be correct .id_i2c = ACCEL_ID_LIS3DH, //i2c id number @@ -314,14 +314,13 @@ struct sensor_operate gsensor_ops = { /****************operate according to sensor chip:end************/ //function name should not be changed -struct sensor_operate *gsensor_get_ops(void) +static struct sensor_operate *gsensor_get_ops(void) { - return &gsensor_ops; + return &gsensor_lis3dh_ops; } -EXPORT_SYMBOL(gsensor_get_ops); -static int __init gsensor_init(void) +static int __init gsensor_lis3dh_init(void) { struct sensor_operate *ops = gsensor_get_ops(); int result = 0; @@ -331,7 +330,7 @@ static int __init gsensor_init(void) return result; } -static void __exit gsensor_exit(void) +static void __exit gsensor_lis3dh_exit(void) { struct sensor_operate *ops = gsensor_get_ops(); int type = ops->type; @@ -339,7 +338,7 @@ static void __exit gsensor_exit(void) } -module_init(gsensor_init); -module_exit(gsensor_exit); +module_init(gsensor_lis3dh_init); +module_exit(gsensor_lis3dh_exit); diff --git a/drivers/input/sensors/accel/mma8452.c b/drivers/input/sensors/accel/mma8452.c index a5e5f40f2e1a..c489c95ce54a 100755 --- a/drivers/input/sensors/accel/mma8452.c +++ b/drivers/input/sensors/accel/mma8452.c @@ -253,7 +253,7 @@ static int sensor_report_value(struct i2c_client *client) } -struct sensor_operate gsensor_ops = { +struct sensor_operate gsensor_mma8452_ops = { .name = "mma8452", .type = SENSOR_TYPE_ACCEL, //sensor type and it should be correct .id_i2c = ACCEL_ID_MMA845X, //i2c id number @@ -274,14 +274,13 @@ struct sensor_operate gsensor_ops = { /****************operate according to sensor chip:end************/ //function name should not be changed -struct sensor_operate *gsensor_get_ops(void) +static struct sensor_operate *gsensor_get_ops(void) { - return &gsensor_ops; + return &gsensor_mma8452_ops; } -EXPORT_SYMBOL(gsensor_get_ops); -static int __init gsensor_init(void) +static int __init gsensor_mma8452_init(void) { struct sensor_operate *ops = gsensor_get_ops(); int result = 0; @@ -291,7 +290,7 @@ static int __init gsensor_init(void) return result; } -static void __exit gsensor_exit(void) +static void __exit gsensor_mma8452_exit(void) { struct sensor_operate *ops = gsensor_get_ops(); int type = ops->type; @@ -299,8 +298,8 @@ static void __exit gsensor_exit(void) } -module_init(gsensor_init); -module_exit(gsensor_exit); +module_init(gsensor_mma8452_init); +module_exit(gsensor_mma8452_exit); diff --git a/drivers/input/sensors/compass/ak8975.c b/drivers/input/sensors/compass/ak8975.c index a8fbf21efe20..3319618705ae 100755 --- a/drivers/input/sensors/compass/ak8975.c +++ b/drivers/input/sensors/compass/ak8975.c @@ -693,7 +693,7 @@ static struct miscdevice compass_dev_device = .fops = &compass_dev_fops, }; -struct sensor_operate akm8975_ops = { +struct sensor_operate akm8975_akm8975_ops = { .name = "akm8975", .type = SENSOR_TYPE_COMPASS, //it is important .id_i2c = COMPASS_ID_AK8975, @@ -715,15 +715,13 @@ struct sensor_operate akm8975_ops = { /****************operate according to sensor chip:end************/ //function name should not be changed -struct sensor_operate *compass_get_ops(void) +static struct sensor_operate *compass_get_ops(void) { - return &akm8975_ops; + return &akm8975_akm8975_ops; } -EXPORT_SYMBOL(compass_get_ops); - -static int __init compass_init(void) +static int __init compass_akm8975_init(void) { struct sensor_operate *ops = compass_get_ops(); int result = 0; @@ -748,7 +746,7 @@ error: return result; } -static void __exit compass_exit(void) +static void __exit compass_akm8975_exit(void) { struct sensor_operate *ops = compass_get_ops(); int type = ops->type; @@ -756,7 +754,7 @@ static void __exit compass_exit(void) } -module_init(compass_init); -module_exit(compass_exit); +module_init(compass_akm8975_init); +module_exit(compass_akm8975_exit); diff --git a/drivers/input/sensors/gyro/l3g4200d.c b/drivers/input/sensors/gyro/l3g4200d.c index 45acad2bb9db..03a0d264fe14 100755 --- a/drivers/input/sensors/gyro/l3g4200d.c +++ b/drivers/input/sensors/gyro/l3g4200d.c @@ -213,7 +213,7 @@ static int sensor_report_value(struct i2c_client *client) } -struct sensor_operate gyro_ops = { +struct sensor_operate gyro_l3g4200d_ops = { .name = "l3g4200d", .type = SENSOR_TYPE_GYROSCOPE,//sensor type and it should be correct .id_i2c = GYRO_ID_L3G4200D, //i2c id number @@ -234,14 +234,13 @@ struct sensor_operate gyro_ops = { /****************operate according to sensor chip:end************/ //function name should not be changed -struct sensor_operate *gyro_get_ops(void) +static struct sensor_operate *gyro_get_ops(void) { - return &gyro_ops; + return &gyro_l3g4200d_ops; } -EXPORT_SYMBOL(gyro_get_ops); -static int __init gyro_init(void) +static int __init gyro_l3g4200d_init(void) { struct sensor_operate *ops = gyro_get_ops(); int result = 0; @@ -251,7 +250,7 @@ static int __init gyro_init(void) return result; } -static void __exit gyro_exit(void) +static void __exit gyro_l3g4200d_exit(void) { struct sensor_operate *ops = gyro_get_ops(); int type = ops->type; @@ -259,7 +258,7 @@ static void __exit gyro_exit(void) } -module_init(gyro_init); -module_exit(gyro_exit); +module_init(gyro_l3g4200d_init); +module_exit(gyro_l3g4200d_exit); diff --git a/drivers/input/sensors/lsensor/cm3217.c b/drivers/input/sensors/lsensor/cm3217.c index b51f27154ebe..31f09b02d0fc 100755 --- a/drivers/input/sensors/lsensor/cm3217.c +++ b/drivers/input/sensors/lsensor/cm3217.c @@ -186,7 +186,7 @@ static int sensor_report_value(struct i2c_client *client) } -struct sensor_operate light_ops = { +struct sensor_operate light_cm3217_ops = { .name = "cm3217", .type = SENSOR_TYPE_LIGHT, //sensor type and it should be correct .id_i2c = LIGHT_ID_CM3217, //i2c id number @@ -207,14 +207,13 @@ struct sensor_operate light_ops = { /****************operate according to sensor chip:end************/ //function name should not be changed -struct sensor_operate *light_get_ops(void) +static struct sensor_operate *light_get_ops(void) { - return &light_ops; + return &light_cm3217_ops; } -EXPORT_SYMBOL(light_get_ops); -static int __init light_init(void) +static int __init light_cm3217_init(void) { struct sensor_operate *ops = light_get_ops(); int result = 0; @@ -224,7 +223,7 @@ static int __init light_init(void) return result; } -static void __exit light_exit(void) +static void __exit light_cm3217_exit(void) { struct sensor_operate *ops = light_get_ops(); int type = ops->type; @@ -232,7 +231,7 @@ static void __exit light_exit(void) } -module_init(light_init); -module_exit(light_exit); +module_init(light_cm3217_init); +module_exit(light_cm3217_exit); diff --git a/drivers/input/sensors/lsensor/ls_al3006.c b/drivers/input/sensors/lsensor/ls_al3006.c index 4b12770215c4..e9a1f52852f8 100755 --- a/drivers/input/sensors/lsensor/ls_al3006.c +++ b/drivers/input/sensors/lsensor/ls_al3006.c @@ -251,7 +251,7 @@ static int sensor_report_value(struct i2c_client *client) return result; } -struct sensor_operate light_ops = { +struct sensor_operate light_al3006_ops = { .name = "ls_al3006", .type = SENSOR_TYPE_LIGHT, //sensor type and it should be correct .id_i2c = LIGHT_ID_AL3006, //i2c id number @@ -272,14 +272,13 @@ struct sensor_operate light_ops = { /****************operate according to sensor chip:end************/ //function name should not be changed -struct sensor_operate *light_get_ops(void) +static struct sensor_operate *light_get_ops(void) { - return &light_ops; + return &light_al3006_ops; } -EXPORT_SYMBOL(light_get_ops); -static int __init light_init(void) +static int __init light_al3006_init(void) { struct sensor_operate *ops = light_get_ops(); int result = 0; @@ -289,7 +288,7 @@ static int __init light_init(void) return result; } -static void __exit light_exit(void) +static void __exit light_al3006_exit(void) { struct sensor_operate *ops = light_get_ops(); int type = ops->type; @@ -297,7 +296,7 @@ static void __exit light_exit(void) } -module_init(light_init); -module_exit(light_exit); +module_init(light_al3006_init); +module_exit(light_al3006_exit); diff --git a/drivers/input/sensors/lsensor/ls_stk3171.c b/drivers/input/sensors/lsensor/ls_stk3171.c index ef4f1fc3f048..9edd1bff906b 100755 --- a/drivers/input/sensors/lsensor/ls_stk3171.c +++ b/drivers/input/sensors/lsensor/ls_stk3171.c @@ -270,7 +270,7 @@ static int sensor_report_value(struct i2c_client *client) return result; } -struct sensor_operate light_ops = { +struct sensor_operate light_stk3171_ops = { .name = "ls_stk3171", .type = SENSOR_TYPE_LIGHT, //sensor type and it should be correct .id_i2c = LIGHT_ID_STK3171, //i2c id number @@ -291,14 +291,13 @@ struct sensor_operate light_ops = { /****************operate according to sensor chip:end************/ //function name should not be changed -struct sensor_operate *light_get_ops(void) +static struct sensor_operate *light_get_ops(void) { - return &light_ops; + return &light_stk3171_ops; } -EXPORT_SYMBOL(light_get_ops); -static int __init light_init(void) +static int __init light_stk3171_init(void) { struct sensor_operate *ops = light_get_ops(); int result = 0; @@ -308,7 +307,7 @@ static int __init light_init(void) return result; } -static void __exit light_exit(void) +static void __exit light_stk3171_exit(void) { struct sensor_operate *ops = light_get_ops(); int type = ops->type; @@ -316,7 +315,7 @@ static void __exit light_exit(void) } -module_init(light_init); -module_exit(light_exit); +module_init(light_stk3171_init); +module_exit(light_stk3171_exit); diff --git a/drivers/input/sensors/psensor/ps_al3006.c b/drivers/input/sensors/psensor/ps_al3006.c index b78e08dc8061..83be85d6572c 100755 --- a/drivers/input/sensors/psensor/ps_al3006.c +++ b/drivers/input/sensors/psensor/ps_al3006.c @@ -213,7 +213,7 @@ static int sensor_report_value(struct i2c_client *client) return result; } -struct sensor_operate proximity_ops = { +struct sensor_operate proximity_al3006_ops = { .name = "ps_al3006", .type = SENSOR_TYPE_PROXIMITY,//sensor type and it should be correct .id_i2c = PROXIMITY_ID_AL3006, //i2c id number @@ -234,14 +234,13 @@ struct sensor_operate proximity_ops = { /****************operate according to sensor chip:end************/ //function name should not be changed -struct sensor_operate *proximity_get_ops(void) +static struct sensor_operate *proximity_get_ops(void) { - return &proximity_ops; + return &proximity_al3006_ops; } -EXPORT_SYMBOL(proximity_get_ops); -static int __init proximity_init(void) +static int __init proximity_al3006_init(void) { struct sensor_operate *ops = proximity_get_ops(); int result = 0; @@ -251,7 +250,7 @@ static int __init proximity_init(void) return result; } -static void __exit proximity_exit(void) +static void __exit proximity_al3006_exit(void) { struct sensor_operate *ops = proximity_get_ops(); int type = ops->type; @@ -259,7 +258,7 @@ static void __exit proximity_exit(void) } -module_init(proximity_init); -module_exit(proximity_exit); +module_init(proximity_al3006_init); +module_exit(proximity_al3006_exit); diff --git a/drivers/input/sensors/psensor/ps_stk3171.c b/drivers/input/sensors/psensor/ps_stk3171.c index c7ce75dd7861..431b8f7a90fa 100755 --- a/drivers/input/sensors/psensor/ps_stk3171.c +++ b/drivers/input/sensors/psensor/ps_stk3171.c @@ -220,7 +220,7 @@ static int sensor_report_value(struct i2c_client *client) return result; } -struct sensor_operate proximity_ops = { +struct sensor_operate proximity_stk3171_ops = { .name = "ps_stk3171", .type = SENSOR_TYPE_PROXIMITY, //sensor type and it should be correct .id_i2c = PROXIMITY_ID_STK3171, //i2c id number @@ -241,14 +241,12 @@ struct sensor_operate proximity_ops = { /****************operate according to sensor chip:end************/ //function name should not be changed -struct sensor_operate *proximity_get_ops(void) +static struct sensor_operate *proximity_get_ops(void) { - return &proximity_ops; + return &proximity_stk3171_ops; } -EXPORT_SYMBOL(proximity_get_ops); - -static int __init proximity_init(void) +static int __init proximity_stk3171_init(void) { struct sensor_operate *ops = proximity_get_ops(); int result = 0; @@ -258,7 +256,7 @@ static int __init proximity_init(void) return result; } -static void __exit proximity_exit(void) +static void __exit proximity_stk3171_exit(void) { struct sensor_operate *ops = proximity_get_ops(); int type = ops->type; @@ -266,7 +264,7 @@ static void __exit proximity_exit(void) } -module_init(proximity_init); -module_exit(proximity_exit); +module_init(proximity_stk3171_init); +module_exit(proximity_stk3171_exit); diff --git a/drivers/input/sensors/sensor-dev.c b/drivers/input/sensors/sensor-dev.c index 2dc9b8676d52..4e7d0683ec4b 100755 --- a/drivers/input/sensors/sensor-dev.c +++ b/drivers/input/sensors/sensor-dev.c @@ -46,7 +46,7 @@ #endif struct sensor_private_data *g_sensor[SENSOR_NUM_TYPES]; -static struct sensor_operate *sensor_ops[SENSOR_NUM_TYPES]; +static struct sensor_operate *sensor_ops[SENSOR_NUM_ID]; static int sensor_get_id(struct i2c_client *client, int *value) { @@ -106,7 +106,7 @@ static int sensor_chip_init(struct i2c_client *client) { struct sensor_private_data *sensor = (struct sensor_private_data *) i2c_get_clientdata(client); - struct sensor_operate *ops = sensor_ops[sensor->type]; + struct sensor_operate *ops = sensor_ops[(int)sensor->i2c_id->driver_data]; int result = 0; if(ops) @@ -120,9 +120,9 @@ static int sensor_chip_init(struct i2c_client *client) goto error; } - if(sensor->type != ops->type) + if((sensor->type != ops->type) || ((int)sensor->i2c_id->driver_data != ops->id_i2c)) { - printk("%s:type is different:%d,%d\n",__func__,sensor->type, sensor->type); + printk("%s:type or id is different:type=%d,%d,id=%d,%d\n",__func__,sensor->type, ops->type, (int)sensor->i2c_id->driver_data, ops->id_i2c); result = -1; goto error; } @@ -137,11 +137,11 @@ static int sensor_chip_init(struct i2c_client *client) result = sensor_get_id(sensor->client, &sensor->devid);//get id if(result < 0) { - printk("%s:fail to read devid:0x%x\n",__func__,sensor->devid); + printk("%s:fail to read %s devid:0x%x\n",__func__, sensor->i2c_id->name, sensor->devid); goto error; } - printk("%s:sensor->devid=0x%x,ops=0x%p\n",__func__,sensor->devid,sensor->ops); + printk("%s:%s:devid=0x%x,ops=0x%p\n",__func__, sensor->i2c_id->name, sensor->devid,sensor->ops); result = sensor_initial(sensor->client); //init sensor if(result < 0) @@ -1027,8 +1027,14 @@ int sensor_register_slave(int type,struct i2c_client *client, struct sensor_operate *(*get_sensor_ops)(void)) { int result = 0; - sensor_ops[type] = get_sensor_ops(); - printk("%s:%s\n",__func__,sensor_ops[type]->name); + struct sensor_operate *ops = get_sensor_ops(); + if((ops->id_i2c >= SENSOR_NUM_ID) || (ops->id_i2c <= ID_INVALID)) + { + printk("%s:%s id is error %d\n", __func__, ops->name, ops->id_i2c); + return -1; + } + sensor_ops[ops->id_i2c] = ops; + printk("%s:%s,id=%d\n",__func__,sensor_ops[ops->id_i2c]->name, ops->id_i2c); return result; } @@ -1038,8 +1044,14 @@ int sensor_unregister_slave(int type,struct i2c_client *client, struct sensor_operate *(*get_sensor_ops)(void)) { int result = 0; - printk("%s:%s\n",__func__,sensor_ops[type]->name); - sensor_ops[type] = NULL; + struct sensor_operate *ops = get_sensor_ops(); + if((ops->id_i2c >= SENSOR_NUM_ID) || (ops->id_i2c <= ID_INVALID)) + { + printk("%s:%s id is error %d\n", __func__, ops->name, ops->id_i2c); + return -1; + } + printk("%s:%s,id=%d\n",__func__,sensor_ops[ops->id_i2c]->name, ops->id_i2c); + sensor_ops[ops->id_i2c] = NULL; return result; } @@ -1080,6 +1092,13 @@ int sensor_probe(struct i2c_client *client, const struct i2c_device_id *devid) result = -EFAULT; goto out_no_free; } + + if(((int)devid->driver_data >= SENSOR_NUM_ID) || ((int)devid->driver_data <= ID_INVALID)) + { + dev_err(&client->adapter->dev, "sensor id is error %d\n", (int)devid->driver_data); + result = -EFAULT; + goto out_no_free; + } i2c_set_clientdata(client, sensor); sensor->client = client; @@ -1226,7 +1245,7 @@ int sensor_probe(struct i2c_client *client, const struct i2c_device_id *devid) } #endif - printk("%s:initialized ok,sensor name:%s,type:%d\n",__func__,sensor->ops->name,type); + printk("%s:initialized ok,sensor name:%s,type:%d,id=%d\n\n",__func__,sensor->ops->name,type,(int)sensor->i2c_id->driver_data); return result; @@ -1285,6 +1304,7 @@ static const struct i2c_device_id sensor_id[] = { {"k3g", GYRO_ID_K3G}, /*light sensor*/ {"lightsensor", LIGHT_ID_ALL}, + {"light_cm3217", LIGHT_ID_CM3217}, {"light_al3006", LIGHT_ID_AL3006}, {"ls_stk3171", LIGHT_ID_STK3171}, /*proximity sensor*/ diff --git a/include/linux/sensor-dev.h b/include/linux/sensor-dev.h index c087b1bcf8b1..710ce1e36614 100755 --- a/include/linux/sensor-dev.h +++ b/include/linux/sensor-dev.h @@ -52,6 +52,7 @@ enum sensor_id { ACCEL_ID_ADXL34X, ACCEL_ID_MMA8450, ACCEL_ID_MMA845X, + ACCEL_ID_MMA7660, ACCEL_ID_MPU6050, COMPASS_ID_ALL, @@ -84,6 +85,7 @@ enum sensor_id { PRESSURE_ID_ALL, PRESSURE_ID_BMA085, + SENSOR_NUM_ID, };