1 /* drivers/input/sensors/access/kxtik.c
3 * Copyright (C) 2012-2015 ROCKCHIP.
4 * Author: luowei <lw@rock-chips.com>
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.
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.
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>
32 #include <linux/rk_keys.h>
33 #include <linux/sensor-dev.h>
36 #define CM3232_CLOSE 0x01
39 #define CM3232_ADDR_COM 0
40 #define CM3232_ADDR_DATA 50
42 #define CM3232_DRV_NAME "cm3232"
44 #define COMMAND_CTRL 0
45 #define COMMAND_ALS_DATA 50 //ALS: 15:8 MSB 8bits data
48 /****************operate according to sensor chip:start************/
50 static int sensor_active(struct i2c_client *client, int enable, int rate)
52 struct sensor_private_data *sensor =
53 (struct sensor_private_data *) i2c_get_clientdata(client);
56 sensor->status_cur = SENSOR_ON;
60 sensor->status_cur = SENSOR_OFF;
65 static int sensor_init(struct i2c_client *client)
67 struct sensor_private_data *sensor =
68 (struct sensor_private_data *) i2c_get_clientdata(client);
71 result = sensor->ops->active(client,0,0);
74 printk("%s:line=%d,error\n",__func__,__LINE__);
78 sensor->status_cur = SENSOR_OFF;
83 static int sensor_report_value(struct i2c_client *client)
85 struct sensor_private_data *sensor =
86 (struct sensor_private_data *) i2c_get_clientdata(client);
87 struct sensor_platform_data *pdata = sensor->pdata;
89 gpio_value = gpio_get_value(pdata->irq_pin);
92 //send power key to sleep
98 //rk_send_power_key(1);
99 //rk_send_power_key(0);
100 rk_send_wakeup_key(); // wake up the system
106 struct sensor_operate hall_och165t_ops = {
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,
122 .report = sensor_report_value,
125 /****************operate according to sensor chip:end************/
127 //function name should not be changed
128 static struct sensor_operate *hall_get_ops(void)
130 return &hall_och165t_ops;
134 static int __init hall_och165t_init(void)
136 struct sensor_operate *ops = hall_get_ops();
138 int type = ops->type;
139 result = sensor_register_slave(type, NULL, NULL, hall_get_ops);
143 static void __exit hall_och165t_exit(void)
145 struct sensor_operate *ops = hall_get_ops();
146 int type = ops->type;
147 sensor_unregister_slave(type, NULL, NULL, hall_get_ops);
151 module_init(hall_och165t_init);
152 module_exit(hall_och165t_exit);