add light sensor cm3232 support
authorluowei <lw@rock-chips.com>
Mon, 18 Feb 2013 08:23:38 +0000 (16:23 +0800)
committerluowei <lw@rock-chips.com>
Mon, 18 Feb 2013 08:24:05 +0000 (16:24 +0800)
drivers/input/sensors/lsensor/Kconfig
drivers/input/sensors/lsensor/Makefile
drivers/input/sensors/lsensor/cm3232.c [new file with mode: 0755]
drivers/input/sensors/sensor-dev.c
include/linux/sensor-dev.h

index 0e6cf2ff91812de79cf500966d72e6b7b7747c98..8db41c71ba5f4440e09191a4e4fe3058808f4d3c 100755 (executable)
@@ -11,6 +11,10 @@ config LS_CM3217
   bool "light sensor cm3217"
        default n
  
+config LS_CM3232
+  bool "light sensor cm3232"
+       default n
 config LS_AL3006
   bool "light sensor al3006"
        default n
index 48531def826dc59a1c1b1e1b1d49c9e7722b86d4..0930187969253b8097c072abcc24f24365a5a40e 100755 (executable)
@@ -1,6 +1,7 @@
 # gsensor drivers
 
 obj-$(CONFIG_LS_CM3217)                += cm3217.o
+obj-$(CONFIG_LS_CM3232)                += cm3232.o
 obj-$(CONFIG_LS_AL3006)                += ls_al3006.o
 obj-$(CONFIG_LS_STK3171)               += ls_stk3171.o
 obj-$(CONFIG_LS_ISL29023)              += isl29023.o
diff --git a/drivers/input/sensors/lsensor/cm3232.c b/drivers/input/sensors/lsensor/cm3232.c
new file mode 100755 (executable)
index 0000000..bb9cf99
--- /dev/null
@@ -0,0 +1,245 @@
+/* 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_LIGHT\r
+#define DBG(x...) if(sensor->pdata->type == SENSOR_DEBUG_TYPE) printk(x)\r
+#else\r
+#define DBG(x...)\r
+#endif\r
+\r
+#define CM3232_CLOSE   0x01\r
+\r
+\r
+#define CM3232_ADDR_COM 0\r
+#define CM3232_ADDR_DATA 50    \r
+\r
+#define CM3232_DRV_NAME "cm3232"\r
+//command code\r
+#define COMMAND_CTRL           0\r
+#define COMMAND_ALS_DATA       50              //ALS: 15:8 MSB 8bits data\r
+                                               //7:0 LSB 8bits data\r
+\r
+//ctrl bit\r
+#define ALS_RESET(x)                   (((x)&1)<<6) //0 = Reset disable; 1 = Reset enable\r
+#define ALS_IT(x)                      (((x)&7)<<2) //ALS integration time setting\r
+#define HIGH_SENSITIVITY(x)            (((x)&1)<<1) //0 = Normal mode; 1 = High sensitivity mode\r
+#define SHUT_DOWN(x)                   (((x)&1)<<0) //ALS shut down setting: 0 = ALS Power on ; 1 = ALS Shut down\r
+\r
+#define ALS_IT100MS    0               //100ms\r
+#define ALS_IT200MS    1               //200ms\r
+#define ALS_IT400MS    2               //400ms\r
+#define ALS_IT800MS    3               //800ms\r
+#define ALS_IT1600MS   4               //1600ms\r
+#define ALS_IT3200MS   5               //3200ms\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->client->addr = sensor->ops->ctrl_reg; \r
+       //sensor->ops->ctrl_data = sensor_read_reg(client, sensor->ops->ctrl_reg);\r
+       //printk("%s:  client addr = %#x\n\n", __func__, client->addr); \r
+       //register setting according to chip datasheet          \r
+       if (enable) {\r
+               sensor->ops->ctrl_data = ALS_RESET(1);  \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
+                       return -1;\r
+               }\r
+       }\r
+\r
+       if(enable)\r
+       {       \r
+               sensor->ops->ctrl_data = ALS_IT(ALS_IT200MS) | HIGH_SENSITIVITY(1);\r
+       }\r
+       else\r
+       {\r
+               sensor->ops->ctrl_data = SHUT_DOWN(1);\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
+\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
+\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
+       return result;\r
+}\r
+\r
+\r
+static void light_report_value(struct input_dev *input, int data)\r
+{\r
+       unsigned char index = 0;\r
+       if(data <= 10){\r
+               index = 0;goto report;\r
+       }\r
+       else if(data <= 160){\r
+               index = 1;goto report;\r
+       }\r
+       else if(data <= 225){\r
+               index = 2;goto report;\r
+       }\r
+       else if(data <= 320){\r
+               index = 3;goto report;\r
+       }\r
+       else if(data <= 640){\r
+               index = 4;goto report;\r
+       }\r
+       else if(data <= 1280){\r
+               index = 5;goto report;\r
+       }\r
+       else if(data <= 2600){\r
+               index = 6;goto report;\r
+       }\r
+       else{\r
+               index = 7;goto report;\r
+       }\r
+\r
+report:\r
+       DBG("cm3232 report data=%d,index = %d\n",data,index);\r
+       printk("cm3232 report data=%d,index = %d\n",data,index);\r
+       input_report_abs(input, ABS_MISC, index);\r
+       input_sync(input);\r
+}\r
+\r
+\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
+       int result = 0;\r
+       char msb = 0, lsb = 0;\r
+       char data[2] = {0};\r
+       unsigned short value = 0;\r
+       \r
+       //sensor->client->addr = CM3232_ADDR_DATA;\r
+       data[0] = CM3232_ADDR_DATA;\r
+       sensor_rx_data(sensor->client, data, 2);\r
+       value = (data[1] << 8) | data[0] ;\r
+\r
+       DBG("%s:result=%d\n",__func__,value);\r
+       //printk("%s:result=%d\n",__func__,value);\r
+       light_report_value(sensor->input_dev, value);\r
+\r
+       if((sensor->pdata->irq_enable)&& (sensor->ops->int_status_reg >= 0))    //read sensor intterupt status register\r
+       {\r
+               \r
+               result= sensor_read_reg(client, sensor->ops->int_status_reg);\r
+               if(result)\r
+               {\r
+                       printk("%s:fail to clear sensor int status,ret=0x%x\n",__func__,result);\r
+               }\r
+       }\r
+       \r
+       return result;\r
+}\r
+\r
+\r
+struct sensor_operate light_cm3232_ops = {\r
+       .name                           = "cm3232",\r
+       .type                           = SENSOR_TYPE_LIGHT,    //sensor type and it should be correct\r
+       .id_i2c                         = LIGHT_ID_CM3232,      //i2c id number\r
+       .read_reg                       = CM3232_ADDR_DATA,     //read data\r
+       .read_len                       = 2,                    //data length\r
+       .id_reg                         = SENSOR_UNKNOW_DATA,   //read device id from this register\r
+       .id_data                        = SENSOR_UNKNOW_DATA,   //device id\r
+       .precision                      = 8,                    //8 bits\r
+       .ctrl_reg                       = CM3232_ADDR_COM,      //enable or disable \r
+       .int_status_reg                 = SENSOR_UNKNOW_DATA,   //intterupt status register\r
+       .range                          = {100,65535},          //range\r
+       .brightness                     = {10,255},             // brightness\r
+       .trig                           = SENSOR_UNKNOW_DATA,           \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 *light_get_ops(void)\r
+{\r
+       return &light_cm3232_ops;\r
+}\r
+\r
+\r
+static int __init light_cm3232_init(void)\r
+{\r
+       struct sensor_operate *ops = light_get_ops();\r
+       int result = 0;\r
+       int type = ops->type;\r
+       result = sensor_register_slave(type, NULL, NULL, light_get_ops);\r
+       //printk("%s: >>>>>>>>>>>>>>>>>>>\n\n\n",__func__);\r
+       return result;\r
+}\r
+\r
+static void __exit light_cm3232_exit(void)\r
+{\r
+       struct sensor_operate *ops = light_get_ops();\r
+       int type = ops->type;\r
+       sensor_unregister_slave(type, NULL, NULL, light_get_ops);\r
+}\r
+\r
+\r
+module_init(light_cm3232_init);\r
+module_exit(light_cm3232_exit);\r
+\r
+\r
index db8438acb6372b5ec1887352800211cb64ae58ee..10e43614724dab3bc60eda3727e24d0795ee1769 100755 (executable)
@@ -1415,11 +1415,12 @@ static const struct i2c_device_id sensor_id[] = {
        /*light sensor*/\r
        {"lightsensor", LIGHT_ID_ALL},  \r
        {"light_cm3217", LIGHT_ID_CM3217},\r
+       {"light_cm3232", LIGHT_ID_CM3232},\r
        {"light_al3006", LIGHT_ID_AL3006},\r
        {"ls_stk3171", LIGHT_ID_STK3171},\r
        {"ls_isl29023", LIGHT_ID_ISL29023},\r
        {"ls_ap321xx", LIGHT_ID_AP321XX},\r
-        {"ls_photoresistor", LIGHT_ID_PHOTORESISTOR},\r
+       {"ls_photoresistor", LIGHT_ID_PHOTORESISTOR},\r
        /*proximity sensor*/\r
        {"psensor", PROXIMITY_ID_ALL},\r
        {"proximity_al3006", PROXIMITY_ID_AL3006},      \r
index 5711d3efb2eeda0cc0d4a051663c22f70c228868..24c568e2d3c84d9f3811d9ae45eb1ee167096eab 100755 (executable)
@@ -76,11 +76,12 @@ enum sensor_id {
 \r
        LIGHT_ID_ALL,\r
        LIGHT_ID_CM3217,\r
+       LIGHT_ID_CM3232,\r
        LIGHT_ID_AL3006,\r
        LIGHT_ID_STK3171,\r
        LIGHT_ID_ISL29023,\r
        LIGHT_ID_AP321XX,\r
-        LIGHT_ID_PHOTORESISTOR,        \r
+       LIGHT_ID_PHOTORESISTOR, \r
 \r
        PROXIMITY_ID_ALL,\r
        PROXIMITY_ID_AL3006,\r