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 <linux/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
sensor_active(struct i2c_client * client,int enable,int rate)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
sensor_init(struct i2c_client * client)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
sensor_report_value(struct i2c_client * client)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 static 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************/
hall_och165t_probe(struct i2c_client * client,const struct i2c_device_id * devid)126 static int hall_och165t_probe(struct i2c_client *client,
127 const struct i2c_device_id *devid)
128 {
129 return sensor_register_device(client, NULL, devid, &hall_och165t_ops);
130 }
131
hall_och165t_remove(struct i2c_client * client)132 static int hall_och165t_remove(struct i2c_client *client)
133 {
134 return sensor_unregister_device(client, NULL, &hall_och165t_ops);
135 }
136
137 static const struct i2c_device_id hall_och165t_id[] = {
138 {"hall_och165t", HALL_ID_OCH165T},
139 {}
140 };
141
142 static struct i2c_driver hall_och165t_driver = {
143 .probe = hall_och165t_probe,
144 .remove = hall_och165t_remove,
145 .shutdown = sensor_shutdown,
146 .id_table = hall_och165t_id,
147 .driver = {
148 .name = "hall_och165t",
149 #ifdef CONFIG_PM
150 .pm = &sensor_pm_ops,
151 #endif
152 },
153 };
154
155 module_i2c_driver(hall_och165t_driver);
156
157 MODULE_AUTHOR("luowei <lw@rock-chips.com>");
158 MODULE_DESCRIPTION("och165t hall driver");
159 MODULE_LICENSE("GPL");
160