sensor:add setting gsensor orientation online support
authorlw@rock-chips.com <lw@rock-chips.com>
Sun, 19 Aug 2012 11:39:42 +0000 (19:39 +0800)
committerlw <lw@rock-chips.com>
Sun, 19 Aug 2012 11:40:03 +0000 (19:40 +0800)
arch/arm/plat-rk/include/plat/board.h
drivers/input/sensors/sensor-dev.c

index 36013e75c6b27d64ba1a366f11460c7fccdc33a2..9b3576be7d5d197b9e45a6061399f8afc61a79a5 100755 (executable)
@@ -127,6 +127,7 @@ struct sensor_platform_data {
        int x_min;              //filter
        int y_min;
        int z_min;
+       int factory;
        unsigned char address;
        signed char orientation[9];
        short m_layout[4][3][3];
index 8d10cedc87394ae850f801e98923ef88842ee170..81d5f559ca0592085f6a8e7aeffe420c9332922c 100755 (executable)
@@ -45,6 +45,8 @@
 \r
 struct sensor_private_data *g_sensor[SENSOR_NUM_TYPES];\r
 static struct sensor_operate *sensor_ops[SENSOR_NUM_ID]; \r
+static struct class *g_sensor_class[SENSOR_NUM_TYPES];\r
+\r
 \r
 static int sensor_get_id(struct i2c_client *client, int *value)\r
 {\r
@@ -482,6 +484,72 @@ error:
        return result;\r
 }\r
 \r
+static ssize_t gsensor_set_orientation_online(struct device *dev,\r
+               struct device_attribute *attr, char *buf)\r
+{\r
+       int i=0;\r
+       char orientation[20];\r
+       \r
+       struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_ACCEL];\r
+       struct sensor_platform_data *pdata = sensor->pdata;\r
+\r
+       \r
+       char *p = strstr(buf,"gsensor_class");\r
+       int start = strcspn(p,"{");\r
+       int end = strcspn(p,"}");\r
+       \r
+       strncpy(orientation,p+start,end-start+1);\r
+       char *tmp = orientation;\r
+       \r
+\r
+       while(strncmp(tmp,"}",1)!=0)\r
+        {\r
+               if((strncmp(tmp,",",1)==0)||(strncmp(tmp,"{",1)==0))\r
+               {\r
+                       \r
+                        tmp++;         \r
+                        continue;\r
+               }       \r
+               else if(strncmp(tmp,"-",1)==0)\r
+               {\r
+                       pdata->orientation[i++]=-1;\r
+                       DBG("i=%d,data=%d\n",i,pdata->orientation[i]);\r
+                        tmp++;\r
+               }               \r
+               else\r
+               {\r
+                       pdata->orientation[i++]=tmp[0]-48;              \r
+                       DBG("----i=%d,data=%d\n",i,pdata->orientation[i]);      \r
+               }       \r
+               tmp++;\r
+       \r
+                                               \r
+        }\r
+\r
+       for(i=0;i<9;i++)\r
+               DBG("i=%d gsensor_info=%d\n",i,pdata->orientation[i]);\r
+       return 0;\r
+\r
+}\r
+\r
+static CLASS_ATTR(orientation, 0660, NULL,gsensor_set_orientation_online);\r
+\r
+static int  gsensor_class_init(void)\r
+{\r
+       int ret ;\r
+       struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_ACCEL];       \r
+       g_sensor_class[SENSOR_TYPE_ACCEL] = class_create(THIS_MODULE, "gsensor_class");\r
+       ret =  class_create_file(g_sensor_class[SENSOR_TYPE_ACCEL], &class_attr_orientation);\r
+       if (ret)\r
+       {\r
+               printk("%s:Fail to creat class\n",__func__);\r
+               return ret;\r
+       }\r
+       printk("%s:%s\n",__func__,sensor->i2c_id->name);\r
+       return 0;\r
+}\r
+\r
+\r
 \r
 static int compass_dev_open(struct inode *inode, struct file *file)\r
 {\r
@@ -1222,6 +1290,16 @@ int sensor_probe(struct i2c_client *client, const struct i2c_device_id *devid)
        \r
        g_sensor[type] = sensor;\r
 \r
+       if((type == SENSOR_TYPE_ACCEL) && (sensor->pdata->factory))     //only support  setting gsensor orientation online now  \r
+       {\r
+               result = gsensor_class_init();\r
+               if (result) {\r
+                       dev_err(&client->dev,\r
+                               "fail to register misc device %s\n", sensor->i2c_id->name);\r
+                       goto out_misc_device_register_device_failed;\r
+               }\r
+       }\r
+       \r
 #ifdef CONFIG_HAS_EARLYSUSPEND\r
        if((sensor->ops->suspend) && (sensor->ops->resume))\r
        {\r