return ret;\r
}\r
\r
-struct sensor_operate gsensor_ops = {\r
+struct sensor_operate gsensor_kxtik_ops = {\r
.name = "kxtik",\r
.type = SENSOR_TYPE_ACCEL, //sensor type and it should be correct\r
.id_i2c = ACCEL_ID_KXTIK, //i2c id number\r
/****************operate according to sensor chip:end************/\r
\r
//function name should not be changed\r
-struct sensor_operate *gsensor_get_ops(void)\r
+static struct sensor_operate *gsensor_get_ops(void)\r
{\r
- return &gsensor_ops;\r
+ return &gsensor_kxtik_ops;\r
}\r
\r
-EXPORT_SYMBOL(gsensor_get_ops);\r
\r
-static int __init gsensor_init(void)\r
+static int __init gsensor_kxtik_init(void)\r
{\r
struct sensor_operate *ops = gsensor_get_ops();\r
int result = 0;\r
return result;\r
}\r
\r
-static void __exit gsensor_exit(void)\r
+static void __exit gsensor_kxtik_exit(void)\r
{\r
struct sensor_operate *ops = gsensor_get_ops();\r
int type = ops->type;\r
}\r
\r
\r
-module_init(gsensor_init);\r
-module_exit(gsensor_exit);\r
+module_init(gsensor_kxtik_init);\r
+module_exit(gsensor_kxtik_exit);\r
\r
\r
return ret;\r
}\r
\r
-struct sensor_operate gsensor_ops = {\r
+struct sensor_operate gsensor_lis3dh_ops = {\r
.name = "lis3dh",\r
.type = SENSOR_TYPE_ACCEL, //sensor type and it should be correct\r
.id_i2c = ACCEL_ID_LIS3DH, //i2c id number\r
/****************operate according to sensor chip:end************/\r
\r
//function name should not be changed\r
-struct sensor_operate *gsensor_get_ops(void)\r
+static struct sensor_operate *gsensor_get_ops(void)\r
{\r
- return &gsensor_ops;\r
+ return &gsensor_lis3dh_ops;\r
}\r
\r
-EXPORT_SYMBOL(gsensor_get_ops);\r
\r
-static int __init gsensor_init(void)\r
+static int __init gsensor_lis3dh_init(void)\r
{\r
struct sensor_operate *ops = gsensor_get_ops();\r
int result = 0;\r
return result;\r
}\r
\r
-static void __exit gsensor_exit(void)\r
+static void __exit gsensor_lis3dh_exit(void)\r
{\r
struct sensor_operate *ops = gsensor_get_ops();\r
int type = ops->type;\r
}\r
\r
\r
-module_init(gsensor_init);\r
-module_exit(gsensor_exit);\r
+module_init(gsensor_lis3dh_init);\r
+module_exit(gsensor_lis3dh_exit);\r
\r
\r
}\r
\r
\r
-struct sensor_operate gsensor_ops = {\r
+struct sensor_operate gsensor_mma8452_ops = {\r
.name = "mma8452",\r
.type = SENSOR_TYPE_ACCEL, //sensor type and it should be correct\r
.id_i2c = ACCEL_ID_MMA845X, //i2c id number\r
/****************operate according to sensor chip:end************/\r
\r
//function name should not be changed\r
-struct sensor_operate *gsensor_get_ops(void)\r
+static struct sensor_operate *gsensor_get_ops(void)\r
{\r
- return &gsensor_ops;\r
+ return &gsensor_mma8452_ops;\r
}\r
\r
-EXPORT_SYMBOL(gsensor_get_ops);\r
\r
-static int __init gsensor_init(void)\r
+static int __init gsensor_mma8452_init(void)\r
{\r
struct sensor_operate *ops = gsensor_get_ops();\r
int result = 0;\r
return result;\r
}\r
\r
-static void __exit gsensor_exit(void)\r
+static void __exit gsensor_mma8452_exit(void)\r
{\r
struct sensor_operate *ops = gsensor_get_ops();\r
int type = ops->type;\r
}\r
\r
\r
-module_init(gsensor_init);\r
-module_exit(gsensor_exit);\r
+module_init(gsensor_mma8452_init);\r
+module_exit(gsensor_mma8452_exit);\r
\r
\r
\r
.fops = &compass_dev_fops,\r
};\r
\r
-struct sensor_operate akm8975_ops = {\r
+struct sensor_operate akm8975_akm8975_ops = {\r
.name = "akm8975",\r
.type = SENSOR_TYPE_COMPASS, //it is important\r
.id_i2c = COMPASS_ID_AK8975,\r
/****************operate according to sensor chip:end************/\r
\r
//function name should not be changed\r
-struct sensor_operate *compass_get_ops(void)\r
+static struct sensor_operate *compass_get_ops(void)\r
{\r
- return &akm8975_ops;\r
+ return &akm8975_akm8975_ops;\r
}\r
\r
-EXPORT_SYMBOL(compass_get_ops);\r
\r
-\r
-static int __init compass_init(void)\r
+static int __init compass_akm8975_init(void)\r
{\r
struct sensor_operate *ops = compass_get_ops();\r
int result = 0;\r
return result;\r
}\r
\r
-static void __exit compass_exit(void)\r
+static void __exit compass_akm8975_exit(void)\r
{\r
struct sensor_operate *ops = compass_get_ops();\r
int type = ops->type;\r
}\r
\r
\r
-module_init(compass_init);\r
-module_exit(compass_exit);\r
+module_init(compass_akm8975_init);\r
+module_exit(compass_akm8975_exit);\r
\r
\r
}\r
\r
\r
-struct sensor_operate gyro_ops = {\r
+struct sensor_operate gyro_l3g4200d_ops = {\r
.name = "l3g4200d",\r
.type = SENSOR_TYPE_GYROSCOPE,//sensor type and it should be correct\r
.id_i2c = GYRO_ID_L3G4200D, //i2c id number\r
/****************operate according to sensor chip:end************/\r
\r
//function name should not be changed\r
-struct sensor_operate *gyro_get_ops(void)\r
+static struct sensor_operate *gyro_get_ops(void)\r
{\r
- return &gyro_ops;\r
+ return &gyro_l3g4200d_ops;\r
}\r
\r
-EXPORT_SYMBOL(gyro_get_ops);\r
\r
-static int __init gyro_init(void)\r
+static int __init gyro_l3g4200d_init(void)\r
{\r
struct sensor_operate *ops = gyro_get_ops();\r
int result = 0;\r
return result;\r
}\r
\r
-static void __exit gyro_exit(void)\r
+static void __exit gyro_l3g4200d_exit(void)\r
{\r
struct sensor_operate *ops = gyro_get_ops();\r
int type = ops->type;\r
}\r
\r
\r
-module_init(gyro_init);\r
-module_exit(gyro_exit);\r
+module_init(gyro_l3g4200d_init);\r
+module_exit(gyro_l3g4200d_exit);\r
\r
\r
}\r
\r
\r
-struct sensor_operate light_ops = {\r
+struct sensor_operate light_cm3217_ops = {\r
.name = "cm3217",\r
.type = SENSOR_TYPE_LIGHT, //sensor type and it should be correct\r
.id_i2c = LIGHT_ID_CM3217, //i2c id number\r
/****************operate according to sensor chip:end************/\r
\r
//function name should not be changed\r
-struct sensor_operate *light_get_ops(void)\r
+static struct sensor_operate *light_get_ops(void)\r
{\r
- return &light_ops;\r
+ return &light_cm3217_ops;\r
}\r
\r
-EXPORT_SYMBOL(light_get_ops);\r
\r
-static int __init light_init(void)\r
+static int __init light_cm3217_init(void)\r
{\r
struct sensor_operate *ops = light_get_ops();\r
int result = 0;\r
return result;\r
}\r
\r
-static void __exit light_exit(void)\r
+static void __exit light_cm3217_exit(void)\r
{\r
struct sensor_operate *ops = light_get_ops();\r
int type = ops->type;\r
}\r
\r
\r
-module_init(light_init);\r
-module_exit(light_exit);\r
+module_init(light_cm3217_init);\r
+module_exit(light_cm3217_exit);\r
\r
\r
return result;\r
}\r
\r
-struct sensor_operate light_ops = {\r
+struct sensor_operate light_al3006_ops = {\r
.name = "ls_al3006",\r
.type = SENSOR_TYPE_LIGHT, //sensor type and it should be correct\r
.id_i2c = LIGHT_ID_AL3006, //i2c id number\r
/****************operate according to sensor chip:end************/\r
\r
//function name should not be changed\r
-struct sensor_operate *light_get_ops(void)\r
+static struct sensor_operate *light_get_ops(void)\r
{\r
- return &light_ops;\r
+ return &light_al3006_ops;\r
}\r
\r
-EXPORT_SYMBOL(light_get_ops);\r
\r
-static int __init light_init(void)\r
+static int __init light_al3006_init(void)\r
{\r
struct sensor_operate *ops = light_get_ops();\r
int result = 0;\r
return result;\r
}\r
\r
-static void __exit light_exit(void)\r
+static void __exit light_al3006_exit(void)\r
{\r
struct sensor_operate *ops = light_get_ops();\r
int type = ops->type;\r
}\r
\r
\r
-module_init(light_init);\r
-module_exit(light_exit);\r
+module_init(light_al3006_init);\r
+module_exit(light_al3006_exit);\r
\r
\r
return result;\r
}\r
\r
-struct sensor_operate light_ops = {\r
+struct sensor_operate light_stk3171_ops = {\r
.name = "ls_stk3171",\r
.type = SENSOR_TYPE_LIGHT, //sensor type and it should be correct\r
.id_i2c = LIGHT_ID_STK3171, //i2c id number\r
/****************operate according to sensor chip:end************/\r
\r
//function name should not be changed\r
-struct sensor_operate *light_get_ops(void)\r
+static struct sensor_operate *light_get_ops(void)\r
{\r
- return &light_ops;\r
+ return &light_stk3171_ops;\r
}\r
\r
-EXPORT_SYMBOL(light_get_ops);\r
\r
-static int __init light_init(void)\r
+static int __init light_stk3171_init(void)\r
{\r
struct sensor_operate *ops = light_get_ops();\r
int result = 0;\r
return result;\r
}\r
\r
-static void __exit light_exit(void)\r
+static void __exit light_stk3171_exit(void)\r
{\r
struct sensor_operate *ops = light_get_ops();\r
int type = ops->type;\r
}\r
\r
\r
-module_init(light_init);\r
-module_exit(light_exit);\r
+module_init(light_stk3171_init);\r
+module_exit(light_stk3171_exit);\r
\r
\r
return result;\r
}\r
\r
-struct sensor_operate proximity_ops = {\r
+struct sensor_operate proximity_al3006_ops = {\r
.name = "ps_al3006",\r
.type = SENSOR_TYPE_PROXIMITY,//sensor type and it should be correct\r
.id_i2c = PROXIMITY_ID_AL3006, //i2c id number\r
/****************operate according to sensor chip:end************/\r
\r
//function name should not be changed\r
-struct sensor_operate *proximity_get_ops(void)\r
+static struct sensor_operate *proximity_get_ops(void)\r
{\r
- return &proximity_ops;\r
+ return &proximity_al3006_ops;\r
}\r
\r
-EXPORT_SYMBOL(proximity_get_ops);\r
\r
-static int __init proximity_init(void)\r
+static int __init proximity_al3006_init(void)\r
{\r
struct sensor_operate *ops = proximity_get_ops();\r
int result = 0;\r
return result;\r
}\r
\r
-static void __exit proximity_exit(void)\r
+static void __exit proximity_al3006_exit(void)\r
{\r
struct sensor_operate *ops = proximity_get_ops();\r
int type = ops->type;\r
}\r
\r
\r
-module_init(proximity_init);\r
-module_exit(proximity_exit);\r
+module_init(proximity_al3006_init);\r
+module_exit(proximity_al3006_exit);\r
\r
\r
return result;\r
}\r
\r
-struct sensor_operate proximity_ops = {\r
+struct sensor_operate proximity_stk3171_ops = {\r
.name = "ps_stk3171",\r
.type = SENSOR_TYPE_PROXIMITY, //sensor type and it should be correct\r
.id_i2c = PROXIMITY_ID_STK3171, //i2c id number\r
/****************operate according to sensor chip:end************/\r
\r
//function name should not be changed\r
-struct sensor_operate *proximity_get_ops(void)\r
+static struct sensor_operate *proximity_get_ops(void)\r
{\r
- return &proximity_ops;\r
+ return &proximity_stk3171_ops;\r
}\r
\r
-EXPORT_SYMBOL(proximity_get_ops);\r
-\r
-static int __init proximity_init(void)\r
+static int __init proximity_stk3171_init(void)\r
{\r
struct sensor_operate *ops = proximity_get_ops();\r
int result = 0;\r
return result;\r
}\r
\r
-static void __exit proximity_exit(void)\r
+static void __exit proximity_stk3171_exit(void)\r
{\r
struct sensor_operate *ops = proximity_get_ops();\r
int type = ops->type;\r
}\r
\r
\r
-module_init(proximity_init);\r
-module_exit(proximity_exit);\r
+module_init(proximity_stk3171_init);\r
+module_exit(proximity_stk3171_exit);\r
\r
\r
#endif\r
\r
struct sensor_private_data *g_sensor[SENSOR_NUM_TYPES];\r
-static struct sensor_operate *sensor_ops[SENSOR_NUM_TYPES]; \r
+static struct sensor_operate *sensor_ops[SENSOR_NUM_ID]; \r
\r
static int sensor_get_id(struct i2c_client *client, int *value)\r
{\r
{\r
struct sensor_private_data *sensor =\r
(struct sensor_private_data *) i2c_get_clientdata(client); \r
- struct sensor_operate *ops = sensor_ops[sensor->type];\r
+ struct sensor_operate *ops = sensor_ops[(int)sensor->i2c_id->driver_data];\r
int result = 0;\r
\r
if(ops)\r
goto error;\r
}\r
\r
- if(sensor->type != ops->type)\r
+ if((sensor->type != ops->type) || ((int)sensor->i2c_id->driver_data != ops->id_i2c))\r
{\r
- printk("%s:type is different:%d,%d\n",__func__,sensor->type, sensor->type);\r
+ 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);\r
result = -1;\r
goto error;\r
}\r
result = sensor_get_id(sensor->client, &sensor->devid);//get id\r
if(result < 0)\r
{ \r
- printk("%s:fail to read devid:0x%x\n",__func__,sensor->devid); \r
+ printk("%s:fail to read %s devid:0x%x\n",__func__, sensor->i2c_id->name, sensor->devid); \r
goto error;\r
}\r
\r
- printk("%s:sensor->devid=0x%x,ops=0x%p\n",__func__,sensor->devid,sensor->ops);\r
+ printk("%s:%s:devid=0x%x,ops=0x%p\n",__func__, sensor->i2c_id->name, sensor->devid,sensor->ops);\r
\r
result = sensor_initial(sensor->client); //init sensor\r
if(result < 0)\r
struct sensor_operate *(*get_sensor_ops)(void))\r
{\r
int result = 0;\r
- sensor_ops[type] = get_sensor_ops();\r
- printk("%s:%s\n",__func__,sensor_ops[type]->name);\r
+ struct sensor_operate *ops = get_sensor_ops();\r
+ if((ops->id_i2c >= SENSOR_NUM_ID) || (ops->id_i2c <= ID_INVALID))\r
+ { \r
+ printk("%s:%s id is error %d\n", __func__, ops->name, ops->id_i2c);\r
+ return -1; \r
+ }\r
+ sensor_ops[ops->id_i2c] = ops;\r
+ printk("%s:%s,id=%d\n",__func__,sensor_ops[ops->id_i2c]->name, ops->id_i2c);\r
return result;\r
}\r
\r
struct sensor_operate *(*get_sensor_ops)(void))\r
{\r
int result = 0;\r
- printk("%s:%s\n",__func__,sensor_ops[type]->name);\r
- sensor_ops[type] = NULL; \r
+ struct sensor_operate *ops = get_sensor_ops();\r
+ if((ops->id_i2c >= SENSOR_NUM_ID) || (ops->id_i2c <= ID_INVALID))\r
+ { \r
+ printk("%s:%s id is error %d\n", __func__, ops->name, ops->id_i2c);\r
+ return -1; \r
+ }\r
+ printk("%s:%s,id=%d\n",__func__,sensor_ops[ops->id_i2c]->name, ops->id_i2c);\r
+ sensor_ops[ops->id_i2c] = NULL; \r
return result;\r
}\r
\r
result = -EFAULT;\r
goto out_no_free; \r
}\r
+\r
+ if(((int)devid->driver_data >= SENSOR_NUM_ID) || ((int)devid->driver_data <= ID_INVALID))\r
+ { \r
+ dev_err(&client->adapter->dev, "sensor id is error %d\n", (int)devid->driver_data);\r
+ result = -EFAULT;\r
+ goto out_no_free; \r
+ }\r
\r
i2c_set_clientdata(client, sensor);\r
sensor->client = client; \r
}\r
#endif\r
\r
- printk("%s:initialized ok,sensor name:%s,type:%d\n",__func__,sensor->ops->name,type);\r
+ printk("%s:initialized ok,sensor name:%s,type:%d,id=%d\n\n",__func__,sensor->ops->name,type,(int)sensor->i2c_id->driver_data);\r
\r
return result;\r
\r
{"k3g", GYRO_ID_K3G},\r
/*light sensor*/\r
{"lightsensor", LIGHT_ID_ALL}, \r
+ {"light_cm3217", LIGHT_ID_CM3217},\r
{"light_al3006", LIGHT_ID_AL3006},\r
{"ls_stk3171", LIGHT_ID_STK3171},\r
/*proximity sensor*/\r
ACCEL_ID_ADXL34X,\r
ACCEL_ID_MMA8450,\r
ACCEL_ID_MMA845X,\r
+ ACCEL_ID_MMA7660,\r
ACCEL_ID_MPU6050,\r
\r
COMPASS_ID_ALL,\r
\r
PRESSURE_ID_ALL,\r
PRESSURE_ID_BMA085,\r
+ SENSOR_NUM_ID,\r
};\r
\r
\r