From ac6508b2cfa75de684c6f82e45cfa906dae09397 Mon Sep 17 00:00:00 2001 From: Tao Huang Date: Thu, 1 Nov 2018 14:35:56 +0800 Subject: [PATCH] drivers/input: remove unused lightsensor drivers Change-Id: I0d42b822e0cf89a416b04eb18c1c3dc814fb5ac3 Signed-off-by: Tao Huang --- drivers/input/lightsensor/Kconfig | 38 -- drivers/input/lightsensor/Makefile | 7 - drivers/input/lightsensor/cm3202.c | 297 -------------- drivers/input/lightsensor/cm3217.c | 379 ------------------ drivers/input/lightsensor/rk29_lightsensor.c | 379 ------------------ drivers/input/lightsensor/us5151.c | 393 ------------------- 6 files changed, 1493 deletions(-) delete mode 100644 drivers/input/lightsensor/Kconfig delete mode 100644 drivers/input/lightsensor/Makefile delete mode 100644 drivers/input/lightsensor/cm3202.c delete mode 100644 drivers/input/lightsensor/cm3217.c delete mode 100644 drivers/input/lightsensor/rk29_lightsensor.c delete mode 100644 drivers/input/lightsensor/us5151.c diff --git a/drivers/input/lightsensor/Kconfig b/drivers/input/lightsensor/Kconfig deleted file mode 100644 index 92abd23bc134..000000000000 --- a/drivers/input/lightsensor/Kconfig +++ /dev/null @@ -1,38 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# gsensor drivers configuration -# - -menuconfig LIGHT_SENSOR_DEVICE - bool "light_sensor device support" - default n - help - Enable this to be able to choose the drivers for controlling the - light_sensor on some platforms, for example on PDAs. - -if LIGHT_SENSOR_DEVICE - -config CM3202 - bool "cm3202" - depends on LIGHT_SENSOR_DEVICE - default n - help - To have support for your specific gsesnor you will have to - select the proper drivers which depend on this option. - -config LS_CM3217 - bool "cm3217" - depends on LIGHT_SENSOR_DEVICE - default n - help - To have support for your specific gsesnor you will have to - select the proper drivers which depend on this option. -config LS_US5151 - bool "us5151" - depends on LIGHT_SENSOR_DEVICE - default n - help - To have support for your specific gsesnor you will have to - select the proper drivers which depend on this option. - -endif diff --git a/drivers/input/lightsensor/Makefile b/drivers/input/lightsensor/Makefile deleted file mode 100644 index 62f67f0f22cf..000000000000 --- a/drivers/input/lightsensor/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# gsensor drivers - -obj-$(CONFIG_CM3202) += cm3202.o -obj-$(CONFIG_LS_CM3217) += cm3217.o -obj-$(CONFIG_LS_US5151) += us5151.o - diff --git a/drivers/input/lightsensor/cm3202.c b/drivers/input/lightsensor/cm3202.c deleted file mode 100644 index 13375fc78dd1..000000000000 --- a/drivers/input/lightsensor/cm3202.c +++ /dev/null @@ -1,297 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -#include -#include -#ifdef CONFIG_HAS_EARLYSUSPEND -#include -#endif - -#define DEBUG 0 - -#if DEBUG -#define DBG(X...) printk(KERN_NOTICE X) -#else -#define DBG(X...) -#endif - -//#define CM3202_SD_IOPIN LIGHT_INT_IOPIN//light sensor int Pin -//#define DATA_ADC_CHN 2 //SARADC_AIN[3] -#define SENSOR_ON 1 -#define SENSOR_OFF 0 -#define LIGHTSENSOR_IOCTL_MAGIC 'l' -#define LIGHTSENSOR_IOCTL_GET_ENABLED _IOR(LIGHTSENSOR_IOCTL_MAGIC, 1, int *) -#define LIGHTSENSOR_IOCTL_ENABLE _IOW(LIGHTSENSOR_IOCTL_MAGIC, 2, int *) -#define LIGHTSENSOR_IOCTL_DISABLE _IOW(LIGHTSENSOR_IOCTL_MAGIC, 3, int *) - -struct cm3202_data { - struct adc_client *client; - struct timer_list timer; - struct work_struct timer_work; - struct input_dev *input; - int CM3202_SD; - int statue; -}; -#ifdef CONFIG_HAS_EARLYSUSPEND -static struct early_suspend cm3202_early_suspend; -#endif -static struct cm3202_data *light; - -static int cm3202_start(struct cm3202_data *data) -{ - struct cm3202_data *cm3202 = data; - if(cm3202->statue) - return 0; - gpio_direction_output(cm3202->CM3202_SD,0);//level = 0 Sensor ON - cm3202->statue = SENSOR_ON; - cm3202->timer.expires = jiffies + 1*HZ; - add_timer(&cm3202->timer); - printk("========== cm3202 light sensor start ==========\n"); - return 0; -} - -static int cm3202_stop(struct cm3202_data *data) -{ - struct cm3202_data *cm3202 = data; - if(cm3202->statue == 0) - return 0; - gpio_direction_output(cm3202->CM3202_SD,1);//level = 1 Sensor OFF - cm3202->statue = SENSOR_OFF; - del_timer(&cm3202->timer); - printk("========== cm3202 light sensor stop ==========\n"); - return 0; -} - -#ifdef CONFIG_HAS_EARLYSUSPEND -static void cm3202_suspend(struct early_suspend *h) -{ - struct cm3202_data *cm3202 = light; - cm3202_stop(cm3202); - printk("Light Sensor cm3202 enter suspend cm3202->status %d\n",cm3202->statue); -} - -static void cm3202_resume(struct early_suspend *h) -{ - struct cm3202_data *cm3202 = light; - cm3202_start(cm3202); - printk("Light Sensor cm3202 enter resume cm3202->status %d\n",cm3202->statue); -} -#endif -static int cm3202_open(struct inode *indoe, struct file *file) -{ - return 0; -} - -static int cm3202_release(struct inode *inode, struct file *file) -{ - return 0; -} - -static int cm3202_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) -{ - unsigned long *argp = (unsigned char *)arg; - switch(cmd){ - case LIGHTSENSOR_IOCTL_GET_ENABLED: - *argp = light->statue; - break; - case LIGHTSENSOR_IOCTL_ENABLE: - if(*argp) - cm3202_start(light); - else - cm3202_stop(light); - break; - default:break; - } - return 0; -} - -static void cm3202_value_report(struct input_dev *input, int data) -{ - unsigned char index = 0; - if(data <= 10){ - index = 0;goto report; - } - else if(data <= 160){ - index = 1;goto report; - } - else if(data <= 225){ - index = 2;goto report; - } - else if(data <= 320){ - index = 3;goto report; - } - else if(data <= 640){ - index = 4;goto report; - } - else if(data <= 1280){ - index = 5;goto report; - } - else if(data <= 2600){ - index = 6;goto report; - } - else{ - index = 7;goto report; - } -report: - DBG("cm3202 report index = %d\n",index); - input_report_abs(input, ABS_MISC, index); - input_sync(input); - return; -} -static void callback(struct adc_client *client, void *param, int result) -{ - DBG("[chn%d] cm3202 report value: %d\n", client->chn, result); - return; -} -static void adc_timer(unsigned long data) -{ - struct cm3202_data *cm3202=(struct cm3202_data *)data; - schedule_work(&cm3202->timer_work); -} -static void adc_timer_work(struct work_struct *work) -{ - int sync_read = 0; - struct cm3202_data *cm3202 = container_of(work, struct cm3202_data,timer_work); - adc_async_read(cm3202->client); - sync_read = adc_sync_read(cm3202->client); - cm3202_value_report(cm3202->input, sync_read); - if(cm3202->statue){ - cm3202->timer.expires = jiffies + 3*HZ; - add_timer(&cm3202->timer); - } -} - -static struct file_operations cm3202_fops = { - .owner = THIS_MODULE, - .ioctl = cm3202_ioctl, - .open = cm3202_open, - .release = cm3202_release, -}; - -static struct miscdevice cm3202_device = { - .minor = MISC_DYNAMIC_MINOR, - .name = "lightsensor", - .fops = &cm3202_fops, -}; - -static int cm3202_probe(struct platform_device *pdev) -{ - struct cm3202_data *cm3202; - struct cm3202_platform_data *pdata = pdata = pdev->dev.platform_data; - int err; - DBG("============= cm3202 probe enter ==============\n"); - cm3202 = kmalloc(sizeof(struct cm3202_data), GFP_KERNEL); - if(!cm3202){ - printk("cm3202 alloc memory err !!!\n"); - err = -ENOMEM; - goto alloc_memory_fail; - } - if(pdata->init_platform_hw) - pdata->init_platform_hw(); - - cm3202->CM3202_SD = pdata->CM3202_SD_IOPIN; - DBG("===============================cm3202==========================\ncm3202_ADC_CHN = %d",pdata->DATA_ADC_CHN); - light = cm3202; - cm3202->client = adc_register(pdata->DATA_ADC_CHN, callback, NULL); - cm3202->statue = SENSOR_OFF; - cm3202->input = input_allocate_device(); - if (!cm3202->input) { - err = -ENOMEM; - printk(KERN_ERR"cm3202: Failed to allocate input device\n"); - goto exit_input_allocate_device_failed; - } - set_bit(EV_ABS, cm3202->input->evbit); - /* light sensor data */ - input_set_abs_params(cm3202->input, ABS_MISC, 0, 0x3ff, 0, 0); - cm3202->input->name = "lightsensor"; - - err = input_register_device(cm3202->input); - if (err < 0) { - printk(KERN_ERR"cm3202: Unable to register input device: %s\n",cm3202->input->name); - goto exit_input_register_device_failed; - } - /* - ret = gpio_request(CM3202_SD_IOPIN, "cm3202_sd"); - if (ret) { - printk( "failed to request cm3202 SD GPIO%d\n",CM3202_SD_IOPIN); - goto exit_gpio_request_fail; - } - DBG("cm3202 request INT inpin ok !!!"); - gpio_pull_updown(CM3202_SD_IOPIN,GPIOPullDown); */ - INIT_WORK(&cm3202->timer_work, adc_timer_work); - setup_timer(&cm3202->timer, adc_timer, (unsigned long)cm3202); - err = misc_register(&cm3202_device); - if (err < 0) { - printk(KERN_ERR"cm3202_probe: lightsensor_device register failed\n"); - goto exit_misc_register_fail; - } - printk("lightsensor cm3202 driver created !\n"); - //cm3202_start(light); -#ifdef CONFIG_HAS_EARLYSUSPEND - cm3202_early_suspend.suspend = cm3202_suspend; - cm3202_early_suspend.resume = cm3202_resume; - cm3202_early_suspend.level = 0x2; - register_early_suspend(&cm3202_early_suspend); -#endif - return 0; -exit_misc_register_fail: - gpio_free(pdata->CM3202_SD_IOPIN); - input_unregister_device(cm3202->input); -exit_input_register_device_failed: - input_free_device(cm3202->input); -exit_input_allocate_device_failed: - kfree(cm3202); -alloc_memory_fail: - printk("%s error\n",__FUNCTION__); - return err; -} - -static int cm3202_remove(struct platform_device *pdev) -{ - struct cm3202_data *cm3202 = light; - kfree(cm3202); - input_free_device(cm3202->input); - input_unregister_device(cm3202->input); - misc_deregister(&cm3202_device); - return 0; -} - -static struct platform_driver cm3202_driver = { - .probe = cm3202_probe, - .remove = cm3202_remove, - .driver = { - .owner = THIS_MODULE, - .name = "lightsensor", - } -}; - -static int __init cm3202_init(void) -{ - return platform_driver_register(&cm3202_driver); -} - -static void __exit cm3202_exit(void) -{ - platform_driver_unregister(&cm3202_driver); -} - -module_init(cm3202_init); -module_exit(cm3202_exit); diff --git a/drivers/input/lightsensor/cm3217.c b/drivers/input/lightsensor/cm3217.c deleted file mode 100644 index 61d9bb30f9dd..000000000000 --- a/drivers/input/lightsensor/cm3217.c +++ /dev/null @@ -1,379 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -#include -#include -#ifdef CONFIG_HAS_EARLYSUSPEND -#include -#endif - -#define DEBUG 0 - -#if DEBUG -#define DBG(X...) printk(KERN_NOTICE X) -#else -#define DBG(X...) -#endif - -#define CM3217_I2C_RATE (200*1000) -#define CM3217_ADDR_COM1 0x10 -#define CM3217_ADDR_COM2 0x11 -#define CM3217_ADDR_DATA_MSB 0x10 -#define CM3217_ADDR_DATA_LSB 0x11 - -#define CM3217_COM1_VALUE 0xA7 // (GAIN1:GAIN0)=10, (IT_T1:IT_TO)=01,WMD=1,SD=1, -#define CM3217_COM2_VALUE 0xA0 //100ms - - -#define SENSOR_ON 1 -#define SENSOR_OFF 0 -#define LIGHTSENSOR_IOCTL_MAGIC 'l' -#define LIGHTSENSOR_IOCTL_GET_ENABLED _IOR(LIGHTSENSOR_IOCTL_MAGIC, 1, int *) -#define LIGHTSENSOR_IOCTL_ENABLE _IOW(LIGHTSENSOR_IOCTL_MAGIC, 2, int *) -#define LIGHTSENSOR_IOCTL_DISABLE _IOW(LIGHTSENSOR_IOCTL_MAGIC, 3, int *) - -struct cm3217_data { - struct i2c_client *client; - struct timer_list timer; - struct work_struct timer_work; - struct input_dev *input; - int power_pin; - int irq_pin; - int status; -}; -#ifdef CONFIG_HAS_EARLYSUSPEND -static struct early_suspend cm3217_early_suspend; -#endif -static struct cm3217_data *glight; - -static int cm3217_command_set(struct i2c_client *client, char *buf, int num) -{ - int ret = 0; - ret = i2c_master_normal_send(client, buf, num, CM3217_I2C_RATE); - - return (ret == num) ? 0 : ret; -} - -static int cm3217_command_get(struct i2c_client *client, char *buf, int num) -{ - int ret = 0; - ret = i2c_master_normal_recv(client, buf, num, CM3217_I2C_RATE); - - return (ret == num) ? 0 : ret; -} - - -static int cm3217_start(struct cm3217_data *data) -{ - struct cm3217_data *cm3217 = data; - char buf = 0; - if(cm3217->status) - return 0; - - //if(cm3217->power_pin != INVALID_GPIO) - //gpio_direction_output(cm3217->power_pin,0);//level = 0 Sensor ON - - buf = CM3217_COM1_VALUE & 0xfe ; //SD=0 - cm3217->client->addr = CM3217_ADDR_COM1; - cm3217_command_set(cm3217->client, &buf, 1); - - cm3217->status = SENSOR_ON; - cm3217->timer.expires = jiffies + 1*HZ; - add_timer(&cm3217->timer); - DBG("cm3217 light sensor start\n"); - return 0; -} - -static int cm3217_stop(struct cm3217_data *data) -{ - struct cm3217_data *cm3217 = data; - char buf = 0; - if(cm3217->status == 0) - return 0; - - //if(cm3217->power_pin != INVALID_GPIO) - //gpio_direction_output(cm3217->power_pin,1);//level = 1 Sensor OFF - - buf = CM3217_COM1_VALUE | 0x01 ; //SD=1 - cm3217->client->addr = CM3217_ADDR_COM1; - cm3217_command_set(cm3217->client, &buf, 1); - - cm3217->status = SENSOR_OFF; - del_timer(&cm3217->timer); - DBG("cm3217 light sensor stop\n"); - return 0; -} - -#ifdef CONFIG_HAS_EARLYSUSPEND -static void cm3217_suspend(struct early_suspend *h) -{ - struct cm3217_data *cm3217 = glight; - int status = cm3217->status; - cm3217_stop(cm3217); - cm3217->status = status; - DBG("Light Sensor cm3217 enter suspend cm3217->status %d\n",cm3217->status); -} - -static void cm3217_resume(struct early_suspend *h) -{ - struct cm3217_data *cm3217 = glight; - if(cm3217->status == SENSOR_ON) - cm3217_start(cm3217); - DBG("Light Sensor cm3217 enter resume cm3217->status %d\n",cm3217->status); -} -#endif -static int cm3217_open(struct inode *indoe, struct file *file) -{ - return 0; -} - -static int cm3217_release(struct inode *inode, struct file *file) -{ - return 0; -} - - -static long cm3217_ioctl( struct file *file, unsigned int cmd, unsigned long arg) -{ - unsigned int *argp = (unsigned int *)arg; - struct cm3217_data *cm3217 = glight; - switch(cmd){ - case LIGHTSENSOR_IOCTL_GET_ENABLED: - *argp = cm3217->status; - break; - case LIGHTSENSOR_IOCTL_ENABLE: - if(*argp) - cm3217_start(cm3217); - else - cm3217_stop(cm3217); - break; - default:break; - } - return 0; -} - -static void cm3217_value_report(struct input_dev *input, int data) -{ - unsigned char index = 0; - if(data <= 10){ - index = 0;goto report; - } - else if(data <= 160){ - index = 1;goto report; - } - else if(data <= 225){ - index = 2;goto report; - } - else if(data <= 320){ - index = 3;goto report; - } - else if(data <= 640){ - index = 4;goto report; - } - else if(data <= 1280){ - index = 5;goto report; - } - else if(data <= 2600){ - index = 6;goto report; - } - else{ - index = 7;goto report; - } - -report: - DBG("cm3217 report data=%d,index = %d\n",data,index); - input_report_abs(input, ABS_MISC, index); - input_sync(input); - return; -} - -static void adc_timer(unsigned long data) -{ - struct cm3217_data *cm3217=(struct cm3217_data *)data; - schedule_work(&cm3217->timer_work); -} - -static void adc_timer_work(struct work_struct *work) -{ - int result = 0; - struct cm3217_data *cm3217 = container_of(work, struct cm3217_data,timer_work); - char msb = 0, lsb = 0; - - cm3217->client->addr = CM3217_ADDR_DATA_LSB; - cm3217_command_get(cm3217->client, &lsb, 1); - cm3217->client->addr = CM3217_ADDR_DATA_MSB; - cm3217_command_get(cm3217->client, &msb, 1); - result = ((msb << 8) | lsb) & 0xffff; - cm3217_value_report(cm3217->input, result); - DBG("%s:result=%d\n",__func__,result); - - if(cm3217->status){ - cm3217->timer.expires = jiffies + 1*HZ; - add_timer(&cm3217->timer); - } -} - -static struct file_operations cm3217_fops = { - .owner = THIS_MODULE, - .open = cm3217_open, - .release = cm3217_release, - .unlocked_ioctl = cm3217_ioctl, -}; - -static struct miscdevice cm3217_device = { - .minor = MISC_DYNAMIC_MINOR, - .name = "lightsensor", - .fops = &cm3217_fops, -}; - -static int cm3217_probe(struct i2c_client *client, const struct i2c_device_id *id) -{ - struct cm3217_data *cm3217; - struct cm3217_platform_data *pdata = pdata = client->dev.platform_data; - char com1 = CM3217_COM1_VALUE, com2 = CM3217_COM2_VALUE; - int err; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) - { - dev_err(&client->dev, "Must have I2C_FUNC_I2C.\n"); - err = -ENODEV; - goto alloc_memory_fail; - } - - cm3217 = kmalloc(sizeof(struct cm3217_data), GFP_KERNEL); - if(!cm3217){ - printk("cm3217 alloc memory err !!!\n"); - err = -ENOMEM; - goto alloc_memory_fail; - } - - if(pdata->init_platform_hw) - pdata->init_platform_hw(); - - cm3217->client = client; - i2c_set_clientdata(client, cm3217); - cm3217->power_pin = pdata->power_pin; - cm3217->irq_pin = pdata->irq_pin; - cm3217->status = SENSOR_OFF; - glight = cm3217; - - //init cm3217 - client->addr = CM3217_ADDR_COM1; - cm3217_command_set(client, &com1, 1); - client->addr = CM3217_ADDR_COM2; - cm3217_command_set(client, &com2, 1); - - cm3217->input = input_allocate_device(); - if (!cm3217->input) { - err = -ENOMEM; - printk(KERN_ERR"cm3217: Failed to allocate input device\n"); - goto exit_input_allocate_device_failed; - } - set_bit(EV_ABS, cm3217->input->evbit); - /* light sensor data */ - input_set_abs_params(cm3217->input, ABS_MISC, 0, 10, 0, 0); - cm3217->input->name = "lightsensor-level"; - - err = input_register_device(cm3217->input); - if (err < 0) { - printk(KERN_ERR"cm3217: Unable to register input device: %s\n",cm3217->input->name); - goto exit_input_register_device_failed; - } -/* - if(cm3217->power_pin != INVALID_GPIO) - { - gpio_request(cm3217->power_pin, "cm3217_power_pin"); - gpio_pull_updown(cm3217->power_pin,PullDisable); - } -*/ - INIT_WORK(&cm3217->timer_work, adc_timer_work); - setup_timer(&cm3217->timer, adc_timer, (unsigned long)cm3217); - err = misc_register(&cm3217_device); - if (err < 0) { - printk(KERN_ERR"cm3217_probe: lightsensor_device register failed\n"); - goto exit_misc_register_fail; - } - printk("lightsensor cm3217 driver created !\n"); - //cm3217_start(cm3217); -#ifdef CONFIG_HAS_EARLYSUSPEND - cm3217_early_suspend.suspend = cm3217_suspend; - cm3217_early_suspend.resume = cm3217_resume; - cm3217_early_suspend.level = 0x2; - register_early_suspend(&cm3217_early_suspend); -#endif - return 0; -exit_misc_register_fail: - //gpio_free(pdata->power_pin); - input_unregister_device(cm3217->input); -exit_input_register_device_failed: - input_free_device(cm3217->input); -exit_input_allocate_device_failed: - kfree(cm3217); -alloc_memory_fail: - printk("%s error\n",__FUNCTION__); - return err; -} - -static int cm3217_remove(struct i2c_client *client) -{ - struct cm3217_data *cm3217 = i2c_get_clientdata(client); - kfree(cm3217); - input_free_device(cm3217->input); - input_unregister_device(cm3217->input); - misc_deregister(&cm3217_device); - return 0; -} - -static const struct i2c_device_id cm3217_id[] = { - { "lightsensor", 0 }, -}; - -static void cm3217_shutdown(struct i2c_client *client) -{ -#ifdef CONFIG_HAS_EARLYSUSPEND - unregister_early_suspend(&cm3217_early_suspend); -#endif -} - -static struct i2c_driver cm3217_driver = { - .probe = cm3217_probe, - .remove = __devexit_p(cm3217_remove), - .shutdown = cm3217_shutdown, - .id_table = cm3217_id, - .driver = { - .owner = THIS_MODULE, - .name = "lightsensor", - } -}; - - -static int __init cm3217_init(void) -{ - return i2c_add_driver(&cm3217_driver); -} - -static void __exit cm3217_exit(void) -{ - i2c_del_driver(&cm3217_driver); -} - -module_init(cm3217_init); -module_exit(cm3217_exit); diff --git a/drivers/input/lightsensor/rk29_lightsensor.c b/drivers/input/lightsensor/rk29_lightsensor.c deleted file mode 100644 index 1fcc569c2c88..000000000000 --- a/drivers/input/lightsensor/rk29_lightsensor.c +++ /dev/null @@ -1,379 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef CONFIG_HAS_EARLYSUSPEND -#include -#endif - -#include -#ifdef CONFIG_HAS_EARLYSUSPEND -static struct early_suspend cm3202_early_suspend; -#endif - - -struct rk29_lsr_platform_data *lightsensor; -static void lsr_report_value(struct input_dev *input_dev, int value) -{ - input_report_abs(input_dev, ABS_MISC/*ABS_X*/, value); - input_sync(input_dev); -} - - -static inline void timer_callback(unsigned long data) -{ - int ret; - unsigned int rate; - adc_async_read(lightsensor->client); - mutex_lock(&lightsensor->lsr_mutex); - rate = lightsensor->rate; - mutex_unlock(&lightsensor->lsr_mutex); - if(lightsensor->client->result != lightsensor->oldresult) - { - lsr_report_value(lightsensor->input_dev, lightsensor->client->result); - lightsensor->oldresult = lightsensor->client->result; - } - ret = mod_timer( &lightsensor->timer, jiffies + msecs_to_jiffies(RATE(rate))); - if(ret) - printk("Error in mod_timer\n"); -} -static inline void set_lsr_value(bool state) -{ - if(state) - lightsensor->lsr_state = 1; - else - lightsensor->lsr_state = 0; - gpio_direction_output(LSR_GPIO, lightsensor->lsr_state); - gpio_set_value(LSR_GPIO, lightsensor->lsr_state); -} - -static inline unsigned int get_lsr_value(void) -{ - if(0 == lightsensor->lsr_state) - return 0; - else - return 1; -} - -static inline unsigned int get_adc_value(void) -{ - - return lightsensor->client->result; -} - -static inline unsigned int set_lsr_rate(unsigned int value) -{ - mutex_lock(&lightsensor->lsr_mutex); - if(value <= 0) - value = 1; - if(value >= 100) - value = 100; - lightsensor->rate = value; - mutex_unlock(&lightsensor->lsr_mutex); - return 0; -} -static inline unsigned int set_lsr_timer(unsigned int value) -{ - if(value > 0) - { - if(1 != lightsensor->timer_on) - { - add_timer(&lightsensor->timer); - lightsensor->timer_on = 1; - } - - } - if(value == 0) - { - if(0 != lightsensor->timer_on) - { - del_timer(&lightsensor->timer); - lightsensor->timer_on = 0; - } - - } - return 0; -} - - - -static ssize_t lsr_store_value(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - unsigned long val; - if(0 == count) - return count; - if (strict_strtoul(buf, 10, &val) < 0) - return -EINVAL; - if(val) - set_lsr_value(true); - else - set_lsr_value(false); - return count; -} - -static ssize_t lsr_show_value(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return sprintf(buf, "lsr value:%d\nadc value:%d\n", get_lsr_value(),get_adc_value()); -} - -static DEVICE_ATTR(value, S_IWUSR|S_IRUGO, lsr_show_value, lsr_store_value ); - -static struct attribute *lsr_attributes[] = { - &dev_attr_value.attr, - NULL -}; - -static const struct attribute_group lsr_attr_group = { - .attrs = lsr_attributes, -}; -static int rk29_lsr_io_init(struct platform_device *dev) -{ - int err; - struct platform_device *pdev = dev; - struct rk29_lsr_platform_data *pdata = pdev->dev.platform_data; - - err = gpio_request(pdata->gpio, pdata->desc ?: "rk29-lsr"); - if (err) { - gpio_free(pdata->gpio); - printk("-------request RK29_PIN6_PB1 fail--------\n"); - return -1; - } - - gpio_direction_output(pdata->gpio, pdata->active_low); - gpio_set_value(pdata->gpio, pdata->active_low); - set_lsr_value(STARTUP_LEV_LOW); - err = sysfs_create_group(&pdev->dev.kobj, &lsr_attr_group); - return 0; -} -static int rk29_lsr_io_deinit(struct platform_device *dev) -{ - struct platform_device *pdev = dev; - struct rk29_lsr_platform_data *pdata = pdev->dev.platform_data; - - gpio_direction_output(pdata->gpio, pdata->active_low); - gpio_set_value(pdata->gpio, pdata->active_low); - - gpio_free(pdata->gpio); - sysfs_remove_group(&pdev->dev.kobj, &lsr_attr_group); - return 0; -} -static void callback(struct adc_client *client, void *callback_param, int result) -{ - client->result = result; -} -static int rk29_lsr_adc_init(struct platform_device *dev) -{ - struct rk29_lsr_platform_data *pdata = dev->dev.platform_data; - pdata->client = adc_register(pdata->adc_chn, callback, "lsr_adc"); - if(!pdata->client) - return -EINVAL; - mutex_init(&pdata->lsr_mutex); - return 0; -} -static void rk29_lsr_adc_deinit(struct platform_device *dev) -{ - struct rk29_lsr_platform_data *pdata = dev->dev.platform_data; - adc_unregister(pdata->client); - mutex_destroy(&pdata->lsr_mutex); -} - -static void rk29_lsr_timer_init(struct platform_device *dev) -{ - int ret; - struct rk29_lsr_platform_data *pdata = dev->dev.platform_data; - setup_timer(&pdata->timer, timer_callback, 0); - lightsensor->timer_on = 1; - ret = mod_timer( &pdata->timer, jiffies + msecs_to_jiffies(pdata->delay_time) ); - if(ret) - printk("Error in mod_timer\n"); - return ; -} -static void rk29_lsr_timer_deinit(struct platform_device *dev) -{ - struct rk29_lsr_platform_data *pdata = dev->dev.platform_data; - del_timer(&pdata->timer); - lightsensor->timer_on = 0; -} - -static void rk29_lsr_input_init(struct platform_device *dev) -{ - int ret; - struct rk29_lsr_platform_data *pdata = dev->dev.platform_data; - pdata->input_dev = input_allocate_device(); - if (!pdata->input_dev) { - printk(KERN_ERR"rk29_lsr_input_init: Failed to allocate input device\n"); - goto init_input_register_device_failed; - } - pdata->input_dev->name = "lsensor"; - pdata->input_dev->dev.parent = &dev->dev; - pdata->input_dev->evbit[0] = BIT(EV_ABS); - input_set_abs_params(pdata->input_dev,ABS_MISC/*ABS_X*/,0,9/*0x3ff*/,0,0); - ret = input_register_device(pdata->input_dev); - return ; -init_input_register_device_failed: -input_free_device(pdata->input_dev); -} - -static void rk29_lsr_input_deinit(struct platform_device *dev) -{ - struct rk29_lsr_platform_data *pdata = dev->dev.platform_data; - input_unregister_device(pdata->input_dev); - input_free_device(pdata->input_dev); -} -static int lsr_suspend(struct platform_device *pdev, pm_message_t state) -{ - set_lsr_timer(0); - set_lsr_value(LSR_OFF); - return 0; -} - -static int lsr_resume(struct platform_device *pdev) -{ - set_lsr_timer(1); - set_lsr_value(LSR_ON); - return 0; -} -static int __devinit lsr_probe(struct platform_device *pdev) -{ - lightsensor = kzalloc(sizeof(struct rk29_lsr_platform_data), GFP_KERNEL); - if(!lightsensor) - { - dev_err(&pdev->dev, "no memory for state\n"); - goto err_kzalloc_lightsensor; - } - lightsensor->gpio = LSR_GPIO; - lightsensor->desc = "rk29-lsr"; - lightsensor->adc_chn = 2; - lightsensor->delay_time = 1000; - lightsensor->rate = 100; - lightsensor->oldresult = 0; - lightsensor->active_low = STARTUP_LEV_LOW; - pdev->dev.platform_data = lightsensor; - rk29_lsr_io_init(pdev); - rk29_lsr_adc_init(pdev); - rk29_lsr_timer_init(pdev); - rk29_lsr_input_init(pdev); -#ifdef CONFIG_HAS_EARLYSUSPEND - cm3202_early_suspend.suspend = lsr_suspend; - cm3202_early_suspend.resume = lsr_resume; - register_early_suspend(&cm3202_early_suspend); -#endif - - return 0; - -err_kzalloc_lightsensor: - kfree(lightsensor); - return 0; - -} - -static int __devexit lsr_remove(struct platform_device *pdev) -{ - rk29_lsr_io_deinit(pdev); - rk29_lsr_adc_deinit(pdev); - rk29_lsr_timer_deinit(pdev); - rk29_lsr_input_deinit(pdev); - kfree(lightsensor); - return 0; -} - -static struct platform_driver lsr_device_driver = { - .probe = lsr_probe, - .remove = __devexit_p(lsr_remove), -// .suspend = lsr_suspend, -// .resume = lsr_resume, - .driver = { - .name = LSR_NAME, - .owner = THIS_MODULE, - } -}; - -static int lsr_adc_open(struct inode * inode, struct file * file) -{ - set_lsr_value(LSR_ON); - return 0; -} - -static int lsr_adc_ioctl(struct tty_struct * tty,struct file * file,unsigned int cmd, unsigned long arg) -{ - int ret = 0; - switch(cmd) - { - case LSR_IOCTL_ENABLE: - set_lsr_value(arg); - break; - case LSR_IOCTL_SETRATE: - set_lsr_rate(arg); - break; - case LSR_IOCTL_DEVNAME: - ret = copy_to_user((void __user *)arg,lightsensor->input_dev->name,strlen(lightsensor->input_dev->name)+1); - break; - case LSR_IOCTL_SWICTH: - set_lsr_timer(arg); - break; - default: - break; - } - return ret; -} - -static ssize_t lsr_adc_read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off) -{ - int ret; - ret = copy_to_user(userbuf,&lightsensor->client->result,bytes); - return ret; -} - -static struct file_operations lsr_adc_fops = { - .owner = THIS_MODULE, - .open = lsr_adc_open, - .read = lsr_adc_read, - .ioctl = lsr_adc_ioctl, -}; - -static struct miscdevice misc_lsr_adc_device = { - .minor = MISC_DYNAMIC_MINOR, - .name = LSR_NAME, - .fops = &lsr_adc_fops, -}; - -static int __init lsr_init(void) -{ - platform_driver_register(&lsr_device_driver); - misc_register(&misc_lsr_adc_device); - return 0; -} - -static void __exit lsr_exit(void) -{ - platform_driver_unregister(&lsr_device_driver); - misc_deregister(&misc_lsr_adc_device); -} - -module_init(lsr_init); -module_exit(lsr_exit); - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Seven Huang "); -MODULE_DESCRIPTION("Light sensor for Backlight"); -MODULE_ALIAS("platform:gpio-lightsensor"); diff --git a/drivers/input/lightsensor/us5151.c b/drivers/input/lightsensor/us5151.c deleted file mode 100644 index 51552f40faec..000000000000 --- a/drivers/input/lightsensor/us5151.c +++ /dev/null @@ -1,393 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -#include -#include -#ifdef CONFIG_HAS_EARLYSUSPEND -#include -#endif - -#define DEBUG 0 - -#define POWER_PIN NULL//RK29_PIN6_PA0 - -#if DEBUG -#define DBG(X...) printk(KERN_NOTICE X) -#else -#define DBG(X...) -#endif - -//#define DATA_ADC_CHN 2 //SARADC_AIN[3] -#define SENSOR_ON 1 -#define SENSOR_OFF 0 -#define LIGHTSENSOR_IOCTL_MAGIC 'l' -#define LIGHTSENSOR_IOCTL_GET_ENABLED _IOR(LIGHTSENSOR_IOCTL_MAGIC, 1, int *) -#define LIGHTSENSOR_IOCTL_ENABLE _IOW(LIGHTSENSOR_IOCTL_MAGIC, 2, int *) -#define LIGHTSENSOR_IOCTL_DISABLE _IOW(LIGHTSENSOR_IOCTL_MAGIC, 3, int *) - -struct us5151_data { - struct timer_list timer; - struct work_struct timer_work; - struct input_dev *input; - struct i2c_client *client; - int statue; -}; -#ifdef CONFIG_HAS_EARLYSUSPEND -static struct early_suspend us5151_early_suspend; -#endif -static struct us5151_data *light; - -static int us5151_rx_data(struct i2c_client *client, char *rxData, int length) -{ - int ret = 0; - char reg = rxData[0]; - DBG("%s.....%d...\n",__FUNCTION__,__LINE__); - ret = i2c_master_reg8_recv(client, reg, rxData, length, 250*1000); - return (ret > 0)? 0 : ret; -} - -static int us5151_tx_data(struct i2c_client *client, char *txData, int length) -{ - int ret = 0; - char reg = txData[0]; - char i = 0; - DBG("%s.....%d...\n",__FUNCTION__,__LINE__); - - ret =i2c_master_normal_send(client,txData,length,250*1000); - //ret = i2c_master_reg8_send(client, reg, &txData[1], length-1, 250*1000); - return (ret > 0)? 0 : ret; -} - -static char start_flag = 0; -static int us5151_start(struct us5151_data *data) -{ - struct us5151_data *us5151 = data; - int ret = 0; - char txData[2] = {0x01,0x80}; - - DBG("%s.....%d...\n",__FUNCTION__,__LINE__); - if(us5151->statue) - return 0; - ret = us5151_tx_data(us5151->client,txData,sizeof(txData)); - if (ret == 0) - { - us5151->statue = SENSOR_ON; - us5151->timer.expires = jiffies + 3*HZ; - add_timer(&us5151->timer); - } - else - { - us5151->statue = 0; - printk("%s......%d ret=%d\n",__FUNCTION__,__LINE__,ret); - } - printk("========== us5151 light sensor start ==========\n"); - return 0; -} - -static int us5151_stop(struct us5151_data *data) -{ - struct us5151_data *us5151 = data; - int ret = 0; - char txData[2] = {0x01,0x00}; - - DBG("%s.....%d...\n",__FUNCTION__,__LINE__); - if(us5151->statue == 0) - return 0; - - ret = us5151_tx_data(us5151->client,txData,sizeof(txData)); - if (ret == 0) - { - us5151->statue = SENSOR_OFF; - del_timer(&us5151->timer); - } - else - { - us5151->statue = 0; - printk("%s......%d ret=%d\n",__FUNCTION__,__LINE__,ret); - } - printk("========== us5151 light sensor stop ==========\n"); - return 0; -} - -#ifdef CONFIG_HAS_EARLYSUSPEND -static void us5151_suspend(struct early_suspend *h) -{ - struct us5151_data *us5151 = light; - - if (start_flag == 1) - us5151_stop(us5151); - - printk("Light Sensor us5151 enter suspend us5151->status %d\n",us5151->statue); -} - -static void us5151_resume(struct early_suspend *h) -{ - struct us5151_data *us5151 = light; - - if (start_flag == 1) - us5151_start(us5151); - - printk("Light Sensor us5151 enter resume us5151->status %d\n",us5151->statue); -} -#endif -static int us5151_open(struct inode *indoe, struct file *file) -{ - DBG("%s.....%d\n",__FUNCTION__,__LINE__); - return 0; -} - -static int us5151_release(struct inode *inode, struct file *file) -{ - DBG("%s.....%d\n",__FUNCTION__,__LINE__); - return 0; -} - -static long us5151_ioctl(struct file *file, unsigned int cmd, unsigned long arg) -{ - unsigned long *argp = (unsigned long *)arg; - - DBG("%s.....%d\n",__FUNCTION__,__LINE__); - switch(cmd){ - case LIGHTSENSOR_IOCTL_GET_ENABLED: - *argp = light->statue; - break; - case LIGHTSENSOR_IOCTL_ENABLE: - if(*argp) - { - start_flag = 1; - us5151_start(light); - } - else - { - start_flag = 0; - us5151_stop(light); - } - break; - default:break; - } - return 0; -} - -static void us5151_value_report(struct input_dev *input, int data) -{ - unsigned char index = 0; - if(data <= 30){ - index = 0;goto report; - } - else if(data <= 100){ - index = 1;goto report; - } - else if(data <= 150){ - index = 2;goto report; - } - else if(data <= 220){ - index = 3;goto report; - } - else if(data <= 280){ - index = 4;goto report; - } - else if(data <= 350){ - index = 5;goto report; - } - else if(data <= 420){ - index = 6;goto report; - } - else{ - index = 7;goto report; - } -report: - DBG("us5151 report index = %d data=%d\n",index,data); - input_report_abs(input, ABS_MISC, index); - input_sync(input); - return; -} - -static void us5151_read(struct work_struct *work) -{ - - int ret = 0; - int adc_value = 35541; - char value[2] = {0x02,0x03}; - char enable[1] = {0x01}; - - struct us5151_data *us5151 = container_of(work, struct us5151_data,timer_work); - - ret = us5151_rx_data(us5151->client,value,sizeof(value)); - ret = us5151_rx_data(us5151->client,enable,sizeof(enable)); - if (ret == 0) - { - adc_value = value[1]>>7 | value[0]<<1; - DBG("%s......%d ret=%d value[0]=%d value[1]=%d adc_value=%d enable=%d\n",__FUNCTION__,__LINE__,ret,value[0],value[1],adc_value,enable[0]); - us5151_value_report(us5151->input,adc_value); - } - else - { - //us5151->statue = 0; - printk("%s......%d ret=%d value[0]=%d value[1]=%d adc_value=%d\n",__FUNCTION__,__LINE__,ret,value[0],value[1],adc_value); - } - - if(us5151->statue){ - us5151->timer.expires = jiffies + 3*HZ; - add_timer(&us5151->timer); - } -}; - -static void us5151_read_value(unsigned long data) -{ - struct us5151_data *us5151=(struct us5151_data *)data; - schedule_work(&us5151->timer_work); -}; -static struct file_operations us5151_fops = { - .owner = THIS_MODULE, - .unlocked_ioctl = us5151_ioctl, - .open = us5151_open, - .release = us5151_release, -}; - -static struct miscdevice us5151_device = { - .minor = MISC_DYNAMIC_MINOR, - .name = "lightsensor", - .fops = &us5151_fops, -}; - -static ssize_t us5151_start_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len) -{ - - DBG("%s......\n",__FUNCTION__); - if (*buf == 'A') - us5151_start(light); - else - { - us5151_stop(light); - printk("%s.........%s\n",__FUNCTION__,buf); - } - - return len; -}; -static DEVICE_ATTR(start,0666,NULL,us5151_start_store); - -static int us5151_probe(struct i2c_client *pdev,const struct i2c_device_id *id) -{ - struct us5151_data *us5151; - struct us5151_platform_data *pdata = pdata = pdev->dev.platform_data; - int err; - DBG("============= us5151 probe enter ==============\n"); - us5151 = kmalloc(sizeof(struct us5151_data), GFP_KERNEL); - if(!us5151){ - printk("us5151 alloc memory err !!!\n"); - err = -ENOMEM; - goto alloc_memory_fail; - } - light = us5151; - us5151->statue = SENSOR_OFF; - us5151->client = pdev; - us5151->input = input_allocate_device(); - if (!us5151->input) { - err = -ENOMEM; - printk(KERN_ERR"us5151: Failed to allocate input device\n"); - goto exit_input_allocate_device_failed; - } - set_bit(EV_ABS, us5151->input->evbit); - /* light sensor data */ - input_set_abs_params(us5151->input, ABS_MISC, 0, 0x1ff, 0, 0); - us5151->input->name = "lightsensor-level"; - - err = input_register_device(us5151->input); - if (err < 0) { - printk(KERN_ERR"us5151: Unable to register input device: %s\n",us5151->input->name); - goto exit_input_register_device_failed; - } - - INIT_WORK(&us5151->timer_work,us5151_read); - setup_timer(&us5151->timer, us5151_read_value, (unsigned long)us5151); - - err = misc_register(&us5151_device); - if (err < 0) { - printk(KERN_ERR"us5151_probe: lightsensor_device register failed\n"); - goto exit_misc_register_fail; - } - - err = device_create_file(&pdev->dev, &dev_attr_start); - if (err) - { - - printk("%s....make a mistake in creating devices attr file\n\n ",__FUNCTION__); - } - -#ifdef CONFIG_HAS_EARLYSUSPEND - us5151_early_suspend.suspend = us5151_suspend; - us5151_early_suspend.resume = us5151_resume; - us5151_early_suspend.level = 0x2; - register_early_suspend(&us5151_early_suspend); -#endif - - printk("lightsensor us5151 driver created !\n"); - //us5151_start(light); - return 0; -exit_misc_register_fail: - input_unregister_device(us5151->input); -exit_input_register_device_failed: - input_free_device(us5151->input); -exit_input_allocate_device_failed: - kfree(us5151); -alloc_memory_fail: - printk("%s error\n",__FUNCTION__); - return err; -} - -static __devexit int us5151_remove(struct i2c_client *pdev) -{ - struct us5151_data *us5151 = light; - kfree(us5151); - input_free_device(us5151->input); - input_unregister_device(us5151->input); - misc_deregister(&us5151_device); - return 0; -} - -static const struct i2c_device_id us5151_i2c_id[] = { - { "us5151", 0 }, - { } -}; - -static struct i2c_driver us5151_driver = { - .probe = us5151_probe, - .remove = __devexit_p(us5151_remove), - .driver = { - .owner = THIS_MODULE, - .name = "lightsensor", - }, - .id_table = us5151_i2c_id, -}; - -static int __init us5151_init(void) -{ - return i2c_add_driver(&us5151_driver); -} - -static void __exit us5151_exit(void) -{ - i2c_del_driver(&us5151_driver); -} - -module_init(us5151_init); -module_exit(us5151_exit);