merge new gsensor driver
authorywj <ywj@rockchip.com>
Thu, 16 Aug 2012 09:59:08 +0000 (17:59 +0800)
committerywj <ywj@rockchip.com>
Thu, 16 Aug 2012 09:59:08 +0000 (17:59 +0800)
1  2 
arch/arm/mach-rk30/board-rk30-sdk.c
drivers/input/sensors/accel/kxtik.c
drivers/input/sensors/accel/lis3dh.c
drivers/input/sensors/accel/mma8452.c

Simple merge
index e9c5a754985d6a5facfa97f27afd5362cfe55f2f,d251f44c0a8b4239a39d9e65d82b203c12e767b7..3a014208704d62f7340058b2b7fda8f6d6536331
 -/* drivers/input/sensors/access/kxtik.c\r
 - *\r
 - * Copyright (C) 2012-2015 ROCKCHIP.\r
 - * Author: luowei <lw@rock-chips.com>\r
 - *\r
 - * This software is licensed under the terms of the GNU General Public\r
 - * License version 2, as published by the Free Software Foundation, and\r
 - * may be copied, distributed, and modified under those terms.\r
 - *\r
 - * This program is distributed in the hope that it will be useful,\r
 - * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
 - * GNU General Public License for more details.\r
 - *\r
 - */\r
 -#include <linux/interrupt.h>\r
 -#include <linux/i2c.h>\r
 -#include <linux/slab.h>\r
 -#include <linux/irq.h>\r
 -#include <linux/miscdevice.h>\r
 -#include <linux/gpio.h>\r
 -#include <asm/uaccess.h>\r
 -#include <asm/atomic.h>\r
 -#include <linux/delay.h>\r
 -#include <linux/input.h>\r
 -#include <linux/workqueue.h>\r
 -#include <linux/freezer.h>\r
 -#include <mach/gpio.h>\r
 -#include <mach/board.h> \r
 -#ifdef CONFIG_HAS_EARLYSUSPEND\r
 -#include <linux/earlysuspend.h>\r
 -#endif\r
 -#include <linux/kxtik.h>\r
 -#include <linux/sensor-dev.h>\r
 -\r
 -#if 0\r
 -#define SENSOR_DEBUG_TYPE SENSOR_TYPE_ACCEL\r
 -#define DBG(x...) if(sensor->pdata->type == SENSOR_DEBUG_TYPE) printk(x)\r
 -#else\r
 -#define DBG(x...)\r
 -#endif\r
 -\r
 -\r
 -\r
 -/****************operate according to sensor chip:start************/\r
 -\r
 -static int sensor_active(struct i2c_client *client, int enable, int rate)\r
 -{\r
 -      struct sensor_private_data *sensor =\r
 -          (struct sensor_private_data *) i2c_get_clientdata(client);  \r
 -      int result = 0;\r
 -      int status = 0;\r
 -              \r
 -      sensor->ops->ctrl_data = sensor_read_reg(client, sensor->ops->ctrl_reg);\r
 -      \r
 -      //register setting according to chip datasheet          \r
 -      if(enable)\r
 -      {       \r
 -              status = KXTIK_ENABLE;  //kxtik \r
 -              sensor->ops->ctrl_data |= status;       \r
 -      }\r
 -      else\r
 -      {\r
 -              status = ~KXTIK_ENABLE; //kxtik\r
 -              sensor->ops->ctrl_data &= status;\r
 -      }\r
 -\r
 -      DBG("%s:reg=0x%x,reg_ctrl=0x%x,enable=%d\n",__func__,sensor->ops->ctrl_reg, sensor->ops->ctrl_data, enable);\r
 -      result = sensor_write_reg(client, sensor->ops->ctrl_reg, sensor->ops->ctrl_data);\r
 -      if(result)\r
 -              printk("%s:fail to active sensor\n",__func__);\r
 -      \r
 -      return result;\r
 -\r
 -}\r
 -\r
 -static int sensor_init(struct i2c_client *client)\r
 -{     \r
 -      struct sensor_private_data *sensor =\r
 -          (struct sensor_private_data *) i2c_get_clientdata(client);  \r
 -      int result = 0;\r
 -      \r
 -      result = sensor->ops->active(client,0,0);\r
 -      if(result)\r
 -      {\r
 -              printk("%s:line=%d,error\n",__func__,__LINE__);\r
 -              return result;\r
 -      }\r
 -      \r
 -      sensor->status_cur = SENSOR_OFF;\r
 -      \r
 -      result = sensor_write_reg(client, KXTIK_DATA_CTRL_REG, KXTIK_ODR400F);\r
 -      if(result)\r
 -      {\r
 -              printk("%s:line=%d,error\n",__func__,__LINE__);\r
 -              return result;\r
 -      }\r
 -\r
 -      if(sensor->pdata->irq_enable)   //open interrupt\r
 -      {\r
 -              result = sensor_write_reg(client, KXTIK_INT_CTRL_REG1, 0x34);//enable int,active high,need read INT_REL\r
 -              if(result)\r
 -              {\r
 -                      printk("%s:line=%d,error\n",__func__,__LINE__);\r
 -                      return result;\r
 -              }\r
 -      }\r
 -      \r
 -      sensor->ops->ctrl_data = (KXTIK_RES_12BIT | KXTIK_G_2G);\r
 -      result = sensor_write_reg(client, sensor->ops->ctrl_reg, sensor->ops->ctrl_data);\r
 -      if(result)\r
 -      {\r
 -              printk("%s:line=%d,error\n",__func__,__LINE__);\r
 -              return result;\r
 -      }\r
 -      \r
 -      return result;\r
 -}\r
 -\r
 -static int sensor_convert_data(struct i2c_client *client, char high_byte, char low_byte)\r
 -{\r
 -    s64 result;\r
 -      struct sensor_private_data *sensor =\r
 -          (struct sensor_private_data *) i2c_get_clientdata(client);  \r
 -      //int precision = sensor->ops->precision;\r
 -      switch (sensor->devid) {        \r
 -              case KXTIK_DEVID:               \r
 -                      result = (((int)high_byte << 8) | ((int)low_byte ))>>4;\r
 -                      if (result < KXTIK_BOUNDARY)\r
 -                              result = result* KXTIK_GRAVITY_STEP;\r
 -              else\r
 -                              result = ~( ((~result & (0x7fff>>(16-KXTIK_PRECISION)) ) + 1) \r
 -                                              * KXTIK_GRAVITY_STEP) + 1;\r
 -                      break;\r
 -\r
 -              default:\r
 -                      printk(KERN_ERR "%s: devid wasn't set correctly\n",__func__);\r
 -                      return -EFAULT;\r
 -    }\r
 -\r
 -    return (int)result;\r
 -}\r
 -\r
 -static int gsensor_report_value(struct i2c_client *client, struct sensor_axis *axis)\r
 -{\r
 -      struct sensor_private_data *sensor =\r
 -              (struct sensor_private_data *) i2c_get_clientdata(client);      \r
 -\r
 -      /* Report acceleration sensor information */\r
 -      input_report_abs(sensor->input_dev, ABS_X, axis->x);\r
 -      input_report_abs(sensor->input_dev, ABS_Y, axis->y);\r
 -      input_report_abs(sensor->input_dev, ABS_Z, axis->z);\r
 -      input_sync(sensor->input_dev);\r
 -      DBG("Gsensor x==%d  y==%d z==%d\n",axis->x,axis->y,axis->z);\r
 -\r
 -      return 0;\r
 -}\r
 -\r
 -#define GSENSOR_MIN  10\r
 -static int sensor_report_value(struct i2c_client *client)\r
 -{\r
 -      struct sensor_private_data *sensor =\r
 -                      (struct sensor_private_data *) i2c_get_clientdata(client);      \r
 -      struct sensor_platform_data *pdata = sensor->pdata;\r
 -      int ret = 0;\r
 -      int x,y,z;\r
 -      struct sensor_axis axis;        \r
 -      char buffer[6] = {0};   \r
 -      char value = 0;\r
 -      \r
 -      if(sensor->ops->read_len < 6)   //sensor->ops->read_len = 6\r
 -      {\r
 -              printk("%s:lenth is error,len=%d\n",__func__,sensor->ops->read_len);\r
 -              return -1;\r
 -      }\r
 -      \r
 -      memset(buffer, 0, 6);\r
 -      \r
 -      /* Data bytes from hardware xL, xH, yL, yH, zL, zH */   \r
 -      do {\r
 -              *buffer = sensor->ops->read_reg;\r
 -              ret = sensor_rx_data(client, buffer, sensor->ops->read_len);\r
 -              if (ret < 0)\r
 -              return ret;\r
 -      } while (0);\r
 -\r
 -      //this gsensor need 6 bytes buffer\r
 -      x = sensor_convert_data(sensor->client, buffer[1], buffer[0]);  //buffer[1]:high bit \r
 -      y = sensor_convert_data(sensor->client, buffer[3], buffer[2]);\r
 -      z = sensor_convert_data(sensor->client, buffer[5], buffer[4]);          \r
 -\r
 -      axis.x = (pdata->orientation[0])*x + (pdata->orientation[1])*y + (pdata->orientation[2])*z;\r
 -      axis.y = (pdata->orientation[3])*x + (pdata->orientation[4])*y + (pdata->orientation[5])*z;     \r
 -      axis.z = (pdata->orientation[6])*x + (pdata->orientation[7])*y + (pdata->orientation[8])*z;\r
 -\r
 -      DBG( "%s: axis = %d  %d  %d \n", __func__, axis.x, axis.y, axis.z);\r
 -\r
 -      //Report event  only while value is changed to save some power\r
 -      if((abs(sensor->axis.x - axis.x) > GSENSOR_MIN) || (abs(sensor->axis.y - axis.y) > GSENSOR_MIN) || (abs(sensor->axis.z - axis.z) > GSENSOR_MIN))\r
 -      {\r
 -              gsensor_report_value(client, &axis);\r
 -\r
 -              /* »¥³âµØ»º´æÊý¾Ý. */\r
 -              mutex_lock(&(sensor->data_mutex) );\r
 -              sensor->axis = axis;\r
 -              mutex_unlock(&(sensor->data_mutex) );\r
 -      }\r
 -\r
 -      if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0))    //read sensor intterupt status register\r
 -      {\r
 -              \r
 -              value = sensor_read_reg(client, sensor->ops->int_status_reg);\r
 -              DBG("%s:sensor int status :0x%x\n",__func__,value);\r
 -      }\r
 -      \r
 -      return ret;\r
 -}\r
 -\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
 -      .read_reg                       = KXTIK_XOUT_L,                 //read data\r
 -      .read_len                       = 6,                            //data length\r
 -      .id_reg                         = KXTIK_WHO_AM_I,               //read device id from this register\r
 -      .id_data                        = KXTIK_DEVID,                  //device id\r
 -      .precision                      = KXTIK_PRECISION,              //12 bits\r
 -      .ctrl_reg                       = KXTIK_CTRL_REG1,              //enable or disable \r
 -      .int_status_reg                 = KXTIK_INT_REL,                //intterupt status register\r
 -      .range                          = {-KXTIK_RANGE,KXTIK_RANGE},   //range\r
 -      .trig                           = IRQF_TRIGGER_LOW|IRQF_ONESHOT,                \r
 -      .active                         = sensor_active,        \r
 -      .init                           = sensor_init,\r
 -      .report                         = sensor_report_value,\r
 -};\r
 -\r
 -/****************operate according to sensor chip:end************/\r
 -\r
 -//function name should not be changed\r
 -static struct sensor_operate *gsensor_get_ops(void)\r
 -{\r
 -      return &gsensor_kxtik_ops;\r
 -}\r
 -\r
 -\r
 -static int __init gsensor_kxtik_init(void)\r
 -{\r
 -      struct sensor_operate *ops = gsensor_get_ops();\r
 -      int result = 0;\r
 -      int type = ops->type;\r
 -      result = sensor_register_slave(type, NULL, NULL, gsensor_get_ops);\r
 -      printk("%s\n",__func__);\r
 -      return result;\r
 -}\r
 -\r
 -static void __exit gsensor_kxtik_exit(void)\r
 -{\r
 -      struct sensor_operate *ops = gsensor_get_ops();\r
 -      int type = ops->type;\r
 -      sensor_unregister_slave(type, NULL, NULL, gsensor_get_ops);\r
 -}\r
 -\r
 -\r
 -module_init(gsensor_kxtik_init);\r
 -module_exit(gsensor_kxtik_exit);\r
 -\r
 -\r
 +/* drivers/input/sensors/access/kxtik.c
 + *
 + * Copyright (C) 2012-2015 ROCKCHIP.
 + * Author: luowei <lw@rock-chips.com>
 + *
 + * This software is licensed under the terms of the GNU General Public
 + * License version 2, as published by the Free Software Foundation, and
 + * may be copied, distributed, and modified under those terms.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + */
 +#include <linux/interrupt.h>
 +#include <linux/i2c.h>
 +#include <linux/slab.h>
 +#include <linux/irq.h>
 +#include <linux/miscdevice.h>
 +#include <linux/gpio.h>
 +#include <asm/uaccess.h>
 +#include <asm/atomic.h>
 +#include <linux/delay.h>
 +#include <linux/input.h>
 +#include <linux/workqueue.h>
 +#include <linux/freezer.h>
 +#include <mach/gpio.h>
 +#include <mach/board.h> 
 +#ifdef CONFIG_HAS_EARLYSUSPEND
 +#include <linux/earlysuspend.h>
 +#endif
 +#include <linux/kxtik.h>
 +#include <linux/sensor-dev.h>
 +
 +#if 0
 +#define SENSOR_DEBUG_TYPE SENSOR_TYPE_ACCEL
 +#define DBG(x...) if(sensor->pdata->type == SENSOR_DEBUG_TYPE) printk(x)
 +#else
 +#define DBG(x...)
 +#endif
 +
- struct i2c_client *this_client=NULL;
++struct i2c_client *kxtik_client=NULL;
 +static struct class *sensor_class = NULL;
 +
 +static ssize_t sensor_setoratitention(struct device *dev,
 +              struct device_attribute *attr, char *buf)
 +{
 +      int i=0;
 +      char gsensororatation[20];
 +      
 +      struct sensor_private_data *sensor =
-           (struct sensor_private_data *) i2c_get_clientdata(this_client);     
++          (struct sensor_private_data *) i2c_get_clientdata(kxtik_client);    
 +      struct sensor_platform_data *pdata = sensor->pdata;
 +
 +      
 +      char *p = strstr(buf,"gsensor");
 +      int start = strcspn(p,"{");
 +      int end = strcspn(p,"}");
 +      
 +      strncpy(gsensororatation,p+start,end-start+1);
 +      char *tmp=gsensororatation;
 +      
 +
 +      while(strncmp(tmp,"}",1)!=0)
 +       {
 +              if((strncmp(tmp,",",1)==0)||(strncmp(tmp,"{",1)==0))
 +              {
 +                      
 +                       tmp++;         
 +                       continue;
 +              }       
 +              else if(strncmp(tmp,"-",1)==0)
 +              {
 +                      pdata->orientation[i++]=-1;
 +                      DBG("i=%d,data=%d\n",i,pdata->orientation[i]);
 +                       tmp++;
 +              }               
 +              else
 +              {
 +                      pdata->orientation[i++]=tmp[0]-48;              
 +                      DBG("----i=%d,data=%d\n",i,pdata->orientation[i]);      
 +              }       
 +              tmp++;
 +      
 +                                              
 +       }
 +
 +      for(i=0;i<9;i++)
 +              DBG("i=%d gsensor_info=%d\n",i,pdata->orientation[i]);
 +      return 0;
 +
 +}
 +
 +static CLASS_ATTR(oratiention, 0777, NULL,sensor_setoratitention);
 +
 +static int  sensor_sys_init(void)
 +{
 +      int ret ;
 +      sensor_class = class_create(THIS_MODULE, "gsensor");
 +      ret =  class_create_file(sensor_class, &class_attr_oratiention);
 +      if (ret)
 +      {
 +       printk("Fail to creat class oratiention.\n");
 +      }
 +      return 0;
 +}
 +
++
 +/****************operate according to sensor chip:start************/
 +
 +static int sensor_active(struct i2c_client *client, int enable, int rate)
 +{
 +      struct sensor_private_data *sensor =
 +          (struct sensor_private_data *) i2c_get_clientdata(client);  
 +      int result = 0;
 +      int status = 0;
 +              
 +      sensor->ops->ctrl_data = sensor_read_reg(client, sensor->ops->ctrl_reg);
 +      
 +      //register setting according to chip datasheet          
 +      if(enable)
 +      {       
 +              status = KXTIK_ENABLE;  //kxtik 
 +              sensor->ops->ctrl_data |= status;       
 +      }
 +      else
 +      {
 +              status = ~KXTIK_ENABLE; //kxtik
 +              sensor->ops->ctrl_data &= status;
 +      }
 +
 +      DBG("%s:reg=0x%x,reg_ctrl=0x%x,enable=%d\n",__func__,sensor->ops->ctrl_reg, sensor->ops->ctrl_data, enable);
 +      result = sensor_write_reg(client, sensor->ops->ctrl_reg, sensor->ops->ctrl_data);
 +      if(result)
 +              printk("%s:fail to active sensor\n",__func__);
 +      
 +      return result;
 +
- }
++} 
 +
 +static int sensor_init(struct i2c_client *client)
 +{     
 +      struct sensor_private_data *sensor =
 +          (struct sensor_private_data *) i2c_get_clientdata(client);  
 +      int result = 0;
 +      
 +      result = sensor->ops->active(client,0,0);
 +      if(result)
 +      {
 +              printk("%s:line=%d,error\n",__func__,__LINE__);
 +              return result;
 +      }
-       this_client = client;
 +      
++      kxtik_client=client;
 +      sensor->status_cur = SENSOR_OFF;
 +      
 +      result = sensor_write_reg(client, KXTIK_DATA_CTRL_REG, KXTIK_ODR400F);
 +      if(result)
 +      {
 +              printk("%s:line=%d,error\n",__func__,__LINE__);
 +              return result;
 +      }
 +
 +      if(sensor->pdata->irq_enable)   //open interrupt
 +      {
 +              result = sensor_write_reg(client, KXTIK_INT_CTRL_REG1, 0x34);//enable int,active high,need read INT_REL
 +              if(result)
 +              {
 +                      printk("%s:line=%d,error\n",__func__,__LINE__);
 +                      return result;
 +              }
 +      }
 +      
 +      sensor->ops->ctrl_data = (KXTIK_RES_12BIT | KXTIK_G_2G);
 +      result = sensor_write_reg(client, sensor->ops->ctrl_reg, sensor->ops->ctrl_data);
 +      if(result)
 +      {
 +              printk("%s:line=%d,error\n",__func__,__LINE__);
 +              return result;
 +      }
-       
++
 +      sensor_sys_init();
++      
 +      return result;
 +}
 +
 +static int sensor_convert_data(struct i2c_client *client, char high_byte, char low_byte)
 +{
 +    s64 result;
 +      struct sensor_private_data *sensor =
 +          (struct sensor_private_data *) i2c_get_clientdata(client);  
 +      //int precision = sensor->ops->precision;
 +      switch (sensor->devid) {        
 +              case KXTIK_DEVID:               
 +                      result = (((int)high_byte << 8) | ((int)low_byte ))>>4;
 +                      if (result < KXTIK_BOUNDARY)
 +                              result = result* KXTIK_GRAVITY_STEP;
 +              else
 +                              result = ~( ((~result & (0x7fff>>(16-KXTIK_PRECISION)) ) + 1) 
 +                                              * KXTIK_GRAVITY_STEP) + 1;
 +                      break;
 +
 +              default:
 +                      printk(KERN_ERR "%s: devid wasn't set correctly\n",__func__);
 +                      return -EFAULT;
 +    }
 +
 +    return (int)result;
 +}
 +
 +static int gsensor_report_value(struct i2c_client *client, struct sensor_axis *axis)
 +{
 +      struct sensor_private_data *sensor =
 +              (struct sensor_private_data *) i2c_get_clientdata(client);      
 +
 +      /* Report acceleration sensor information */
 +      input_report_abs(sensor->input_dev, ABS_X, axis->x);
 +      input_report_abs(sensor->input_dev, ABS_Y, axis->y);
 +      input_report_abs(sensor->input_dev, ABS_Z, axis->z);
 +      input_sync(sensor->input_dev);
 +      DBG("Gsensor x==%d  y==%d z==%d\n",axis->x,axis->y,axis->z);
 +
 +      return 0;
 +}
 +
 +#define GSENSOR_MIN  10
 +static int sensor_report_value(struct i2c_client *client)
 +{
 +      struct sensor_private_data *sensor =
 +                      (struct sensor_private_data *) i2c_get_clientdata(client);      
 +      struct sensor_platform_data *pdata = sensor->pdata;
 +      int ret = 0;
 +      int x,y,z;
 +      struct sensor_axis axis;        
 +      char buffer[6] = {0};   
 +      char value = 0;
 +      
 +      if(sensor->ops->read_len < 6)   //sensor->ops->read_len = 6
 +      {
 +              printk("%s:lenth is error,len=%d\n",__func__,sensor->ops->read_len);
 +              return -1;
 +      }
 +      
 +      memset(buffer, 0, 6);
 +      
 +      /* Data bytes from hardware xL, xH, yL, yH, zL, zH */   
 +      do {
 +              *buffer = sensor->ops->read_reg;
 +              ret = sensor_rx_data(client, buffer, sensor->ops->read_len);
 +              if (ret < 0)
 +              return ret;
 +      } while (0);
 +
 +      //this gsensor need 6 bytes buffer
 +      x = sensor_convert_data(sensor->client, buffer[1], buffer[0]);  //buffer[1]:high bit 
 +      y = sensor_convert_data(sensor->client, buffer[3], buffer[2]);
 +      z = sensor_convert_data(sensor->client, buffer[5], buffer[4]);          
 +
 +      axis.x = (pdata->orientation[0])*x + (pdata->orientation[1])*y + (pdata->orientation[2])*z;
 +      axis.y = (pdata->orientation[3])*x + (pdata->orientation[4])*y + (pdata->orientation[5])*z;     
 +      axis.z = (pdata->orientation[6])*x + (pdata->orientation[7])*y + (pdata->orientation[8])*z;
 +
 +      DBG( "%s: axis = %d  %d  %d \n", __func__, axis.x, axis.y, axis.z);
 +
 +      //Report event  only while value is changed to save some power
 +      if((abs(sensor->axis.x - axis.x) > GSENSOR_MIN) || (abs(sensor->axis.y - axis.y) > GSENSOR_MIN) || (abs(sensor->axis.z - axis.z) > GSENSOR_MIN))
 +      {
 +              gsensor_report_value(client, &axis);
 +
 +              /* »¥³âµØ»º´æÊý¾Ý. */
 +              mutex_lock(&(sensor->data_mutex) );
 +              sensor->axis = axis;
 +              mutex_unlock(&(sensor->data_mutex) );
 +      }
 +
 +      if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0))    //read sensor intterupt status register
 +      {
 +              
 +              value = sensor_read_reg(client, sensor->ops->int_status_reg);
 +              DBG("%s:sensor int status :0x%x\n",__func__,value);
 +      }
 +      
 +      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
 +      .read_reg                       = KXTIK_XOUT_L,                 //read data
 +      .read_len                       = 6,                            //data length
 +      .id_reg                         = KXTIK_WHO_AM_I,               //read device id from this register
 +      .id_data                        = KXTIK_DEVID,                  //device id
 +      .precision                      = KXTIK_PRECISION,              //12 bits
 +      .ctrl_reg                       = KXTIK_CTRL_REG1,              //enable or disable 
 +      .int_status_reg                 = KXTIK_INT_REL,                //intterupt status register
 +      .range                          = {-KXTIK_RANGE,KXTIK_RANGE},   //range
 +      .trig                           = IRQF_TRIGGER_LOW|IRQF_ONESHOT,                
 +      .active                         = sensor_active,        
 +      .init                           = sensor_init,
 +      .report                         = sensor_report_value,
 +};
 +
 +/****************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;
 +      int type = ops->type;
 +      result = sensor_register_slave(type, NULL, NULL, gsensor_get_ops);
 +      printk("%s\n",__func__);
 +      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;
 +      sensor_unregister_slave(type, NULL, NULL, gsensor_get_ops);
 +}
 +
 +
- module_init(gsensor_init);
- module_exit(gsensor_exit);
++module_init(gsensor_kxtik_init);
++module_exit(gsensor_kxtik_exit);
 +
index 2dcea964c28f857def6a05284ff254ddc5fff8d0,8ce14bbe6cd6bfddc7dfb2b34ad765c0c3d52795..7d6852271abc9eb2d1fa1029d397da5fa0b66d68
 -/* drivers/input/sensors/access/kxtik.c\r
 - *\r
 - * Copyright (C) 2012-2015 ROCKCHIP.\r
 - * Author: luowei <lw@rock-chips.com>\r
 - *\r
 - * This software is licensed under the terms of the GNU General Public\r
 - * License version 2, as published by the Free Software Foundation, and\r
 - * may be copied, distributed, and modified under those terms.\r
 - *\r
 - * This program is distributed in the hope that it will be useful,\r
 - * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
 - * GNU General Public License for more details.\r
 - *\r
 - */\r
 -#include <linux/interrupt.h>\r
 -#include <linux/i2c.h>\r
 -#include <linux/slab.h>\r
 -#include <linux/irq.h>\r
 -#include <linux/miscdevice.h>\r
 -#include <linux/gpio.h>\r
 -#include <asm/uaccess.h>\r
 -#include <asm/atomic.h>\r
 -#include <linux/delay.h>\r
 -#include <linux/input.h>\r
 -#include <linux/workqueue.h>\r
 -#include <linux/freezer.h>\r
 -#include <mach/gpio.h>\r
 -#include <mach/board.h> \r
 -#ifdef CONFIG_HAS_EARLYSUSPEND\r
 -#include <linux/earlysuspend.h>\r
 -#endif\r
 -#include <linux/sensor-dev.h>\r
 -\r
 -#if 0\r
 -#define SENSOR_DEBUG_TYPE SENSOR_TYPE_ACCEL\r
 -#define DBG(x...) if(sensor->pdata->type == SENSOR_DEBUG_TYPE) printk(x)\r
 -#else\r
 -#define DBG(x...)\r
 -#endif\r
 -\r
 -#define LIS3DH_INT_COUNT              (0x0E)\r
 -#define LIS3DH_WHO_AM_I                       (0x0F)\r
 -\r
 -/* full scale setting - register & mask */\r
 -#define LIS3DH_TEMP_CFG_REG           (0x1F)\r
 -#define LIS3DH_CTRL_REG1              (0x20)\r
 -#define LIS3DH_CTRL_REG2              (0x21)\r
 -#define LIS3DH_CTRL_REG3              (0x22)\r
 -#define LIS3DH_CTRL_REG4              (0x23)\r
 -#define LIS3DH_CTRL_REG5              (0x24)\r
 -#define LIS3DH_CTRL_REG6              (0x25)\r
 -#define LIS3DH_REFERENCE              (0x26)\r
 -#define LIS3DH_STATUS_REG             (0x27)\r
 -#define LIS3DH_OUT_X_L                        (0x28)\r
 -#define LIS3DH_OUT_X_H                        (0x29)\r
 -#define LIS3DH_OUT_Y_L                        (0x2a)\r
 -#define LIS3DH_OUT_Y_H                        (0x2b)\r
 -#define LIS3DH_OUT_Z_L                        (0x2c)\r
 -#define LIS3DH_OUT_Z_H                        (0x2d)\r
 -#define LIS3DH_FIFO_CTRL_REG          (0x2E)\r
 -\r
 -#define LIS3DH_INT1_CFG                       (0x30)\r
 -#define LIS3DH_INT1_SRC                       (0x31)\r
 -#define LIS3DH_INT1_THS                       (0x32)\r
 -#define LIS3DH_INT1_DURATION          (0x33)\r
 -\r
 -#define LIS3DH_DEVID                  (0x33)  //chip id\r
 -#define LIS3DH_ACC_DISABLE            (0x08)\r
 -\r
 -#define LIS3DH_RANGE                  2000000\r
 -\r
 -/* LIS3DH */\r
 -#define LIS3DH_PRECISION              16\r
 -#define LIS3DH_BOUNDARY                       (0x1 << (LIS3DH_PRECISION - 1))\r
 -#define LIS3DH_GRAVITY_STEP           (LIS3DH_RANGE / LIS3DH_BOUNDARY)\r
 -\r
 -#define ODR1                          0x10  /* 1Hz output data rate */\r
 -#define ODR10                         0x20  /* 10Hz output data rate */\r
 -#define ODR25                         0x30  /* 25Hz output data rate */\r
 -#define ODR50                         0x40  /* 50Hz output data rate */\r
 -#define ODR100                                0x50  /* 100Hz output data rate */\r
 -#define ODR200                                0x60  /* 200Hz output data rate */\r
 -#define ODR400                                0x70  /* 400Hz output data rate */\r
 -#define ODR1250                               0x90  /* 1250Hz output data rate */\r
 -\r
 -\r
 -\r
 -struct sensor_reg_data {\r
 -      char reg;\r
 -      char data;\r
 -};\r
 -\r
 -\r
 -/****************operate according to sensor chip:start************/\r
 -\r
 -static int sensor_active(struct i2c_client *client, int enable, int rate)\r
 -{\r
 -      struct sensor_private_data *sensor =\r
 -          (struct sensor_private_data *) i2c_get_clientdata(client);  \r
 -      int result = 0;\r
 -      int status = 0;\r
 -              \r
 -      sensor->ops->ctrl_data = sensor_read_reg(client, sensor->ops->ctrl_reg);\r
 -\r
 -      sensor->ops->ctrl_data |= ODR100;       //100HZ,if 0 then power down\r
 -      \r
 -      //register setting according to chip datasheet          \r
 -      if(!enable)\r
 -      {       \r
 -              status = LIS3DH_ACC_DISABLE;    //lis3dh        \r
 -              sensor->ops->ctrl_data |= status;       \r
 -      }\r
 -      else\r
 -      {\r
 -              status = ~LIS3DH_ACC_DISABLE;   //lis3dh\r
 -              sensor->ops->ctrl_data &= status;\r
 -      }\r
 -\r
 -      DBG("%s:reg=0x%x,reg_ctrl=0x%x,enable=%d\n",__func__,sensor->ops->ctrl_reg, sensor->ops->ctrl_data, enable);\r
 -      result = sensor_write_reg(client, sensor->ops->ctrl_reg, sensor->ops->ctrl_data);\r
 -      if(result)\r
 -              printk("%s:fail to active sensor\n",__func__);\r
 -      \r
 -      return result;\r
 -\r
 -}\r
 -\r
 -static int sensor_init(struct i2c_client *client)\r
 -{     \r
 -      struct sensor_private_data *sensor =\r
 -          (struct sensor_private_data *) i2c_get_clientdata(client);  \r
 -      int result = 0;\r
 -      int i;\r
 -      struct sensor_reg_data reg_data[] = \r
 -      {                       \r
 -              {LIS3DH_CTRL_REG2,0X00},                        \r
 -              {LIS3DH_CTRL_REG4,0x08},        //High resolution output mode: 1, Normal mode   \r
 -              {LIS3DH_CTRL_REG6,0x40},        \r
 -              {LIS3DH_TEMP_CFG_REG,0x00},     //\r
 -              {LIS3DH_FIFO_CTRL_REG,0x00},    //      \r
 -              {LIS3DH_INT1_CFG,0xFF},         //6 direction position recognition      \r
 -              {LIS3DH_INT1_THS,0x7F},         //Interrupt 1 threshold \r
 -              {LIS3DH_INT1_DURATION,0x7F},    //Duration value 0x00->ox7f\r
 -      };  \r
 -      \r
 -      result = sensor->ops->active(client,0,0);\r
 -      if(result)\r
 -      {\r
 -              printk("%s:line=%d,error\n",__func__,__LINE__);\r
 -              return result;\r
 -      }\r
 -      \r
 -      sensor->status_cur = SENSOR_OFF;\r
 -      \r
 -      for(i=0;i<(sizeof(reg_data)/sizeof(struct sensor_reg_data));i++)\r
 -      {\r
 -              result = sensor_write_reg(client, reg_data[i].reg, reg_data[i].data);\r
 -              if(result)\r
 -              {\r
 -                      printk("%s:line=%d,i=%d,error\n",__func__,__LINE__,i);\r
 -                      return result;\r
 -              }\r
 -      }\r
 -\r
 -      \r
 -      if(sensor->pdata->irq_enable)\r
 -      {\r
 -\r
 -              result = sensor_write_reg(client, LIS3DH_CTRL_REG3, 0x40);//I1_AOI1 =1  if motion       \r
 -              if(result)\r
 -              {\r
 -                      printk("%s:line=%d,error\n",__func__,__LINE__);\r
 -                      return result;\r
 -              }\r
 -\r
 -              result = sensor_write_reg(client, LIS3DH_CTRL_REG5, 0x08);\r
 -              if(result)\r
 -              {\r
 -                      printk("%s:line=%d,error\n",__func__,__LINE__);\r
 -                      return result;\r
 -              }\r
 -\r
 -      }\r
 -      \r
 -      return result;\r
 -}\r
 -\r
 -static int sensor_convert_data(struct i2c_client *client, char high_byte, char low_byte)\r
 -{\r
 -      s64 result;\r
 -      struct sensor_private_data *sensor =\r
 -          (struct sensor_private_data *) i2c_get_clientdata(client);  \r
 -      //int precision = sensor->ops->precision;\r
 -      switch (sensor->devid) {        \r
 -              case LIS3DH_DEVID:              \r
 -                      result = ((int)high_byte << 8) | (int)low_byte;\r
 -                      if (result < LIS3DH_BOUNDARY)\r
 -                              result = result* LIS3DH_GRAVITY_STEP;\r
 -              else\r
 -                              result = ~( ((~result & (0x7fff>>(16-LIS3DH_PRECISION)) ) + 1) \r
 -                                              * LIS3DH_GRAVITY_STEP) + 1;\r
 -                      break;\r
 -\r
 -              default:\r
 -                      printk(KERN_ERR "%s: devid wasn't set correctly\n",__func__);\r
 -                      return -EFAULT;\r
 -    }\r
 -\r
 -    return (int)result;\r
 -}\r
 -\r
 -static int gsensor_report_value(struct i2c_client *client, struct sensor_axis *axis)\r
 -{\r
 -      struct sensor_private_data *sensor =\r
 -              (struct sensor_private_data *) i2c_get_clientdata(client);      \r
 -\r
 -      /* Report acceleration sensor information */\r
 -      input_report_abs(sensor->input_dev, ABS_X, axis->x);\r
 -      input_report_abs(sensor->input_dev, ABS_Y, axis->y);\r
 -      input_report_abs(sensor->input_dev, ABS_Z, axis->z);\r
 -      input_sync(sensor->input_dev);\r
 -      DBG("Gsensor x==%d  y==%d z==%d\n",axis->x,axis->y,axis->z);\r
 -\r
 -      return 0;\r
 -}\r
 -\r
 -#define GSENSOR_MIN  10\r
 -static int sensor_report_value(struct i2c_client *client)\r
 -{\r
 -      struct sensor_private_data *sensor =\r
 -                      (struct sensor_private_data *) i2c_get_clientdata(client);      \r
 -      struct sensor_platform_data *pdata = sensor->pdata;\r
 -      int ret = 0;\r
 -      int x,y,z;\r
 -      struct sensor_axis axis;        \r
 -      char buffer[6] = {0};   \r
 -      char value = 0;\r
 -      \r
 -      if(sensor->ops->read_len < 6)   //sensor->ops->read_len = 6\r
 -      {\r
 -              printk("%s:lenth is error,len=%d\n",__func__,sensor->ops->read_len);\r
 -              return -1;\r
 -      }\r
 -      \r
 -      memset(buffer, 0, 6);\r
 -\r
 -      value = sensor_read_reg(client, LIS3DH_STATUS_REG);\r
 -      if((value & 0x0f) == 0)\r
 -      {\r
 -              printk("%s:line=%d,value=0x%x,data is not ready\n",__func__,__LINE__,value);\r
 -              return -1;\r
 -      }\r
 -              \r
 -      \r
 -      /* Data bytes from hardware xL, xH, yL, yH, zL, zH */   \r
 -      do {\r
 -              *buffer = sensor->ops->read_reg;\r
 -              ret = sensor_rx_data(client, buffer, sensor->ops->read_len);\r
 -              if (ret < 0)\r
 -              return ret;\r
 -      } while (0);\r
 -\r
 -      //this gsensor need 6 bytes buffer\r
 -      x = sensor_convert_data(sensor->client, buffer[1], buffer[0]);  //buffer[1]:high bit \r
 -      y = sensor_convert_data(sensor->client, buffer[3], buffer[2]);\r
 -      z = sensor_convert_data(sensor->client, buffer[5], buffer[4]);          \r
 -\r
 -      axis.x = (pdata->orientation[0])*x + (pdata->orientation[1])*y + (pdata->orientation[2])*z;\r
 -      axis.y = (pdata->orientation[3])*x + (pdata->orientation[4])*y + (pdata->orientation[5])*z;     \r
 -      axis.z = (pdata->orientation[6])*x + (pdata->orientation[7])*y + (pdata->orientation[8])*z;\r
 -\r
 -      DBG( "%s: axis = %d  %d  %d \n", __func__, axis.x, axis.y, axis.z);\r
 -\r
 -      //Report event  only while value is changed to save some power\r
 -      if((abs(sensor->axis.x - axis.x) > GSENSOR_MIN) || (abs(sensor->axis.y - axis.y) > GSENSOR_MIN) || (abs(sensor->axis.z - axis.z) > GSENSOR_MIN))\r
 -      {\r
 -              gsensor_report_value(client, &axis);\r
 -\r
 -              /* »¥³âµØ»º´æÊý¾Ý. */\r
 -              mutex_lock(&(sensor->data_mutex) );\r
 -              sensor->axis = axis;\r
 -              mutex_unlock(&(sensor->data_mutex) );\r
 -      }\r
 -\r
 -      if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0))    //read sensor intterupt status register\r
 -      {\r
 -              \r
 -              value = sensor_read_reg(client, sensor->ops->int_status_reg);\r
 -              DBG("%s:sensor int status :0x%x\n",__func__,value);\r
 -      }\r
 -      \r
 -      return ret;\r
 -}\r
 -\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
 -      .read_reg                       = (LIS3DH_OUT_X_L | 0x80),      //read data\r
 -      .read_len                       = 6,                            //data length\r
 -      .id_reg                         = LIS3DH_WHO_AM_I,              //read device id from this register\r
 -      .id_data                        = LIS3DH_DEVID,                 //device id\r
 -      .precision                      = LIS3DH_PRECISION,             //12 bits\r
 -      .ctrl_reg                       = LIS3DH_CTRL_REG1,             //enable or disable \r
 -      .int_status_reg                 = LIS3DH_INT1_SRC,              //intterupt status register\r
 -      .range                          = {-LIS3DH_RANGE,LIS3DH_RANGE}, //range\r
 -      .trig                           = (IRQF_TRIGGER_LOW|IRQF_ONESHOT),              \r
 -      .active                         = sensor_active,        \r
 -      .init                           = sensor_init,\r
 -      .report                         = sensor_report_value,\r
 -};\r
 -\r
 -/****************operate according to sensor chip:end************/\r
 -\r
 -//function name should not be changed\r
 -static struct sensor_operate *gsensor_get_ops(void)\r
 -{\r
 -      return &gsensor_lis3dh_ops;\r
 -}\r
 -\r
 -\r
 -static int __init gsensor_lis3dh_init(void)\r
 -{\r
 -      struct sensor_operate *ops = gsensor_get_ops();\r
 -      int result = 0;\r
 -      int type = ops->type;\r
 -      result = sensor_register_slave(type, NULL, NULL, gsensor_get_ops);\r
 -      printk("%s\n",__func__);\r
 -      return result;\r
 -}\r
 -\r
 -static void __exit gsensor_lis3dh_exit(void)\r
 -{\r
 -      struct sensor_operate *ops = gsensor_get_ops();\r
 -      int type = ops->type;\r
 -      sensor_unregister_slave(type, NULL, NULL, gsensor_get_ops);\r
 -}\r
 -\r
 -\r
 -module_init(gsensor_lis3dh_init);\r
 -module_exit(gsensor_lis3dh_exit);\r
 -\r
 -\r
 +/* drivers/input/sensors/access/kxtik.c
 + *
 + * Copyright (C) 2012-2015 ROCKCHIP.
 + * Author: luowei <lw@rock-chips.com>
 + *
 + * This software is licensed under the terms of the GNU General Public
 + * License version 2, as published by the Free Software Foundation, and
 + * may be copied, distributed, and modified under those terms.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + */
 +#include <linux/interrupt.h>
 +#include <linux/i2c.h>
 +#include <linux/slab.h>
 +#include <linux/irq.h>
 +#include <linux/miscdevice.h>
 +#include <linux/gpio.h>
 +#include <asm/uaccess.h>
 +#include <asm/atomic.h>
 +#include <linux/delay.h>
 +#include <linux/input.h>
 +#include <linux/workqueue.h>
 +#include <linux/freezer.h>
 +#include <mach/gpio.h>
 +#include <mach/board.h> 
 +#ifdef CONFIG_HAS_EARLYSUSPEND
 +#include <linux/earlysuspend.h>
 +#endif
 +#include <linux/sensor-dev.h>
 +
 +#if 0
 +#define SENSOR_DEBUG_TYPE SENSOR_TYPE_ACCEL
 +#define DBG(x...) if(sensor->pdata->type == SENSOR_DEBUG_TYPE) printk(x)
 +#else
 +#define DBG(x...)
 +#endif
 +
 +#define LIS3DH_INT_COUNT              (0x0E)
 +#define LIS3DH_WHO_AM_I                       (0x0F)
 +
 +/* full scale setting - register & mask */
 +#define LIS3DH_TEMP_CFG_REG           (0x1F)
 +#define LIS3DH_CTRL_REG1              (0x20)
 +#define LIS3DH_CTRL_REG2              (0x21)
 +#define LIS3DH_CTRL_REG3              (0x22)
 +#define LIS3DH_CTRL_REG4              (0x23)
 +#define LIS3DH_CTRL_REG5              (0x24)
 +#define LIS3DH_CTRL_REG6              (0x25)
 +#define LIS3DH_REFERENCE              (0x26)
 +#define LIS3DH_STATUS_REG             (0x27)
 +#define LIS3DH_OUT_X_L                        (0x28)
 +#define LIS3DH_OUT_X_H                        (0x29)
 +#define LIS3DH_OUT_Y_L                        (0x2a)
 +#define LIS3DH_OUT_Y_H                        (0x2b)
 +#define LIS3DH_OUT_Z_L                        (0x2c)
 +#define LIS3DH_OUT_Z_H                        (0x2d)
 +#define LIS3DH_FIFO_CTRL_REG          (0x2E)
 +
 +#define LIS3DH_INT1_CFG                       (0x30)
 +#define LIS3DH_INT1_SRC                       (0x31)
 +#define LIS3DH_INT1_THS                       (0x32)
 +#define LIS3DH_INT1_DURATION          (0x33)
 +
 +#define LIS3DH_DEVID                  (0x33)  //chip id
 +#define LIS3DH_ACC_DISABLE            (0x08)
 +
 +#define LIS3DH_RANGE                  2000000
 +
 +/* LIS3DH */
 +#define LIS3DH_PRECISION              16
 +#define LIS3DH_BOUNDARY                       (0x1 << (LIS3DH_PRECISION - 1))
 +#define LIS3DH_GRAVITY_STEP           (LIS3DH_RANGE / LIS3DH_BOUNDARY)
 +
 +#define ODR1                          0x10  /* 1Hz output data rate */
 +#define ODR10                         0x20  /* 10Hz output data rate */
 +#define ODR25                         0x30  /* 25Hz output data rate */
 +#define ODR50                         0x40  /* 50Hz output data rate */
 +#define ODR100                                0x50  /* 100Hz output data rate */
 +#define ODR200                                0x60  /* 200Hz output data rate */
 +#define ODR400                                0x70  /* 400Hz output data rate */
 +#define ODR1250                               0x90  /* 1250Hz output data rate */
 +
 +
 +
 +struct sensor_reg_data {
 +      char reg;
 +      char data;
 +};
 +
- struct i2c_client *this_client=NULL;
++struct i2c_client *lis3dgh_client=NULL;
 +static struct class *sensor_class = NULL;
 +
 +static ssize_t sensor_setoratitention(struct device *dev,
 +              struct device_attribute *attr, char *buf)
 +{
 +      int i=0;
 +      char gsensororatation[20];
 +      
 +      struct sensor_private_data *sensor =
-           (struct sensor_private_data *) i2c_get_clientdata(this_client);     
++          (struct sensor_private_data *) i2c_get_clientdata(lis3dgh_client);  
 +      struct sensor_platform_data *pdata = sensor->pdata;
 +
 +      
 +      char *p = strstr(buf,"gsensor");
 +      int start = strcspn(p,"{");
 +      int end = strcspn(p,"}");
 +      
 +      strncpy(gsensororatation,p+start,end-start+1);
 +      char *tmp=gsensororatation;
 +      
 +
 +      while(strncmp(tmp,"}",1)!=0)
 +       {
 +              if((strncmp(tmp,",",1)==0)||(strncmp(tmp,"{",1)==0))
 +              {
 +                      
 +                       tmp++;         
 +                       continue;
 +              }       
 +              else if(strncmp(tmp,"-",1)==0)
 +              {
 +                      pdata->orientation[i++]=-1;
 +                      DBG("i=%d,data=%d\n",i,pdata->orientation[i]);
 +                       tmp++;
 +              }               
 +              else
 +              {
 +                      pdata->orientation[i++]=tmp[0]-48;              
 +                      DBG("----i=%d,data=%d\n",i,pdata->orientation[i]);      
 +              }       
 +              tmp++;
 +      
 +                                              
 +       }
 +
 +      for(i=0;i<9;i++)
 +              DBG("i=%d gsensor_info=%d\n",i,pdata->orientation[i]);
 +      return 0;
 +
 +}
 +
 +static CLASS_ATTR(oratiention, 0777, NULL,sensor_setoratitention);
 +
 +static int  sensor_sys_init(void)
 +{
 +      int ret ;
 +      sensor_class = class_create(THIS_MODULE, "gsensor");
 +      ret =  class_create_file(sensor_class, &class_attr_oratiention);
 +      if (ret)
 +      {
 +       printk("Fail to creat class oratiention.\n");
 +      }
 +      return 0;
 +}
 +
++
 +/****************operate according to sensor chip:start************/
 +
 +static int sensor_active(struct i2c_client *client, int enable, int rate)
 +{
 +      struct sensor_private_data *sensor =
 +          (struct sensor_private_data *) i2c_get_clientdata(client);  
 +      int result = 0;
 +      int status = 0;
 +              
 +      sensor->ops->ctrl_data = sensor_read_reg(client, sensor->ops->ctrl_reg);
 +
 +      sensor->ops->ctrl_data |= ODR100;       //100HZ,if 0 then power down
 +      
 +      //register setting according to chip datasheet          
 +      if(!enable)
 +      {       
 +              status = LIS3DH_ACC_DISABLE;    //lis3dh        
 +              sensor->ops->ctrl_data |= status;       
 +      }
 +      else
 +      {
 +              status = ~LIS3DH_ACC_DISABLE;   //lis3dh
 +              sensor->ops->ctrl_data &= status;
 +      }
 +
 +      DBG("%s:reg=0x%x,reg_ctrl=0x%x,enable=%d\n",__func__,sensor->ops->ctrl_reg, sensor->ops->ctrl_data, enable);
 +      result = sensor_write_reg(client, sensor->ops->ctrl_reg, sensor->ops->ctrl_data);
 +      if(result)
 +              printk("%s:fail to active sensor\n",__func__);
 +      
 +      return result;
 +
 +}
 +
 +static int sensor_init(struct i2c_client *client)
 +{     
 +      struct sensor_private_data *sensor =
 +          (struct sensor_private_data *) i2c_get_clientdata(client);  
 +      int result = 0;
 +      int i;
 +      struct sensor_reg_data reg_data[] = 
 +      {                       
 +              {LIS3DH_CTRL_REG2,0X00},                        
 +              {LIS3DH_CTRL_REG4,0x08},        //High resolution output mode: 1, Normal mode   
 +              {LIS3DH_CTRL_REG6,0x40},        
 +              {LIS3DH_TEMP_CFG_REG,0x00},     //
 +              {LIS3DH_FIFO_CTRL_REG,0x00},    //      
 +              {LIS3DH_INT1_CFG,0xFF},         //6 direction position recognition      
 +              {LIS3DH_INT1_THS,0x7F},         //Interrupt 1 threshold 
 +              {LIS3DH_INT1_DURATION,0x7F},    //Duration value 0x00->ox7f
 +      };  
 +      
 +      result = sensor->ops->active(client,0,0);
 +      if(result)
 +      {
 +              printk("%s:line=%d,error\n",__func__,__LINE__);
 +              return result;
 +      }
-       this_client = client;
-       
++      lis3dgh_client = client;
++
 +      sensor->status_cur = SENSOR_OFF;
 +      
 +      for(i=0;i<(sizeof(reg_data)/sizeof(struct sensor_reg_data));i++)
 +      {
 +              result = sensor_write_reg(client, reg_data[i].reg, reg_data[i].data);
 +              if(result)
 +              {
 +                      printk("%s:line=%d,i=%d,error\n",__func__,__LINE__,i);
 +                      return result;
 +              }
 +      }
 +
 +      
 +      if(sensor->pdata->irq_enable)
 +      {
 +
 +              result = sensor_write_reg(client, LIS3DH_CTRL_REG3, 0x40);//I1_AOI1 =1  if motion       
 +              if(result)
 +              {
 +                      printk("%s:line=%d,error\n",__func__,__LINE__);
 +                      return result;
 +              }
 +
 +              result = sensor_write_reg(client, LIS3DH_CTRL_REG5, 0x08);
 +              if(result)
 +              {
 +                      printk("%s:line=%d,error\n",__func__,__LINE__);
 +                      return result;
 +              }
 +
 +      }
-       sensor_sys_init();
 +      
++      sensor_sys_init();
 +      return result;
 +}
 +
 +static int sensor_convert_data(struct i2c_client *client, char high_byte, char low_byte)
 +{
 +      s64 result;
 +      struct sensor_private_data *sensor =
 +          (struct sensor_private_data *) i2c_get_clientdata(client);  
 +      //int precision = sensor->ops->precision;
 +      switch (sensor->devid) {        
 +              case LIS3DH_DEVID:              
 +                      result = ((int)high_byte << 8) | (int)low_byte;
 +                      if (result < LIS3DH_BOUNDARY)
 +                              result = result* LIS3DH_GRAVITY_STEP;
 +              else
 +                              result = ~( ((~result & (0x7fff>>(16-LIS3DH_PRECISION)) ) + 1) 
 +                                              * LIS3DH_GRAVITY_STEP) + 1;
 +                      break;
 +
 +              default:
 +                      printk(KERN_ERR "%s: devid wasn't set correctly\n",__func__);
 +                      return -EFAULT;
 +    }
 +
 +    return (int)result;
 +}
 +
 +static int gsensor_report_value(struct i2c_client *client, struct sensor_axis *axis)
 +{
 +      struct sensor_private_data *sensor =
 +              (struct sensor_private_data *) i2c_get_clientdata(client);      
 +
 +      /* Report acceleration sensor information */
 +      input_report_abs(sensor->input_dev, ABS_X, axis->x);
 +      input_report_abs(sensor->input_dev, ABS_Y, axis->y);
 +      input_report_abs(sensor->input_dev, ABS_Z, axis->z);
 +      input_sync(sensor->input_dev);
 +      DBG("Gsensor x==%d  y==%d z==%d\n",axis->x,axis->y,axis->z);
 +
 +      return 0;
 +}
 +
 +#define GSENSOR_MIN  10
 +static int sensor_report_value(struct i2c_client *client)
 +{
 +      struct sensor_private_data *sensor =
 +                      (struct sensor_private_data *) i2c_get_clientdata(client);      
 +      struct sensor_platform_data *pdata = sensor->pdata;
 +      int ret = 0;
 +      int x,y,z;
 +      struct sensor_axis axis;        
 +      char buffer[6] = {0};   
 +      char value = 0;
 +      
 +      if(sensor->ops->read_len < 6)   //sensor->ops->read_len = 6
 +      {
 +              printk("%s:lenth is error,len=%d\n",__func__,sensor->ops->read_len);
 +              return -1;
 +      }
 +      
 +      memset(buffer, 0, 6);
 +
 +      value = sensor_read_reg(client, LIS3DH_STATUS_REG);
 +      if((value & 0x0f) == 0)
 +      {
 +              printk("%s:line=%d,value=0x%x,data is not ready\n",__func__,__LINE__,value);
 +              return -1;
 +      }
 +              
 +      
 +      /* Data bytes from hardware xL, xH, yL, yH, zL, zH */   
 +      do {
 +              *buffer = sensor->ops->read_reg;
 +              ret = sensor_rx_data(client, buffer, sensor->ops->read_len);
 +              if (ret < 0)
 +              return ret;
 +      } while (0);
 +
 +      //this gsensor need 6 bytes buffer
 +      x = sensor_convert_data(sensor->client, buffer[1], buffer[0]);  //buffer[1]:high bit 
 +      y = sensor_convert_data(sensor->client, buffer[3], buffer[2]);
 +      z = sensor_convert_data(sensor->client, buffer[5], buffer[4]);          
 +
 +      axis.x = (pdata->orientation[0])*x + (pdata->orientation[1])*y + (pdata->orientation[2])*z;
 +      axis.y = (pdata->orientation[3])*x + (pdata->orientation[4])*y + (pdata->orientation[5])*z;     
 +      axis.z = (pdata->orientation[6])*x + (pdata->orientation[7])*y + (pdata->orientation[8])*z;
 +
 +      DBG( "%s: axis = %d  %d  %d \n", __func__, axis.x, axis.y, axis.z);
 +
 +      //Report event  only while value is changed to save some power
 +      if((abs(sensor->axis.x - axis.x) > GSENSOR_MIN) || (abs(sensor->axis.y - axis.y) > GSENSOR_MIN) || (abs(sensor->axis.z - axis.z) > GSENSOR_MIN))
 +      {
 +              gsensor_report_value(client, &axis);
 +
 +              /* »¥³âµØ»º´æÊý¾Ý. */
 +              mutex_lock(&(sensor->data_mutex) );
 +              sensor->axis = axis;
 +              mutex_unlock(&(sensor->data_mutex) );
 +      }
 +
 +      if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0))    //read sensor intterupt status register
 +      {
 +              
 +              value = sensor_read_reg(client, sensor->ops->int_status_reg);
 +              DBG("%s:sensor int status :0x%x\n",__func__,value);
 +      }
 +      
 +      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
 +      .read_reg                       = (LIS3DH_OUT_X_L | 0x80),      //read data
 +      .read_len                       = 6,                            //data length
 +      .id_reg                         = LIS3DH_WHO_AM_I,              //read device id from this register
 +      .id_data                        = LIS3DH_DEVID,                 //device id
 +      .precision                      = LIS3DH_PRECISION,             //12 bits
 +      .ctrl_reg                       = LIS3DH_CTRL_REG1,             //enable or disable 
 +      .int_status_reg                 = LIS3DH_INT1_SRC,              //intterupt status register
 +      .range                          = {-LIS3DH_RANGE,LIS3DH_RANGE}, //range
 +      .trig                           = (IRQF_TRIGGER_LOW|IRQF_ONESHOT),              
 +      .active                         = sensor_active,        
 +      .init                           = sensor_init,
 +      .report                         = sensor_report_value,
 +};
 +
 +/****************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;
 +      int type = ops->type;
 +      result = sensor_register_slave(type, NULL, NULL, gsensor_get_ops);
 +      printk("%s\n",__func__);
 +      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;
 +      sensor_unregister_slave(type, NULL, NULL, gsensor_get_ops);
 +}
 +
 +
- module_init(gsensor_init);
- module_exit(gsensor_exit);
++module_init(gsensor_lis3dh_init);
++module_exit(gsensor_lis3dh_exit);
 +
 +
index bb698d46ca72dbca78df65063f6a7604fe0f765a,c489c95ce54a3326b7113f568101f684af6c5eee..5258a8b0e51051ae1c7254ae07b6b956623b1b7d
 -/* drivers/input/sensors/access/mma8452.c\r
 - *\r
 - * Copyright (C) 2012-2015 ROCKCHIP.\r
 - * Author: luowei <lw@rock-chips.com>\r
 - *\r
 - * This software is licensed under the terms of the GNU General Public\r
 - * License version 2, as published by the Free Software Foundation, and\r
 - * may be copied, distributed, and modified under those terms.\r
 - *\r
 - * This program is distributed in the hope that it will be useful,\r
 - * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
 - * GNU General Public License for more details.\r
 - *\r
 - */\r
 -#include <linux/interrupt.h>\r
 -#include <linux/i2c.h>\r
 -#include <linux/slab.h>\r
 -#include <linux/irq.h>\r
 -#include <linux/miscdevice.h>\r
 -#include <linux/gpio.h>\r
 -#include <asm/uaccess.h>\r
 -#include <asm/atomic.h>\r
 -#include <linux/delay.h>\r
 -#include <linux/input.h>\r
 -#include <linux/workqueue.h>\r
 -#include <linux/freezer.h>\r
 -#include <mach/gpio.h>\r
 -#include <mach/board.h> \r
 -#ifdef CONFIG_HAS_EARLYSUSPEND\r
 -#include <linux/earlysuspend.h>\r
 -#endif\r
 -#include <linux/mma8452.h>\r
 -#include <linux/sensor-dev.h>\r
 -\r
 -#if 0\r
 -#define SENSOR_DEBUG_TYPE SENSOR_TYPE_ACCEL\r
 -#define DBG(x...) if(sensor->pdata->type == SENSOR_DEBUG_TYPE) printk(x)\r
 -#else\r
 -#define DBG(x...)\r
 -#endif\r
 -\r
 -\r
 -#define MMA8451_DEVID         0x1a\r
 -#define MMA8452_DEVID         0x2a\r
 -#define MMA8453_DEVID         0x3a\r
 -\r
 -#define MMA8452_ENABLE                1\r
 -\r
 -\r
 -/****************operate according to sensor chip:start************/\r
 -\r
 -static int sensor_active(struct i2c_client *client, int enable, int rate)\r
 -{\r
 -      struct sensor_private_data *sensor =\r
 -          (struct sensor_private_data *) i2c_get_clientdata(client);  \r
 -      int result = 0;\r
 -      int status = 0;\r
 -              \r
 -      sensor->ops->ctrl_data = sensor_read_reg(client, sensor->ops->ctrl_reg);\r
 -      \r
 -      //register setting according to chip datasheet          \r
 -      if(enable)\r
 -      {       \r
 -              status = MMA8452_ENABLE;        //mma8452\r
 -              sensor->ops->ctrl_data |= status;       \r
 -      }\r
 -      else\r
 -      {\r
 -              status = ~MMA8452_ENABLE;       //mma8452\r
 -              sensor->ops->ctrl_data &= status;\r
 -      }\r
 -\r
 -      DBG("%s:reg=0x%x,reg_ctrl=0x%x,enable=%d\n",__func__,sensor->ops->ctrl_reg, sensor->ops->ctrl_data, enable);\r
 -      result = sensor_write_reg(client, sensor->ops->ctrl_reg, sensor->ops->ctrl_data);\r
 -      if(result)\r
 -              printk("%s:fail to active sensor\n",__func__);\r
 -      \r
 -      return result;\r
 -\r
 -}\r
 -\r
 -static int sensor_init(struct i2c_client *client)\r
 -{\r
 -      int tmp;\r
 -      int ret = 0;\r
 -      struct sensor_private_data *sensor =\r
 -          (struct sensor_private_data *) i2c_get_clientdata(client);  \r
 -      \r
 -      ret = sensor->ops->active(client,0,0);\r
 -      if(ret)\r
 -      {\r
 -              printk("%s:line=%d,error\n",__func__,__LINE__);\r
 -              return ret;\r
 -      }\r
 -      \r
 -      sensor->status_cur = SENSOR_OFF;\r
 -\r
 -      /* disable FIFO  FMODE = 0*/\r
 -      ret = sensor_write_reg(client,MMA8452_REG_F_SETUP,0);\r
 -      DBG("%s: MMA8452_REG_F_SETUP:%x\n",__func__, sensor_read_reg(client,MMA8452_REG_F_SETUP));\r
 -\r
 -      /* set full scale range to 2g */\r
 -      ret = sensor_write_reg(client,MMA8452_REG_XYZ_DATA_CFG,0);\r
 -      DBG("%s: MMA8452_REG_XYZ_DATA_CFG:%x\n",__func__, sensor_read_reg(client,MMA8452_REG_XYZ_DATA_CFG));\r
 -\r
 -      /* set bus 8bit/14bit(FREAD = 1,FMODE = 0) ,data rate*/\r
 -      tmp = (MMA8452_RATE_12P5<< MMA8452_RATE_SHIFT) | FREAD_MASK;\r
 -      ret = sensor_write_reg(client,MMA8452_REG_CTRL_REG1,tmp);\r
 -\r
 -      sensor->ops->ctrl_data = tmp;\r
 -      \r
 -      DBG("mma8452 MMA8452_REG_CTRL_REG1:%x\n",sensor_read_reg(client,MMA8452_REG_CTRL_REG1));\r
 -      \r
 -      DBG("mma8452 MMA8452_REG_SYSMOD:%x\n",sensor_read_reg(client,MMA8452_REG_SYSMOD));\r
 -\r
 -      ret = sensor_write_reg(client,MMA8452_REG_CTRL_REG3,5);\r
 -      DBG("mma8452 MMA8452_REG_CTRL_REG3:%x\n",sensor_read_reg(client,MMA8452_REG_CTRL_REG3));\r
 -      \r
 -      ret = sensor_write_reg(client,MMA8452_REG_CTRL_REG4,1);\r
 -      DBG("mma8452 MMA8452_REG_CTRL_REG4:%x\n",sensor_read_reg(client,MMA8452_REG_CTRL_REG4));\r
 -\r
 -      ret = sensor_write_reg(client,MMA8452_REG_CTRL_REG5,1);\r
 -      DBG("mma8452 MMA8452_REG_CTRL_REG5:%x\n",sensor_read_reg(client,MMA8452_REG_CTRL_REG5));        \r
 -\r
 -      DBG("mma8452 MMA8452_REG_SYSMOD:%x\n",sensor_read_reg(client,MMA8452_REG_SYSMOD));\r
 -\r
 -      return ret;\r
 -}\r
 -\r
 -static int sensor_convert_data(struct i2c_client *client, char high_byte, char low_byte)\r
 -{\r
 -    s64 result;\r
 -      struct sensor_private_data *sensor =\r
 -          (struct sensor_private_data *) i2c_get_clientdata(client);  \r
 -      //int precision = sensor->ops->precision;\r
 -      switch (sensor->devid) {\r
 -              case MMA8451_DEVID:     \r
 -                      swap(high_byte,low_byte);\r
 -                      result = ((int)high_byte << (MMA8451_PRECISION-8)) \r
 -                                      | ((int)low_byte >> (16-MMA8451_PRECISION));\r
 -                      if (result < MMA8451_BOUNDARY)\r
 -                              result = result* MMA8451_GRAVITY_STEP;\r
 -                      else\r
 -                              result = ~( ((~result & (0x7fff>>(16-MMA8451_PRECISION)) ) + 1) \r
 -                                              * MMA8451_GRAVITY_STEP) + 1;\r
 -                      break;\r
 -\r
 -              case MMA8452_DEVID:                     \r
 -                      swap(high_byte,low_byte);\r
 -                      result = ((int)high_byte << (MMA8452_PRECISION-8)) \r
 -                                      | ((int)low_byte >> (16-MMA8452_PRECISION));\r
 -                      if (result < MMA8452_BOUNDARY)\r
 -                              result = result* MMA8452_GRAVITY_STEP;\r
 -                      else\r
 -                              result = ~( ((~result & (0x7fff>>(16-MMA8452_PRECISION)) ) + 1) \r
 -                                              * MMA8452_GRAVITY_STEP) + 1;\r
 -                      break;\r
 -                      \r
 -              case MMA8453_DEVID:             \r
 -                      swap(high_byte,low_byte);\r
 -                      result = ((int)high_byte << (MMA8453_PRECISION-8)) \r
 -                                      | ((int)low_byte >> (16-MMA8453_PRECISION));\r
 -                      if (result < MMA8453_BOUNDARY)\r
 -                              result = result* MMA8453_GRAVITY_STEP;\r
 -                      else\r
 -                              result = ~( ((~result & (0x7fff>>(16-MMA8453_PRECISION)) ) + 1) \r
 -                                              * MMA8453_GRAVITY_STEP) + 1;\r
 -                      break;\r
 -\r
 -              default:\r
 -                      printk(KERN_ERR "%s: devid wasn't set correctly\n",__func__);\r
 -                      return -EFAULT;\r
 -    }\r
 -\r
 -    return (int)result;\r
 -}\r
 -\r
 -static int gsensor_report_value(struct i2c_client *client, struct sensor_axis *axis)\r
 -{\r
 -      struct sensor_private_data *sensor =\r
 -          (struct sensor_private_data *) i2c_get_clientdata(client);  \r
 -\r
 -      /* Report acceleration sensor information */\r
 -      input_report_abs(sensor->input_dev, ABS_X, axis->x);\r
 -      input_report_abs(sensor->input_dev, ABS_Y, axis->y);\r
 -      input_report_abs(sensor->input_dev, ABS_Z, axis->z);\r
 -      input_sync(sensor->input_dev);\r
 -      DBG("Gsensor x==%d  y==%d z==%d\n",axis->x,axis->y,axis->z);\r
 -\r
 -      return 0;\r
 -}\r
 -\r
 -#define GSENSOR_MIN           10\r
 -static int sensor_report_value(struct i2c_client *client)\r
 -{\r
 -      struct sensor_private_data *sensor =\r
 -              (struct sensor_private_data *) i2c_get_clientdata(client);      \r
 -      struct sensor_platform_data *pdata = sensor->pdata;\r
 -      int ret = 0;\r
 -      int x,y,z;\r
 -      struct sensor_axis axis;\r
 -      char buffer[6] = {0};   \r
 -      char value = 0;\r
 -      \r
 -      if(sensor->ops->read_len < 6)   //sensor->ops->read_len = 6\r
 -      {\r
 -              printk("%s:lenth is error,len=%d\n",__func__,sensor->ops->read_len);\r
 -              return -1;\r
 -      }\r
 -      \r
 -      memset(buffer, 0, 6);\r
 -      \r
 -      /* Data bytes from hardware xL, xH, yL, yH, zL, zH */   \r
 -      do {\r
 -              *buffer = sensor->ops->read_reg;\r
 -              ret = sensor_rx_data(client, buffer, sensor->ops->read_len);\r
 -              if (ret < 0)\r
 -              return ret;\r
 -      } while (0);\r
 -\r
 -\r
 -      //this gsensor need 6 bytes buffer\r
 -      x = sensor_convert_data(sensor->client, buffer[1], buffer[0]);  //buffer[1]:high bit \r
 -      y = sensor_convert_data(sensor->client, buffer[3], buffer[2]);\r
 -      z = sensor_convert_data(sensor->client, buffer[5], buffer[4]);          \r
 -\r
 -      axis.x = (pdata->orientation[0])*x + (pdata->orientation[1])*y + (pdata->orientation[2])*z;\r
 -      axis.y = (pdata->orientation[3])*x + (pdata->orientation[4])*y + (pdata->orientation[5])*z; \r
 -      axis.z = (pdata->orientation[6])*x + (pdata->orientation[7])*y + (pdata->orientation[8])*z;\r
 -\r
 -      DBG( "%s: axis = %d  %d  %d \n", __func__, axis.x, axis.y, axis.z);\r
 -\r
 -      //Report event only while value is changed to save some power\r
 -      if((abs(sensor->axis.x - axis.x) > GSENSOR_MIN) || (abs(sensor->axis.y - axis.y) > GSENSOR_MIN) || (abs(sensor->axis.z - axis.z) > GSENSOR_MIN))\r
 -      {\r
 -              gsensor_report_value(client, &axis);\r
 -\r
 -              /* »¥³âµØ»º´æÊý¾Ý. */\r
 -              mutex_lock(&(sensor->data_mutex) );\r
 -              sensor->axis = axis;\r
 -              mutex_unlock(&(sensor->data_mutex) );\r
 -      }\r
 -\r
 -      if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0))    //read sensor intterupt status register\r
 -      {\r
 -              \r
 -              value = sensor_read_reg(client, sensor->ops->int_status_reg);\r
 -              DBG("%s:sensor int status :0x%x\n",__func__,value);\r
 -      }\r
 -      \r
 -      return ret;\r
 -}\r
 -\r
 -\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
 -      .read_reg                       = MMA8452_REG_X_OUT_MSB,                //read data\r
 -      .read_len                       = 6,                                    //data length\r
 -      .id_reg                         = MMA8452_REG_WHO_AM_I,                 //read device id from this register\r
 -      .id_data                        = MMA8452_DEVID,                        //device id\r
 -      .precision                      = MMA8452_PRECISION,                    //12 bit\r
 -      .ctrl_reg                       = MMA8452_REG_CTRL_REG1,                //enable or disable     \r
 -      .int_status_reg                 = MMA8452_REG_INTSRC,                   //intterupt status register\r
 -      .range                          = {-MMA845X_RANGE,MMA845X_RANGE},       //range\r
 -      .trig                           = IRQF_TRIGGER_LOW|IRQF_ONESHOT,                \r
 -      .active                         = sensor_active,        \r
 -      .init                           = sensor_init,\r
 -      .report                         = sensor_report_value,\r
 -};\r
 -\r
 -/****************operate according to sensor chip:end************/\r
 -\r
 -//function name should not be changed\r
 -static struct sensor_operate *gsensor_get_ops(void)\r
 -{\r
 -      return &gsensor_mma8452_ops;\r
 -}\r
 -\r
 -\r
 -static int __init gsensor_mma8452_init(void)\r
 -{\r
 -      struct sensor_operate *ops = gsensor_get_ops();\r
 -      int result = 0;\r
 -      int type = ops->type;\r
 -      result = sensor_register_slave(type, NULL, NULL, gsensor_get_ops);      \r
 -      printk("%s\n",__func__);\r
 -      return result;\r
 -}\r
 -\r
 -static void __exit gsensor_mma8452_exit(void)\r
 -{\r
 -      struct sensor_operate *ops = gsensor_get_ops();\r
 -      int type = ops->type;\r
 -      sensor_unregister_slave(type, NULL, NULL, gsensor_get_ops);\r
 -}\r
 -\r
 -\r
 -module_init(gsensor_mma8452_init);\r
 -module_exit(gsensor_mma8452_exit);\r
 -\r
 -\r
 -\r
 +/* drivers/input/sensors/access/mma8452.c
 + *
 + * Copyright (C) 2012-2015 ROCKCHIP.
 + * Author: luowei <lw@rock-chips.com>
 + *
 + * This software is licensed under the terms of the GNU General Public
 + * License version 2, as published by the Free Software Foundation, and
 + * may be copied, distributed, and modified under those terms.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + */
 +#include <linux/interrupt.h>
 +#include <linux/i2c.h>
 +#include <linux/slab.h>
 +#include <linux/irq.h>
 +#include <linux/miscdevice.h>
 +#include <linux/gpio.h>
 +#include <asm/uaccess.h>
 +#include <asm/atomic.h>
 +#include <linux/delay.h>
 +#include <linux/input.h>
 +#include <linux/workqueue.h>
 +#include <linux/freezer.h>
 +#include <mach/gpio.h>
 +#include <mach/board.h> 
 +#ifdef CONFIG_HAS_EARLYSUSPEND
 +#include <linux/earlysuspend.h>
 +#endif
 +#include <linux/mma8452.h>
 +#include <linux/sensor-dev.h>
 +
 +#if 0
 +#define SENSOR_DEBUG_TYPE SENSOR_TYPE_ACCEL
 +#define DBG(x...) if(sensor->pdata->type == SENSOR_DEBUG_TYPE) printk(x)
 +#else
 +#define DBG(x...)
 +#endif
 +
 +
 +#define MMA8451_DEVID         0x1a
 +#define MMA8452_DEVID         0x2a
 +#define MMA8453_DEVID         0x3a
 +
 +#define MMA8452_ENABLE                1
 +
- struct i2c_client *this_client=NULL;
++
++struct i2c_client *mma8452_client=NULL;
 +static struct class *sensor_class = NULL;
 +
 +static ssize_t sensor_setoratitention(struct device *dev,
 +              struct device_attribute *attr, char *buf)
 +{
 +      int i=0;
 +      char gsensororatation[20];
 +      
 +      struct sensor_private_data *sensor =
-           (struct sensor_private_data *) i2c_get_clientdata(this_client);     
++          (struct sensor_private_data *) i2c_get_clientdata(mma8452_client);  
 +      struct sensor_platform_data *pdata = sensor->pdata;
 +
 +      
 +      char *p = strstr(buf,"gsensor");
 +      int start = strcspn(p,"{");
 +      int end = strcspn(p,"}");
 +      
 +      strncpy(gsensororatation,p+start,end-start+1);
 +      char *tmp=gsensororatation;
 +      
 +
 +      while(strncmp(tmp,"}",1)!=0)
 +       {
 +              if((strncmp(tmp,",",1)==0)||(strncmp(tmp,"{",1)==0))
 +              {
 +                      
 +                       tmp++;         
 +                       continue;
 +              }       
 +              else if(strncmp(tmp,"-",1)==0)
 +              {
 +                      pdata->orientation[i++]=-1;
 +                      DBG("i=%d,data=%d\n",i,pdata->orientation[i]);
 +                       tmp++;
 +              }               
 +              else
 +              {
 +                      pdata->orientation[i++]=tmp[0]-48;              
 +                      DBG("----i=%d,data=%d\n",i,pdata->orientation[i]);      
 +              }       
 +              tmp++;
 +      
 +                                              
 +       }
 +
 +      for(i=0;i<9;i++)
 +              DBG("i=%d gsensor_info=%d\n",i,pdata->orientation[i]);
 +      return 0;
 +
 +}
 +
 +static CLASS_ATTR(oratiention, 0777, NULL,sensor_setoratitention);
 +
 +static int  sensor_sys_init(void)
 +{
 +      int ret ;
 +      sensor_class = class_create(THIS_MODULE, "gsensor");
 +      ret =  class_create_file(sensor_class, &class_attr_oratiention);
 +      if (ret)
 +      {
 +       printk("Fail to creat class oratiention.\n");
 +      }
 +      return 0;
 +}
 +
++
 +/****************operate according to sensor chip:start************/
 +
 +static int sensor_active(struct i2c_client *client, int enable, int rate)
 +{
 +      struct sensor_private_data *sensor =
 +          (struct sensor_private_data *) i2c_get_clientdata(client);  
 +      int result = 0;
 +      int status = 0;
 +              
 +      sensor->ops->ctrl_data = sensor_read_reg(client, sensor->ops->ctrl_reg);
 +      
 +      //register setting according to chip datasheet          
 +      if(enable)
 +      {       
 +              status = MMA8452_ENABLE;        //mma8452
 +              sensor->ops->ctrl_data |= status;       
 +      }
 +      else
 +      {
 +              status = ~MMA8452_ENABLE;       //mma8452
 +              sensor->ops->ctrl_data &= status;
 +      }
 +
 +      DBG("%s:reg=0x%x,reg_ctrl=0x%x,enable=%d\n",__func__,sensor->ops->ctrl_reg, sensor->ops->ctrl_data, enable);
 +      result = sensor_write_reg(client, sensor->ops->ctrl_reg, sensor->ops->ctrl_data);
 +      if(result)
 +              printk("%s:fail to active sensor\n",__func__);
 +      
 +      return result;
 +
 +}
 +
 +static int sensor_init(struct i2c_client *client)
 +{
 +      int tmp;
 +      int ret = 0;
 +      struct sensor_private_data *sensor =
 +          (struct sensor_private_data *) i2c_get_clientdata(client);  
 +      
 +      ret = sensor->ops->active(client,0,0);
 +      if(ret)
 +      {
 +              printk("%s:line=%d,error\n",__func__,__LINE__);
 +              return ret;
 +      }
-       this_client=client;
 +      
++      mma8452_client=client;
 +      sensor->status_cur = SENSOR_OFF;
 +
 +      /* disable FIFO  FMODE = 0*/
 +      ret = sensor_write_reg(client,MMA8452_REG_F_SETUP,0);
 +      DBG("%s: MMA8452_REG_F_SETUP:%x\n",__func__, sensor_read_reg(client,MMA8452_REG_F_SETUP));
 +
 +      /* set full scale range to 2g */
 +      ret = sensor_write_reg(client,MMA8452_REG_XYZ_DATA_CFG,0);
 +      DBG("%s: MMA8452_REG_XYZ_DATA_CFG:%x\n",__func__, sensor_read_reg(client,MMA8452_REG_XYZ_DATA_CFG));
 +
 +      /* set bus 8bit/14bit(FREAD = 1,FMODE = 0) ,data rate*/
 +      tmp = (MMA8452_RATE_12P5<< MMA8452_RATE_SHIFT) | FREAD_MASK;
 +      ret = sensor_write_reg(client,MMA8452_REG_CTRL_REG1,tmp);
 +
 +      sensor->ops->ctrl_data = tmp;
 +      
 +      DBG("mma8452 MMA8452_REG_CTRL_REG1:%x\n",sensor_read_reg(client,MMA8452_REG_CTRL_REG1));
 +      
 +      DBG("mma8452 MMA8452_REG_SYSMOD:%x\n",sensor_read_reg(client,MMA8452_REG_SYSMOD));
 +
 +      ret = sensor_write_reg(client,MMA8452_REG_CTRL_REG3,5);
 +      DBG("mma8452 MMA8452_REG_CTRL_REG3:%x\n",sensor_read_reg(client,MMA8452_REG_CTRL_REG3));
 +      
 +      ret = sensor_write_reg(client,MMA8452_REG_CTRL_REG4,1);
 +      DBG("mma8452 MMA8452_REG_CTRL_REG4:%x\n",sensor_read_reg(client,MMA8452_REG_CTRL_REG4));
 +
 +      ret = sensor_write_reg(client,MMA8452_REG_CTRL_REG5,1);
 +      DBG("mma8452 MMA8452_REG_CTRL_REG5:%x\n",sensor_read_reg(client,MMA8452_REG_CTRL_REG5));        
 +
 +      DBG("mma8452 MMA8452_REG_SYSMOD:%x\n",sensor_read_reg(client,MMA8452_REG_SYSMOD));
 +
 +      sensor_sys_init();
 +
 +      return ret;
 +}
 +
 +static int sensor_convert_data(struct i2c_client *client, char high_byte, char low_byte)
 +{
 +    s64 result;
 +      struct sensor_private_data *sensor =
 +          (struct sensor_private_data *) i2c_get_clientdata(client);  
 +      //int precision = sensor->ops->precision;
 +      switch (sensor->devid) {
 +              case MMA8451_DEVID:     
 +                      swap(high_byte,low_byte);
 +                      result = ((int)high_byte << (MMA8451_PRECISION-8)) 
 +                                      | ((int)low_byte >> (16-MMA8451_PRECISION));
 +                      if (result < MMA8451_BOUNDARY)
 +                              result = result* MMA8451_GRAVITY_STEP;
 +                      else
 +                              result = ~( ((~result & (0x7fff>>(16-MMA8451_PRECISION)) ) + 1) 
 +                                              * MMA8451_GRAVITY_STEP) + 1;
 +                      break;
 +
 +              case MMA8452_DEVID:                     
 +                      swap(high_byte,low_byte);
 +                      result = ((int)high_byte << (MMA8452_PRECISION-8)) 
 +                                      | ((int)low_byte >> (16-MMA8452_PRECISION));
 +                      if (result < MMA8452_BOUNDARY)
 +                              result = result* MMA8452_GRAVITY_STEP;
 +                      else
 +                              result = ~( ((~result & (0x7fff>>(16-MMA8452_PRECISION)) ) + 1) 
 +                                              * MMA8452_GRAVITY_STEP) + 1;
 +                      break;
 +                      
 +              case MMA8453_DEVID:             
 +                      swap(high_byte,low_byte);
 +                      result = ((int)high_byte << (MMA8453_PRECISION-8)) 
 +                                      | ((int)low_byte >> (16-MMA8453_PRECISION));
 +                      if (result < MMA8453_BOUNDARY)
 +                              result = result* MMA8453_GRAVITY_STEP;
 +                      else
 +                              result = ~( ((~result & (0x7fff>>(16-MMA8453_PRECISION)) ) + 1) 
 +                                              * MMA8453_GRAVITY_STEP) + 1;
 +                      break;
 +
 +              default:
 +                      printk(KERN_ERR "%s: devid wasn't set correctly\n",__func__);
 +                      return -EFAULT;
 +    }
 +
 +    return (int)result;
 +}
 +
 +static int gsensor_report_value(struct i2c_client *client, struct sensor_axis *axis)
 +{
 +      struct sensor_private_data *sensor =
 +          (struct sensor_private_data *) i2c_get_clientdata(client);  
 +
 +      /* Report acceleration sensor information */
 +      input_report_abs(sensor->input_dev, ABS_X, axis->x);
 +      input_report_abs(sensor->input_dev, ABS_Y, axis->y);
 +      input_report_abs(sensor->input_dev, ABS_Z, axis->z);
 +      input_sync(sensor->input_dev);
 +      DBG("Gsensor x==%d  y==%d z==%d\n",axis->x,axis->y,axis->z);
 +
 +      return 0;
 +}
 +
 +#define GSENSOR_MIN           10
 +static int sensor_report_value(struct i2c_client *client)
 +{
 +      struct sensor_private_data *sensor =
 +              (struct sensor_private_data *) i2c_get_clientdata(client);      
 +      struct sensor_platform_data *pdata = sensor->pdata;
 +      int ret = 0;
 +      int x,y,z;
 +      struct sensor_axis axis;
 +      char buffer[6] = {0};   
 +      char value = 0;
 +      
 +      if(sensor->ops->read_len < 6)   //sensor->ops->read_len = 6
 +      {
 +              printk("%s:lenth is error,len=%d\n",__func__,sensor->ops->read_len);
 +              return -1;
 +      }
 +      
 +      memset(buffer, 0, 6);
 +      
 +      /* Data bytes from hardware xL, xH, yL, yH, zL, zH */   
 +      do {
 +              *buffer = sensor->ops->read_reg;
 +              ret = sensor_rx_data(client, buffer, sensor->ops->read_len);
 +              if (ret < 0)
 +              return ret;
 +      } while (0);
 +
 +
 +      //this gsensor need 6 bytes buffer
 +      x = sensor_convert_data(sensor->client, buffer[1], buffer[0]);  //buffer[1]:high bit 
 +      y = sensor_convert_data(sensor->client, buffer[3], buffer[2]);
 +      z = sensor_convert_data(sensor->client, buffer[5], buffer[4]);          
 +
 +      axis.x = (pdata->orientation[0])*x + (pdata->orientation[1])*y + (pdata->orientation[2])*z;
 +      axis.y = (pdata->orientation[3])*x + (pdata->orientation[4])*y + (pdata->orientation[5])*z; 
 +      axis.z = (pdata->orientation[6])*x + (pdata->orientation[7])*y + (pdata->orientation[8])*z;
 +
 +      DBG( "%s: axis = %d  %d  %d \n", __func__, axis.x, axis.y, axis.z);
 +
 +      //Report event only while value is changed to save some power
 +      if((abs(sensor->axis.x - axis.x) > GSENSOR_MIN) || (abs(sensor->axis.y - axis.y) > GSENSOR_MIN) || (abs(sensor->axis.z - axis.z) > GSENSOR_MIN))
 +      {
 +              gsensor_report_value(client, &axis);
 +
 +              /* »¥³âµØ»º´æÊý¾Ý. */
 +              mutex_lock(&(sensor->data_mutex) );
 +              sensor->axis = axis;
 +              mutex_unlock(&(sensor->data_mutex) );
 +      }
 +
 +      if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0))    //read sensor intterupt status register
 +      {
 +              
 +              value = sensor_read_reg(client, sensor->ops->int_status_reg);
 +              DBG("%s:sensor int status :0x%x\n",__func__,value);
 +      }
 +      
 +      return ret;
 +}
 +
 +
- 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
 +      .read_reg                       = MMA8452_REG_X_OUT_MSB,                //read data
 +      .read_len                       = 6,                                    //data length
 +      .id_reg                         = MMA8452_REG_WHO_AM_I,                 //read device id from this register
 +      .id_data                        = MMA8452_DEVID,                        //device id
 +      .precision                      = MMA8452_PRECISION,                    //12 bit
 +      .ctrl_reg                       = MMA8452_REG_CTRL_REG1,                //enable or disable     
 +      .int_status_reg                 = MMA8452_REG_INTSRC,                   //intterupt status register
 +      .range                          = {-MMA845X_RANGE,MMA845X_RANGE},       //range
 +      .trig                           = IRQF_TRIGGER_LOW|IRQF_ONESHOT,                
 +      .active                         = sensor_active,        
 +      .init                           = sensor_init,
 +      .report                         = sensor_report_value,
 +};
 +
 +/****************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;
 +      int type = ops->type;
 +      result = sensor_register_slave(type, NULL, NULL, gsensor_get_ops);      
 +      printk("%s\n",__func__);
 +      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;
 +      sensor_unregister_slave(type, NULL, NULL, gsensor_get_ops);
 +}
 +
 +
- module_init(gsensor_init);
- module_exit(gsensor_exit);
++module_init(gsensor_mma8452_init);
++module_exit(gsensor_mma8452_exit);
 +
 +
 +