From: 郭毅 Date: Wed, 19 Mar 2014 08:28:32 +0000 (+0800) Subject: sensor: hallsensor : add och165T X-Git-Tag: firefly_0821_release~6001^2~4 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d95f71c1f0f969d3ef720a4629f107435b664981;p=firefly-linux-kernel-4.4.55.git sensor: hallsensor : add och165T --- diff --git a/drivers/input/sensors/Kconfig b/drivers/input/sensors/Kconfig index 15f514567e01..5214ef525413 100755 --- a/drivers/input/sensors/Kconfig +++ b/drivers/input/sensors/Kconfig @@ -16,6 +16,6 @@ source "drivers/input/sensors/lsensor/Kconfig" source "drivers/input/sensors/psensor/Kconfig" source "drivers/input/sensors/temperature/Kconfig" source "drivers/input/sensors/pressure/Kconfig" - +source "drivers/input/sensors/hall/Kconfig" endif diff --git a/drivers/input/sensors/Makefile b/drivers/input/sensors/Makefile index 809b50b40d39..100e65c50af6 100755 --- a/drivers/input/sensors/Makefile +++ b/drivers/input/sensors/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_LIGHT_DEVICE) += lsensor/ obj-$(CONFIG_PROXIMITY_DEVICE) += psensor/ obj-$(CONFIG_TEMPERATURE_DEVICE) += temperature/ obj-$(CONFIG_PRESSURE_DEVICE) += pressure/ +obj-$(CONFIG_HALL_DEVICE) += hall/ obj-$(CONFIG_SENSOR_DEVICE) += sensor-i2c.o diff --git a/drivers/input/sensors/hall/Kconfig b/drivers/input/sensors/hall/Kconfig new file mode 100644 index 000000000000..6619e6ffcde8 --- /dev/null +++ b/drivers/input/sensors/hall/Kconfig @@ -0,0 +1,15 @@ +# +# hall sensor drivers configuration +# + +menuconfig HALL_DEVICE + bool "hall sensor device support" + default n + +if HALL_DEVICE +config HS_OCH165T + bool "hall sensor och165t" + default n + +endif + diff --git a/drivers/input/sensors/hall/Makefile b/drivers/input/sensors/hall/Makefile new file mode 100644 index 000000000000..8c6a4355161d --- /dev/null +++ b/drivers/input/sensors/hall/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_HS_OCH165T) += och165t_hall.o \ No newline at end of file diff --git a/drivers/input/sensors/hall/och165t_hall.c b/drivers/input/sensors/hall/och165t_hall.c new file mode 100644 index 000000000000..7ca25a7f2ba4 --- /dev/null +++ b/drivers/input/sensors/hall/och165t_hall.c @@ -0,0 +1,155 @@ +/* drivers/input/sensors/access/kxtik.c + * + * Copyright (C) 2012-2015 ROCKCHIP. + * Author: luowei + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef CONFIG_HAS_EARLYSUSPEND +#include +#endif +#include + + +#define CM3232_CLOSE 0x01 + + +#define CM3232_ADDR_COM 0 +#define CM3232_ADDR_DATA 50 + +#define CM3232_DRV_NAME "cm3232" +//command code +#define COMMAND_CTRL 0 +#define COMMAND_ALS_DATA 50 //ALS: 15:8 MSB 8bits data + //7:0 LSB 8bits data + +extern void rk_send_power_key(int state); +extern void rk_send_wakeup_key(void); +/****************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); + if(enable) + { + sensor->status_cur = SENSOR_ON; + } + else + { + sensor->status_cur = SENSOR_OFF; + } + return 0; +} + +static int sensor_init(struct i2c_client *client) +{ + struct sensor_private_data *sensor = + (struct sensor_private_data *) i2c_get_clientdata(client); + int result = 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; + return result; +} + + +static int sensor_report_value(struct i2c_client *client) +{ + struct sensor_private_data *sensor = + (struct sensor_private_data *) i2c_get_clientdata(client); + struct sensor_platform_data *pdata = sensor->pdata; + int gpio_value = 0; + gpio_value = gpio_get_value(pdata->irq_pin); + if(gpio_value == 0) + { + //send power key to sleep + rk_send_power_key(1); + rk_send_power_key(0); + } + else + { + //rk_send_power_key(1); + //rk_send_power_key(0); + rk_send_wakeup_key(); // wake up the system + } + return 0; +} + + +struct sensor_operate hall_och165t_ops = { + .name = "och165t", + .type = SENSOR_TYPE_HALL, //sensor type and it should be correct + .id_i2c = HALL_ID_OCH165T, //i2c id number + .read_reg = SENSOR_UNKNOW_DATA, //read data + .read_len = 2, //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 = SENSOR_UNKNOW_DATA, //enable or disable + .int_status_reg = SENSOR_UNKNOW_DATA, //intterupt status register + .range = {100,65535}, //range + .brightness = {10,255}, // brightness + .trig = SENSOR_UNKNOW_DATA, + .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 *hall_get_ops(void) +{ + return &hall_och165t_ops; +} + + +static int __init hall_och165t_init(void) +{ + struct sensor_operate *ops = hall_get_ops(); + int result = 0; + int type = ops->type; + result = sensor_register_slave(type, NULL, NULL, hall_get_ops); + return result; +} + +static void __exit hall_och165t_exit(void) +{ + struct sensor_operate *ops = hall_get_ops(); + int type = ops->type; + sensor_unregister_slave(type, NULL, NULL, hall_get_ops); +} + + +module_init(hall_och165t_init); +module_exit(hall_och165t_exit); + +