input: sensors: fromdos and remove trailing whitespace
[firefly-linux-kernel-4.4.55.git] / drivers / input / sensors / lsensor / ls_al3006.c
index 6fbf1a3e01f04c58d952d5b529b135725b106264..05b4c233d6b0fb8fc7fe6e66ae9bdb609281e169 100755 (executable)
-/* 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 <linux/of_gpio.h>\r
-#ifdef CONFIG_HAS_EARLYSUSPEND\r
-#include <linux/earlysuspend.h>\r
-#endif\r
-#include <linux/sensor-dev.h>\r
-\r
-\r
-#define CONFIG_REG        (0x00)\r
-#define TIM_CTL_REG       (0x01)\r
-#define ALS_CTL_REG       (0x02)\r
-#define INT_STATUS_REG    (0x03)\r
-#define PS_CTL_REG        (0x04)\r
-#define PS_ALS_DATA_REG   (0x05)\r
-#define ALS_WINDOWS_REG   (0x08)\r
-\r
-//enable bit[ 0-1], in register CONFIG_REG\r
-#define ONLY_ALS_EN       (0x00)\r
-#define ONLY_PROX_EN      (0x01)\r
-#define ALL_PROX_ALS_EN   (0x02)\r
-#define ALL_IDLE          (0x03)\r
-\r
-#define POWER_MODE_MASK   (0x0C)\r
-#define POWER_UP_MODE     (0x00)\r
-#define POWER_DOWN_MODE   (0x08)\r
-#define POWER_RESET_MODE  (0x0C)\r
-\r
-static int sensor_power_updown(struct i2c_client *client, int on)\r
-{\r
-       int result = 0;\r
-       char value = 0;\r
-       int i = 0;\r
-       for(i=0; i<3; i++)\r
-       {\r
-               if(!on)\r
-               {\r
-                       value = sensor_read_reg(client, CONFIG_REG);\r
-                       value &= ~POWER_MODE_MASK;\r
-                       value |= POWER_DOWN_MODE;\r
-                       result = sensor_write_reg(client, CONFIG_REG, value);\r
-                       if(result)\r
-                               return result;\r
-               }\r
-               else\r
-               {\r
-                       value = sensor_read_reg(client, CONFIG_REG);\r
-                       value &= ~POWER_MODE_MASK;\r
-                       value |= POWER_UP_MODE;\r
-                       result = sensor_write_reg(client, CONFIG_REG, value);\r
-                       if(result)\r
-                               return result;\r
-               }\r
-               \r
-               if(!result)\r
-               break;\r
-       }\r
-\r
-       if(i>1)\r
-       printk("%s:set %d times",__func__,i);\r
-       \r
-       return result;\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
-       char value = 0;\r
-\r
-       if(enable)      \r
-       sensor_power_updown(client, 1);\r
-\r
-       value = sensor_read_reg(client, sensor->ops->ctrl_reg);\r
-       \r
-       //register setting according to chip datasheet          \r
-       if(enable)\r
-       {       \r
-               if( (value & 0x03) == ONLY_PROX_EN )\r
-               {\r
-                       value &= ~0x03;\r
-                       value |= ALL_PROX_ALS_EN;\r
-               }\r
-               else if((value & 0x03) == ALL_IDLE )\r
-               {\r
-                       value &= ~0x03;\r
-                       value |= ONLY_ALS_EN;\r
-               }\r
-\r
-       }\r
-       else\r
-       {\r
-               if( (value & 0x03) == ONLY_ALS_EN )\r
-               {\r
-                       value &= ~0x03;\r
-                       value |= ALL_IDLE;\r
-               }\r
-               else if((value & 0x03) == ALL_PROX_ALS_EN )\r
-               {\r
-                       value &= ~0x03;\r
-                       value |= ONLY_PROX_EN;\r
-               }\r
-       \r
-       }\r
-       \r
-       sensor->ops->ctrl_data = value;\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
-\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
-       char value = 0;\r
-       \r
-       sensor_power_updown(client, 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
-       value = 0x41;//The ADC effective resolution = 9;  Low lux threshold level = 1;\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 <linux/of_gpio.h>
+#ifdef CONFIG_HAS_EARLYSUSPEND
+#include <linux/earlysuspend.h>
+#endif
+#include <linux/sensor-dev.h>
+
+
+#define CONFIG_REG        (0x00)
+#define TIM_CTL_REG       (0x01)
+#define ALS_CTL_REG       (0x02)
+#define INT_STATUS_REG    (0x03)
+#define PS_CTL_REG        (0x04)
+#define PS_ALS_DATA_REG   (0x05)
+#define ALS_WINDOWS_REG   (0x08)
+
+//enable bit[ 0-1], in register CONFIG_REG
+#define ONLY_ALS_EN       (0x00)
+#define ONLY_PROX_EN      (0x01)
+#define ALL_PROX_ALS_EN   (0x02)
+#define ALL_IDLE          (0x03)
+
+#define POWER_MODE_MASK   (0x0C)
+#define POWER_UP_MODE     (0x00)
+#define POWER_DOWN_MODE   (0x08)
+#define POWER_RESET_MODE  (0x0C)
+
+static int sensor_power_updown(struct i2c_client *client, int on)
+{
+       int result = 0;
+       char value = 0;
+       int i = 0;
+       for(i=0; i<3; i++)
+       {
+               if(!on)
+               {
+                       value = sensor_read_reg(client, CONFIG_REG);
+                       value &= ~POWER_MODE_MASK;
+                       value |= POWER_DOWN_MODE;
+                       result = sensor_write_reg(client, CONFIG_REG, value);
+                       if(result)
+                               return result;
+               }
+               else
+               {
+                       value = sensor_read_reg(client, CONFIG_REG);
+                       value &= ~POWER_MODE_MASK;
+                       value |= POWER_UP_MODE;
+                       result = sensor_write_reg(client, CONFIG_REG, value);
+                       if(result)
+                               return result;
+               }
+
+               if(!result)
+               break;
+       }
+
+       if(i>1)
+       printk("%s:set %d times",__func__,i);
+
+       return result;
+}
+
+/****************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;
+       char value = 0;
+
+       if(enable)
+       sensor_power_updown(client, 1);
+
+       value = sensor_read_reg(client, sensor->ops->ctrl_reg);
+
+       //register setting according to chip datasheet
+       if(enable)
+       {
+               if( (value & 0x03) == ONLY_PROX_EN )
+               {
+                       value &= ~0x03;
+                       value |= ALL_PROX_ALS_EN;
+               }
+               else if((value & 0x03) == ALL_IDLE )
+               {
+                       value &= ~0x03;
+                       value |= ONLY_ALS_EN;
+               }
+
+       }
+       else
+       {
+               if( (value & 0x03) == ONLY_ALS_EN )
+               {
+                       value &= ~0x03;
+                       value |= ALL_IDLE;
+               }
+               else if((value & 0x03) == ALL_PROX_ALS_EN )
+               {
+                       value &= ~0x03;
+                       value |= ONLY_PROX_EN;
+               }
+
+       }
+
+       sensor->ops->ctrl_data = value;
+
+       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;
+       char value = 0;
+
+       sensor_power_updown(client, 0);
+
+       result = sensor->ops->active(client,0,0);
+       if(result)
+       {
+               printk("%s:line=%d,error\n",__func__,__LINE__);
+               return result;
+       }
+
+       sensor->status_cur = SENSOR_OFF;
+
+       value = 0x41;//The ADC effective resolution = 9;  Low lux threshold level = 1;
        //value = 0x69; //The ADC effective resolution = 17;  Low lux threshold level = 9;
-       result = sensor_write_reg(client, ALS_CTL_REG, value);\r
-       if(result)\r
-       {\r
-               printk("%s:line=%d,error\n",__func__,__LINE__);\r
-               return result;\r
-       }\r
+       result = sensor_write_reg(client, ALS_CTL_REG, value);
+       if(result)
+       {
+               printk("%s:line=%d,error\n",__func__,__LINE__);
+               return result;
+       }
 
        //value = 0x04;//0x01-0x0f; 17%->93.5% if value = 0x04,then Compensate Loss 52%
-       value = 0x02;//0x01-0x0f; 17%->93.5% if value = 0x02,then Compensate Loss 31%   \r
-       result = sensor_write_reg(client, ALS_WINDOWS_REG, value);\r
-       if(result)\r
-       {\r
-               printk("%s:line=%d,error\n",__func__,__LINE__);\r
-               return result;\r
-       }\r
-               \r
-       return result;\r
-}\r
-\r
-\r
-static int light_report_value(struct input_dev *input, int data)\r
-{\r
-       unsigned char index = 0;\r
-       if(data <= 0){\r
-               index = 0;goto report;\r
-       }\r
-       else if(data <= 2){\r
-               index = 1;goto report;\r
-       }\r
-       else if(data <= 4){\r
-               index = 2;goto report;\r
-       }\r
-       else if(data <= 8){\r
-               index = 3;goto report;\r
-       }\r
-       else if(data <= 14){\r
-               index = 4;goto report;\r
-       }\r
-       else if(data <= 20){\r
-               index = 5;goto report;\r
-       }\r
-       else if(data <= 26){\r
-               index = 6;goto report;\r
-       }\r
-       else{\r
-               index = 7;goto report;\r
-       }\r
-\r
-report:\r
-       input_report_abs(input, ABS_MISC, index);\r
-       input_sync(input);\r
-\r
-       return index;\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 value = 0;\r
-       char index = 0;\r
-       \r
-       if(sensor->pdata->irq_enable)\r
-       {\r
-               if(sensor->ops->int_status_reg)\r
-               {\r
-                       value = sensor_read_reg(client, sensor->ops->int_status_reg);\r
-               }\r
-               \r
-       }\r
-\r
-       value = sensor_read_reg(client, sensor->ops->read_reg);\r
-       index = light_report_value(sensor->input_dev, value&0x3f); // bit0-5  is ls data;\r
-       \r
-       DBG("%s:%s result=0x%x,index=%d\n",__func__,sensor->ops->name, value,index);\r
-       \r
-       return result;\r
-}\r
-\r
-struct sensor_operate light_al3006_ops = {\r
-       .name                           = "ls_al3006",\r
-       .type                           = SENSOR_TYPE_LIGHT,    //sensor type and it should be correct\r
-       .id_i2c                         = LIGHT_ID_AL3006,      //i2c id number\r
-       .read_reg                       = PS_ALS_DATA_REG,      //read data\r
-       .read_len                       = 1,                    //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                       = CONFIG_REG,           //enable or disable \r
-       .int_status_reg                 = INT_STATUS_REG,       //intterupt status register\r
-       .range                          = {100,65535},          //range\r
-       .brightness                                        ={10,255},                          // brightness\r
-       .trig                           = IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED,                \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_al3006_ops;\r
-}\r
-\r
-\r
-static int __init light_al3006_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
-       return result;\r
-}\r
-\r
-static void __exit light_al3006_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_al3006_init);\r
-module_exit(light_al3006_exit);\r
-\r
-\r
+       value = 0x02;//0x01-0x0f; 17%->93.5% if value = 0x02,then Compensate Loss 31%
+       result = sensor_write_reg(client, ALS_WINDOWS_REG, value);
+       if(result)
+       {
+               printk("%s:line=%d,error\n",__func__,__LINE__);
+               return result;
+       }
+
+       return result;
+}
+
+
+static int light_report_value(struct input_dev *input, int data)
+{
+       unsigned char index = 0;
+       if(data <= 0){
+               index = 0;goto report;
+       }
+       else if(data <= 2){
+               index = 1;goto report;
+       }
+       else if(data <= 4){
+               index = 2;goto report;
+       }
+       else if(data <= 8){
+               index = 3;goto report;
+       }
+       else if(data <= 14){
+               index = 4;goto report;
+       }
+       else if(data <= 20){
+               index = 5;goto report;
+       }
+       else if(data <= 26){
+               index = 6;goto report;
+       }
+       else{
+               index = 7;goto report;
+       }
+
+report:
+       input_report_abs(input, ABS_MISC, index);
+       input_sync(input);
+
+       return index;
+}
+
+
+static int sensor_report_value(struct i2c_client *client)
+{
+       struct sensor_private_data *sensor =
+           (struct sensor_private_data *) i2c_get_clientdata(client);
+       int result = 0;
+       char value = 0;
+       char index = 0;
+
+       if(sensor->pdata->irq_enable)
+       {
+               if(sensor->ops->int_status_reg)
+               {
+                       value = sensor_read_reg(client, sensor->ops->int_status_reg);
+               }
+
+       }
+
+       value = sensor_read_reg(client, sensor->ops->read_reg);
+       index = light_report_value(sensor->input_dev, value&0x3f); // bit0-5  is ls data;
+
+       DBG("%s:%s result=0x%x,index=%d\n",__func__,sensor->ops->name, value,index);
+
+       return result;
+}
+
+struct sensor_operate light_al3006_ops = {
+       .name                           = "ls_al3006",
+       .type                           = SENSOR_TYPE_LIGHT,    //sensor type and it should be correct
+       .id_i2c                         = LIGHT_ID_AL3006,      //i2c id number
+       .read_reg                       = PS_ALS_DATA_REG,      //read data
+       .read_len                       = 1,                    //data length
+       .id_reg                         = SENSOR_UNKNOW_DATA,   //read device id from this register
+       .id_data                        = SENSOR_UNKNOW_DATA,   //device id
+       .precision                      = 8,                    //8 bits
+       .ctrl_reg                       = CONFIG_REG,           //enable or disable
+       .int_status_reg                 = INT_STATUS_REG,       //intterupt status register
+       .range                          = {100,65535},          //range
+       .brightness                                        ={10,255},                          // brightness
+       .trig                           = IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED,
+       .active                         = sensor_active,
+       .init                           = sensor_init,
+       .report                         = sensor_report_value,
+};
+
+/****************operate according to sensor chip:end************/
+
+//function name should not be changed
+static struct sensor_operate *light_get_ops(void)
+{
+       return &light_al3006_ops;
+}
+
+
+static int __init light_al3006_init(void)
+{
+       struct sensor_operate *ops = light_get_ops();
+       int result = 0;
+       int type = ops->type;
+       result = sensor_register_slave(type, NULL, NULL, light_get_ops);
+       return result;
+}
+
+static void __exit light_al3006_exit(void)
+{
+       struct sensor_operate *ops = light_get_ops();
+       int type = ops->type;
+       sensor_unregister_slave(type, NULL, NULL, light_get_ops);
+}
+
+
+module_init(light_al3006_init);
+module_exit(light_al3006_exit);
+
+