input: keyboard: rk_keys: add rk_keys.h
[firefly-linux-kernel-4.4.55.git] / drivers / input / sensors / hall / och165t_hall.c
1 /* drivers/input/sensors/access/kxtik.c
2  *
3  * Copyright (C) 2012-2015 ROCKCHIP.
4  * Author: luowei <lw@rock-chips.com>
5  *
6  * This software is licensed under the terms of the GNU General Public
7  * License version 2, as published by the Free Software Foundation, and
8  * may be copied, distributed, and modified under those terms.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  */
16 #include <linux/interrupt.h>
17 #include <linux/i2c.h>
18 #include <linux/slab.h>
19 #include <linux/irq.h>
20 #include <linux/miscdevice.h>
21 #include <linux/gpio.h>
22 #include <asm/uaccess.h>
23 #include <asm/atomic.h>
24 #include <linux/delay.h>
25 #include <linux/input.h>
26 #include <linux/workqueue.h>
27 #include <linux/freezer.h>
28 #include <linux/of_gpio.h>
29 #ifdef CONFIG_HAS_EARLYSUSPEND
30 #include <linux/earlysuspend.h>
31 #endif
32 #include <linux/rk_keys.h>
33 #include <linux/sensor-dev.h>
34
35
36 #define CM3232_CLOSE    0x01
37
38
39 #define CM3232_ADDR_COM 0
40 #define CM3232_ADDR_DATA 50     
41
42 #define CM3232_DRV_NAME "cm3232"
43 //command code
44 #define COMMAND_CTRL            0
45 #define COMMAND_ALS_DATA        50              //ALS: 15:8 MSB 8bits data
46                                                 //7:0 LSB 8bits data
47
48 /****************operate according to sensor chip:start************/
49
50 static int sensor_active(struct i2c_client *client, int enable, int rate)
51 {
52         struct sensor_private_data *sensor =
53             (struct sensor_private_data *) i2c_get_clientdata(client);  
54         if(enable)
55         {
56                 sensor->status_cur = SENSOR_ON;
57         }
58         else
59         {
60                 sensor->status_cur = SENSOR_OFF;
61         }
62         return 0;
63 }
64
65 static int sensor_init(struct i2c_client *client)
66 {       
67         struct sensor_private_data *sensor =
68             (struct sensor_private_data *) i2c_get_clientdata(client);  
69         int result = 0;
70         
71         result = sensor->ops->active(client,0,0);
72         if(result)
73         {
74                 printk("%s:line=%d,error\n",__func__,__LINE__);
75                 return result;
76         }
77         
78         sensor->status_cur = SENSOR_OFF;
79         return result;
80 }
81
82
83 static int sensor_report_value(struct i2c_client *client)
84 {
85         struct sensor_private_data *sensor =
86             (struct sensor_private_data *) i2c_get_clientdata(client);  
87         struct sensor_platform_data *pdata = sensor->pdata;
88         int gpio_value = 0;
89         gpio_value = gpio_get_value(pdata->irq_pin);
90         if(gpio_value == 0)
91         {               
92                 //send power key to sleep
93                 rk_send_power_key(1);
94                 rk_send_power_key(0);
95         }
96         else
97         {
98                 //rk_send_power_key(1);
99                 //rk_send_power_key(0);
100                 rk_send_wakeup_key(); // wake up the system
101         }
102         return 0;
103 }
104
105
106 struct sensor_operate hall_och165t_ops = {
107         .name                           = "och165t",
108         .type                           = SENSOR_TYPE_HALL,     //sensor type and it should be correct
109         .id_i2c                         = HALL_ID_OCH165T,      //i2c id number
110         .read_reg                       = SENSOR_UNKNOW_DATA,   //read data
111         .read_len                       = 2,                    //data length
112         .id_reg                         = SENSOR_UNKNOW_DATA,   //read device id from this register
113         .id_data                        = SENSOR_UNKNOW_DATA,   //device id
114         .precision                      = 8,                    //8 bits
115         .ctrl_reg                       = SENSOR_UNKNOW_DATA,   //enable or disable 
116         .int_status_reg                 = SENSOR_UNKNOW_DATA,   //intterupt status register
117         .range                          = {100,65535},          //range
118         .brightness                     = {10,255},             // brightness
119         .trig                           = SENSOR_UNKNOW_DATA,           
120         .active                         = sensor_active,        
121         .init                           = sensor_init,
122         .report                         = sensor_report_value,
123 };
124
125 /****************operate according to sensor chip:end************/
126
127 //function name should not be changed
128 static struct sensor_operate *hall_get_ops(void)
129 {
130         return &hall_och165t_ops;
131 }
132
133
134 static int __init hall_och165t_init(void)
135 {
136         struct sensor_operate *ops = hall_get_ops();
137         int result = 0;
138         int type = ops->type;
139         result = sensor_register_slave(type, NULL, NULL, hall_get_ops);
140         return result;
141 }
142
143 static void __exit hall_och165t_exit(void)
144 {
145         struct sensor_operate *ops = hall_get_ops();
146         int type = ops->type;
147         sensor_unregister_slave(type, NULL, NULL, hall_get_ops);
148 }
149
150
151 module_init(hall_och165t_init);
152 module_exit(hall_och165t_exit);
153
154