\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
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
\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