1 /* drivers/input/sensors/sensor-dev.c - handle all gsensor in this file
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.
17 #include <linux/interrupt.h>
18 #include <linux/i2c.h>
19 #include <linux/slab.h>
20 #include <linux/irq.h>
21 #include <linux/miscdevice.h>
22 #include <linux/gpio.h>
23 #include <asm/uaccess.h>
24 #include <asm/atomic.h>
25 #include <linux/delay.h>
26 #include <linux/input.h>
27 #include <linux/workqueue.h>
28 #include <linux/freezer.h>
29 #include <linux/proc_fs.h>
30 #include <linux/gpio.h>
31 #include <linux/of_gpio.h>
33 #ifdef CONFIG_HAS_EARLYSUSPEND
34 #include <linux/earlysuspend.h>
36 #include <linux/l3g4200d.h>
37 #include <linux/sensor-dev.h>
38 #include <linux/module.h>
40 #include <linux/compat.h>
45 sensor-dev.c v1.1 add pressure and temperature support 2013-2-27
46 sensor-dev.c v1.2 add akm8963 support 2013-3-10
47 sensor-dev.c v1.3 add sensor debug support 2013-3-15
48 sensor-dev.c v1.4 add angle calculation support between two gsensors 2013-09-01
51 #define SENSOR_VERSION_AND_TIME "sensor-dev.c v1.4 add angle calculation support between two gsensors 2013-09-01"
54 struct sensor_private_data *g_sensor[SENSOR_NUM_TYPES];
55 static struct sensor_operate *sensor_ops[SENSOR_NUM_ID];
56 static struct class *g_sensor_class[SENSOR_NUM_TYPES];
58 static ssize_t sensor_proc_write(struct file *file, const char __user *buffer,
59 size_t count, loff_t *data)
65 rc = get_user(c, buffer);
68 for(i=SENSOR_TYPE_NULL+1; i<SENSOR_NUM_TYPES; i++)
69 atomic_set(&g_sensor[i]->flags.debug_flag, SENSOR_TYPE_NULL);
76 printk("%s command list:close:%d,angle:%d accel:%d, compass:%d, gyro:%d, light:%d, psensor:%d, temp:%d, pressure:%d,total:%d,num=%d\n",__func__,
78 SENSOR_TYPE_NULL, SENSOR_TYPE_ANGLE, SENSOR_TYPE_ACCEL,SENSOR_TYPE_COMPASS,SENSOR_TYPE_GYROSCOPE,SENSOR_TYPE_LIGHT,SENSOR_TYPE_PROXIMITY,
80 SENSOR_TYPE_TEMPERATURE,SENSOR_TYPE_PRESSURE,SENSOR_NUM_TYPES,num);
82 if((num > SENSOR_NUM_TYPES) || (num < SENSOR_TYPE_NULL))
84 printk("%s:error! only support %d to %d\n",__func__, SENSOR_TYPE_NULL,SENSOR_NUM_TYPES);
88 for(i=SENSOR_TYPE_NULL+1; i<SENSOR_NUM_TYPES; i++)
91 atomic_set(&g_sensor[i]->flags.debug_flag, num);
97 static const struct file_operations sensor_proc_fops = {
99 .write = sensor_proc_write,
104 static int sensor_get_id(struct i2c_client *client, int *value)
106 struct sensor_private_data *sensor =
107 (struct sensor_private_data *) i2c_get_clientdata(client);
109 char temp = sensor->ops->id_reg;
112 if(sensor->ops->id_reg >= 0)
116 result = sensor_rx_data(client, &temp, 1);
125 if(*value != sensor->ops->id_data)
127 printk("%s:id=0x%x is not 0x%x\n",__func__,*value, sensor->ops->id_data);
131 DBG("%s:devid=0x%x\n",__func__,*value);
137 static int sensor_initial(struct i2c_client *client)
139 struct sensor_private_data *sensor =
140 (struct sensor_private_data *) i2c_get_clientdata(client);
143 //register setting according to chip datasheet
144 result = sensor->ops->init(client);
147 printk("%s:fail to init sensor\n",__func__);
152 DBG("%s:ctrl_data=0x%x\n",__func__,sensor->ops->ctrl_data);
158 static int sensor_chip_init(struct i2c_client *client)
160 struct sensor_private_data *sensor =
161 (struct sensor_private_data *) i2c_get_clientdata(client);
162 struct sensor_operate *ops = sensor_ops[(int)sensor->i2c_id->driver_data];
171 printk("%s:ops is null,sensor name is %s\n",__func__,sensor->i2c_id->name);
176 if((sensor->type != ops->type) || ((int)sensor->i2c_id->driver_data != ops->id_i2c))
178 printk("%s:type or id is different:type=%d,%d,id=%d,%d\n",__func__,sensor->type, ops->type, (int)sensor->i2c_id->driver_data, ops->id_i2c);
183 if(!ops->init || !ops->active || !ops->report)
185 printk("%s:error:some function is needed\n",__func__);
190 result = sensor_get_id(sensor->client, &sensor->devid);//get id
193 printk("%s:fail to read %s devid:0x%x\n",__func__, sensor->i2c_id->name, sensor->devid);
197 printk("%s:%s:devid=0x%x,ops=0x%p\n",__func__, sensor->i2c_id->name, sensor->devid,sensor->ops);
199 result = sensor_initial(sensor->client); //init sensor
202 printk("%s:fail to init sensor\n",__func__);
213 static int sensor_reset_rate(struct i2c_client *client, int rate)
215 struct sensor_private_data *sensor =
216 (struct sensor_private_data *) i2c_get_clientdata(client);
219 result = sensor->ops->active(client,SENSOR_OFF,rate);
220 sensor->ops->init(client);
221 result = sensor->ops->active(client,SENSOR_ON,rate);
226 static int sensor_get_data(struct i2c_client *client)
228 struct sensor_private_data *sensor =
229 (struct sensor_private_data *) i2c_get_clientdata(client);
232 result = sensor->ops->report(client);
237 atomic_set(&sensor->data_ready, 1);
238 /*wake up data_ready work queue*/
239 wake_up(&sensor->data_ready_wq);
246 int sensor_get_cached_data(struct i2c_client* client, char *buffer, int length, struct sensor_axis *axis)
248 struct sensor_private_data* sensor = (struct sensor_private_data *)i2c_get_clientdata(client);
249 wait_event_interruptible_timeout(sensor->data_ready_wq,
250 atomic_read(&(sensor->data_ready) ),
251 msecs_to_jiffies(1000) );
252 if ( 0 == atomic_read(&(sensor->data_ready) ) ) {
253 printk("waiting 'data_ready_wq' timed out.");
258 mutex_lock(&sensor->data_mutex);
262 case SENSOR_TYPE_ACCEL:
263 *axis = sensor->axis;
266 case SENSOR_TYPE_COMPASS:
267 memcpy(buffer, sensor->sensor_data, length);
271 mutex_unlock(&sensor->data_mutex);
280 static void sensor_delaywork_func(struct work_struct *work)
282 struct delayed_work *delaywork = container_of(work, struct delayed_work, work);
283 struct sensor_private_data *sensor = container_of(delaywork, struct sensor_private_data, delaywork);
284 struct i2c_client *client = sensor->client;
286 mutex_lock(&sensor->sensor_mutex);
287 if (sensor_get_data(client) < 0)
288 DBG(KERN_ERR "%s: Get data failed\n",__func__);
290 if(!sensor->pdata->irq_enable)//restart work while polling
291 schedule_delayed_work(&sensor->delaywork, msecs_to_jiffies(sensor->pdata->poll_delay_ms));
294 //if((sensor->ops->trig == IRQF_TRIGGER_LOW) || (sensor->ops->trig == IRQF_TRIGGER_HIGH))
295 //enable_irq(sensor->client->irq);
297 mutex_unlock(&sensor->sensor_mutex);
299 DBG("%s:%s\n",__func__,sensor->i2c_id->name);
303 * This is a threaded IRQ handler so can access I2C/SPI. Since all
304 * interrupts are clear on read the IRQ line will be reasserted and
305 * the physical IRQ will be handled again if another interrupt is
306 * asserted while we run - in the normal course of events this is a
307 * rare occurrence so we save I2C/SPI reads. We're also assuming that
308 * it's rare to get lots of interrupts firing simultaneously so try to
311 static irqreturn_t sensor_interrupt(int irq, void *dev_id)
313 struct sensor_private_data *sensor = (struct sensor_private_data *)dev_id;
316 if (sensor_get_data(sensor->client) < 0)
317 DBG(KERN_ERR "%s: Get data failed\n",__func__);
318 msleep(sensor->pdata->poll_delay_ms);
321 //if((sensor->ops->trig == IRQF_TRIGGER_LOW) || (sensor->ops->trig == IRQF_TRIGGER_HIGH))
322 //disable_irq_nosync(irq);
323 //schedule_delayed_work(&sensor->delaywork, msecs_to_jiffies(sensor->pdata->poll_delay_ms));
324 DBG("%s:irq=%d\n",__func__,irq);
329 static int sensor_irq_init(struct i2c_client *client)
331 struct sensor_private_data *sensor =
332 (struct sensor_private_data *) i2c_get_clientdata(client);
335 if((sensor->pdata->irq_enable)&&(sensor->pdata->irq_flags!= SENSOR_UNKNOW_DATA))
337 //INIT_DELAYED_WORK(&sensor->delaywork, sensor_delaywork_func);
338 if(sensor->pdata->poll_delay_ms < 0)
339 sensor->pdata->poll_delay_ms = 30;
340 result = gpio_request(client->irq, sensor->i2c_id->name);
343 printk("%s:fail to request gpio :%d\n",__func__,client->irq);
346 //gpio_pull_updown(client->irq, PullEnable);
347 irq = gpio_to_irq(client->irq);
348 //result = request_irq(irq, sensor_interrupt, sensor->ops->trig, sensor->ops->name, sensor);
349 //result = request_threaded_irq(irq, NULL, sensor_interrupt, sensor->ops->trig, sensor->ops->name, sensor);
350 result = devm_request_threaded_irq(&client->dev, irq, NULL, sensor_interrupt, sensor->pdata->irq_flags | IRQF_ONESHOT, sensor->ops->name, sensor);
352 printk(KERN_ERR "%s:fail to request irq = %d, ret = 0x%x\n",__func__, irq, result);
356 if((sensor->pdata->type == SENSOR_TYPE_GYROSCOPE) || (sensor->pdata->type == SENSOR_TYPE_ACCEL) || (sensor->pdata->type == SENSOR_TYPE_ANGLE))
357 disable_irq_nosync(client->irq);//disable irq
358 if(((sensor->pdata->type == SENSOR_TYPE_LIGHT) || (sensor->pdata->type == SENSOR_TYPE_PROXIMITY))&& (!(sensor->ops->trig & IRQF_SHARED)))
359 disable_irq_nosync(client->irq);//disable irq
360 if(((sensor->pdata->type == SENSOR_TYPE_TEMPERATURE) || (sensor->pdata->type == SENSOR_TYPE_PRESSURE))&& (!(sensor->ops->trig & IRQF_SHARED)))
361 disable_irq_nosync(client->irq);//disable irq
362 DBG("%s:use irq=%d\n",__func__,irq);
364 else if(!sensor->pdata->irq_enable)
366 INIT_DELAYED_WORK(&sensor->delaywork, sensor_delaywork_func);
367 if(sensor->pdata->poll_delay_ms < 0)
368 sensor->pdata->poll_delay_ms = 30;
370 DBG("%s:use polling,delay=%d ms\n",__func__,sensor->pdata->poll_delay_ms);
377 #ifdef CONFIG_HAS_EARLYSUSPEND
378 static void sensor_suspend(struct early_suspend *h)
380 struct sensor_private_data *sensor =
381 container_of(h, struct sensor_private_data, early_suspend);
383 if(sensor->ops->suspend)
384 sensor->ops->suspend(sensor->client);
388 static void sensor_resume(struct early_suspend *h)
390 struct sensor_private_data *sensor =
391 container_of(h, struct sensor_private_data, early_suspend);
393 if(sensor->ops->resume)
394 sensor->ops->resume(sensor->client);
399 static int sensor_of_suspend(struct device *dev)
401 struct sensor_private_data *sensor = dev_get_drvdata(dev);
403 if (sensor->ops->suspend)
404 sensor->ops->suspend(sensor->client);
409 static int sensor_of_resume(struct device *dev)
411 struct sensor_private_data *sensor = dev_get_drvdata(dev);
413 if (sensor->ops->resume)
414 sensor->ops->resume(sensor->client);
415 if (sensor->pdata->power_off_in_suspend)
416 sensor_initial(sensor->client);
421 static const struct dev_pm_ops sensor_pm_ops = {
422 SET_SYSTEM_SLEEP_PM_OPS(sensor_of_suspend, sensor_of_resume)
425 #define SENSOR_PM_OPS (&sensor_pm_ops)
427 #define SENSOR_PM_OPS NULL
430 static int angle_dev_open(struct inode *inode, struct file *file)
432 //struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_ACCEL];
433 //struct i2c_client *client = sensor->client;
442 static int angle_dev_release(struct inode *inode, struct file *file)
444 //struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_ANGLE];
445 //struct i2c_client *client = sensor->client;
453 /* ioctl - I/O control */
454 static long angle_dev_ioctl(struct file *file,
455 unsigned int cmd, unsigned long arg)
457 struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_ANGLE];
458 struct i2c_client *client = sensor->client;
459 void __user *argp = (void __user *)arg;
460 struct sensor_axis axis = {0};
465 case GSENSOR_IOCTL_APP_SET_RATE:
466 if (copy_from_user(&rate, argp, sizeof(rate)))
477 case GSENSOR_IOCTL_START:
478 DBG("%s:GSENSOR_IOCTL_START start,status=%d\n", __func__,sensor->status_cur);
479 mutex_lock(&sensor->operation_mutex);
480 if(++sensor->start_count == 1)
482 if(sensor->status_cur == SENSOR_OFF)
484 atomic_set(&(sensor->data_ready), 0);
485 if ( (result = sensor->ops->active(client, 1, 0) ) < 0 ) {
486 mutex_unlock(&sensor->operation_mutex);
487 printk("%s:fail to active sensor,ret=%d\n",__func__,result);
490 if(sensor->pdata->irq_enable)
492 DBG("%s:enable irq,irq=%d\n",__func__,client->irq);
493 enable_irq(client->irq); //enable irq
497 schedule_delayed_work(&sensor->delaywork, msecs_to_jiffies(sensor->pdata->poll_delay_ms));
499 sensor->status_cur = SENSOR_ON;
502 mutex_unlock(&sensor->operation_mutex);
503 DBG("%s:GSENSOR_IOCTL_START OK\n", __func__);
506 case GSENSOR_IOCTL_CLOSE:
507 DBG("%s:GSENSOR_IOCTL_CLOSE start,status=%d\n", __func__,sensor->status_cur);
508 mutex_lock(&sensor->operation_mutex);
509 if(--sensor->start_count == 0)
511 if(sensor->status_cur == SENSOR_ON)
513 atomic_set(&(sensor->data_ready), 0);
514 if ( (result = sensor->ops->active(client, 0, 0) ) < 0 ) {
515 mutex_unlock(&sensor->operation_mutex);
519 if(sensor->pdata->irq_enable)
521 DBG("%s:disable irq,irq=%d\n",__func__,client->irq);
522 disable_irq_nosync(client->irq);//disable irq
525 cancel_delayed_work_sync(&sensor->delaywork);
526 sensor->status_cur = SENSOR_OFF;
529 DBG("%s:GSENSOR_IOCTL_CLOSE OK\n", __func__);
532 mutex_unlock(&sensor->operation_mutex);
535 case GSENSOR_IOCTL_APP_SET_RATE:
536 DBG("%s:GSENSOR_IOCTL_APP_SET_RATE start\n", __func__);
537 mutex_lock(&sensor->operation_mutex);
538 result = sensor_reset_rate(client, rate);
540 mutex_unlock(&sensor->operation_mutex);
544 sensor->status_cur = SENSOR_ON;
545 mutex_unlock(&sensor->operation_mutex);
546 DBG("%s:GSENSOR_IOCTL_APP_SET_RATE OK\n", __func__);
549 case GSENSOR_IOCTL_GETDATA:
550 mutex_lock(&sensor->data_mutex);
551 memcpy(&axis, &sensor->axis, sizeof(sensor->axis)); //get data from buffer
552 mutex_unlock(&sensor->data_mutex);
560 case GSENSOR_IOCTL_GETDATA:
561 if ( copy_to_user(argp, &axis, sizeof(axis) ) ) {
562 printk("failed to copy sense data to user space.");
566 DBG("%s:GSENSOR_IOCTL_GETDATA OK\n", __func__);
577 static int gsensor_dev_open(struct inode *inode, struct file *file)
579 //struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_ACCEL];
580 //struct i2c_client *client = sensor->client;
589 static int gsensor_dev_release(struct inode *inode, struct file *file)
591 //struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_ACCEL];
592 //struct i2c_client *client = sensor->client;
600 /* ioctl - I/O control */
601 static long gsensor_dev_ioctl(struct file *file,
602 unsigned int cmd, unsigned long arg)
604 struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_ACCEL];
605 struct i2c_client *client = sensor->client;
606 void __user *argp = (void __user *)arg;
607 struct sensor_axis axis = {0};
612 case GSENSOR_IOCTL_APP_SET_RATE:
613 if (copy_from_user(&rate, argp, sizeof(rate)))
624 case GSENSOR_IOCTL_START:
625 DBG("%s:GSENSOR_IOCTL_START start,status=%d\n", __func__,sensor->status_cur);
626 mutex_lock(&sensor->operation_mutex);
627 if(++sensor->start_count == 1)
629 if(sensor->status_cur == SENSOR_OFF)
631 atomic_set(&(sensor->data_ready), 0);
632 if ( (result = sensor->ops->active(client, 1, 0) ) < 0 ) {
633 mutex_unlock(&sensor->operation_mutex);
634 printk("%s:fail to active sensor,ret=%d\n",__func__,result);
637 if(sensor->pdata->irq_enable)
639 DBG("%s:enable irq,irq=%d\n",__func__,client->irq);
640 enable_irq(client->irq); //enable irq
644 schedule_delayed_work(&sensor->delaywork, msecs_to_jiffies(sensor->pdata->poll_delay_ms));
646 sensor->status_cur = SENSOR_ON;
649 mutex_unlock(&sensor->operation_mutex);
650 DBG("%s:GSENSOR_IOCTL_START OK\n", __func__);
653 case GSENSOR_IOCTL_CLOSE:
654 DBG("%s:GSENSOR_IOCTL_CLOSE start,status=%d\n", __func__,sensor->status_cur);
655 mutex_lock(&sensor->operation_mutex);
656 if(--sensor->start_count == 0)
658 if(sensor->status_cur == SENSOR_ON)
660 atomic_set(&(sensor->data_ready), 0);
661 if ( (result = sensor->ops->active(client, 0, 0) ) < 0 ) {
662 mutex_unlock(&sensor->operation_mutex);
666 if(sensor->pdata->irq_enable)
668 DBG("%s:disable irq,irq=%d\n",__func__,client->irq);
669 disable_irq_nosync(client->irq);//disable irq
672 cancel_delayed_work_sync(&sensor->delaywork);
673 sensor->status_cur = SENSOR_OFF;
676 DBG("%s:GSENSOR_IOCTL_CLOSE OK\n", __func__);
679 mutex_unlock(&sensor->operation_mutex);
682 case GSENSOR_IOCTL_APP_SET_RATE:
683 DBG("%s:GSENSOR_IOCTL_APP_SET_RATE start\n", __func__);
684 mutex_lock(&sensor->operation_mutex);
685 result = sensor_reset_rate(client, rate);
687 mutex_unlock(&sensor->operation_mutex);
691 sensor->status_cur = SENSOR_ON;
692 mutex_unlock(&sensor->operation_mutex);
693 DBG("%s:GSENSOR_IOCTL_APP_SET_RATE OK\n", __func__);
696 case GSENSOR_IOCTL_GETDATA:
697 mutex_lock(&sensor->data_mutex);
698 memcpy(&axis, &sensor->axis, sizeof(sensor->axis)); //get data from buffer
699 mutex_unlock(&sensor->data_mutex);
707 case GSENSOR_IOCTL_GETDATA:
708 if ( copy_to_user(argp, &axis, sizeof(axis) ) ) {
709 printk("failed to copy sense data to user space.");
713 DBG("%s:GSENSOR_IOCTL_GETDATA OK\n", __func__);
723 static ssize_t gsensor_set_orientation_online(struct class *class,
724 struct class_attribute *attr, const char *buf, size_t count)
727 char orientation[20];
730 struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_ACCEL];
731 struct sensor_platform_data *pdata = sensor->pdata;
734 char *p = strstr(buf,"gsensor_class");
735 int start = strcspn(p,"{");
736 int end = strcspn(p,"}");
738 strncpy(orientation,p+start,end-start+1);
742 while(strncmp(tmp,"}",1)!=0)
744 if((strncmp(tmp,",",1)==0)||(strncmp(tmp,"{",1)==0))
750 else if(strncmp(tmp,"-",1)==0)
752 pdata->orientation[i++]=-1;
753 DBG("i=%d,data=%d\n",i,pdata->orientation[i]);
758 pdata->orientation[i++]=tmp[0]-48;
759 DBG("----i=%d,data=%d\n",i,pdata->orientation[i]);
767 DBG("i=%d gsensor_info=%d\n",i,pdata->orientation[i]);
772 static CLASS_ATTR(orientation, 0660, NULL, gsensor_set_orientation_online);
774 static int gsensor_class_init(void)
777 struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_ACCEL];
778 g_sensor_class[SENSOR_TYPE_ACCEL] = class_create(THIS_MODULE, "gsensor_class");
779 ret = class_create_file(g_sensor_class[SENSOR_TYPE_ACCEL], &class_attr_orientation);
782 printk("%s:Fail to creat class\n",__func__);
785 printk("%s:%s\n",__func__,sensor->i2c_id->name);
791 static int compass_dev_open(struct inode *inode, struct file *file)
793 struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_COMPASS];
794 //struct i2c_client *client = sensor->client;
798 flag = atomic_read(&sensor->flags.open_flag);
801 atomic_set(&sensor->flags.open_flag, 1);
802 wake_up(&sensor->flags.open_wq);
805 DBG("%s\n", __func__);
811 static int compass_dev_release(struct inode *inode, struct file *file)
813 struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_COMPASS];
814 //struct i2c_client *client = sensor->client;
815 //void __user *argp = (void __user *)arg;
818 flag = atomic_read(&sensor->flags.open_flag);
821 atomic_set(&sensor->flags.open_flag, 0);
822 wake_up(&sensor->flags.open_wq);
825 DBG("%s\n", __func__);
830 /* ioctl - I/O control */
831 static long compass_dev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
833 void __user *arg64 = compat_ptr(arg);
836 if (!file->f_op || !file->f_op->unlocked_ioctl) {
837 pr_err("file->f_op or file->f_op->unlocked_ioctl is null\n");
842 case COMPAT_ECS_IOCTL_APP_SET_MFLAG:
843 if (file->f_op->unlocked_ioctl)
844 result = file->f_op->unlocked_ioctl(file, ECS_IOCTL_APP_SET_MFLAG, (unsigned long)arg64);
846 case COMPAT_ECS_IOCTL_APP_GET_MFLAG:
847 if (file->f_op->unlocked_ioctl)
848 result = file->f_op->unlocked_ioctl(file, ECS_IOCTL_APP_GET_MFLAG, (unsigned long)arg64);
850 case COMPAT_ECS_IOCTL_APP_SET_AFLAG:
851 if (file->f_op->unlocked_ioctl)
852 result = file->f_op->unlocked_ioctl(file, ECS_IOCTL_APP_SET_AFLAG, (unsigned long)arg64);
854 case COMPAT_ECS_IOCTL_APP_GET_AFLAG:
855 if (file->f_op->unlocked_ioctl)
856 result = file->f_op->unlocked_ioctl(file, ECS_IOCTL_APP_GET_AFLAG, (unsigned long)arg64);
858 case COMPAT_ECS_IOCTL_APP_SET_MVFLAG:
859 if (file->f_op->unlocked_ioctl)
860 result = file->f_op->unlocked_ioctl(file, ECS_IOCTL_APP_SET_MVFLAG, (unsigned long)arg64);
862 case COMPAT_ECS_IOCTL_APP_GET_MVFLAG:
863 if (file->f_op->unlocked_ioctl)
864 result = file->f_op->unlocked_ioctl(file, ECS_IOCTL_APP_GET_MVFLAG, (unsigned long)arg64);
866 case COMPAT_ECS_IOCTL_APP_SET_DELAY:
867 if (file->f_op->unlocked_ioctl)
868 result = file->f_op->unlocked_ioctl(file, ECS_IOCTL_APP_SET_DELAY, (unsigned long)arg64);
870 case COMPAT_ECS_IOCTL_APP_GET_DELAY:
871 if (file->f_op->unlocked_ioctl)
872 result = file->f_op->unlocked_ioctl(file, ECS_IOCTL_APP_GET_DELAY, (unsigned long)arg64);
883 /* ioctl - I/O control */
884 static long compass_dev_ioctl(struct file *file,
885 unsigned int cmd, unsigned long arg)
887 struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_COMPASS];
888 //struct i2c_client *client = sensor->client;
889 void __user *argp = (void __user *)arg;
894 case ECS_IOCTL_APP_SET_MFLAG:
895 case ECS_IOCTL_APP_SET_AFLAG:
896 case ECS_IOCTL_APP_SET_MVFLAG:
897 if (copy_from_user(&flag, argp, sizeof(flag))) {
900 if (flag < 0 || flag > 1) {
904 case ECS_IOCTL_APP_SET_DELAY:
905 if (copy_from_user(&flag, argp, sizeof(flag))) {
914 case ECS_IOCTL_APP_SET_MFLAG:
915 atomic_set(&sensor->flags.m_flag, flag);
916 DBG("%s:ECS_IOCTL_APP_SET_MFLAG,flag=%d\n", __func__,flag);
918 case ECS_IOCTL_APP_GET_MFLAG:
919 flag = atomic_read(&sensor->flags.m_flag);
920 DBG("%s:ECS_IOCTL_APP_GET_MFLAG,flag=%d\n", __func__,flag);
922 case ECS_IOCTL_APP_SET_AFLAG:
923 atomic_set(&sensor->flags.a_flag, flag);
924 DBG("%s:ECS_IOCTL_APP_SET_AFLAG,flag=%d\n", __func__,flag);
926 case ECS_IOCTL_APP_GET_AFLAG:
927 flag = atomic_read(&sensor->flags.a_flag);
928 DBG("%s:ECS_IOCTL_APP_GET_AFLAG,flag=%d\n", __func__,flag);
930 case ECS_IOCTL_APP_SET_MVFLAG:
931 atomic_set(&sensor->flags.mv_flag, flag);
932 DBG("%s:ECS_IOCTL_APP_SET_MVFLAG,flag=%d\n", __func__,flag);
934 case ECS_IOCTL_APP_GET_MVFLAG:
935 flag = atomic_read(&sensor->flags.mv_flag);
936 DBG("%s:ECS_IOCTL_APP_GET_MVFLAG,flag=%d\n", __func__,flag);
938 case ECS_IOCTL_APP_SET_DELAY:
939 sensor->flags.delay = flag;
941 case ECS_IOCTL_APP_GET_DELAY:
942 flag = sensor->flags.delay;
949 case ECS_IOCTL_APP_GET_MFLAG:
950 case ECS_IOCTL_APP_GET_AFLAG:
951 case ECS_IOCTL_APP_GET_MVFLAG:
952 case ECS_IOCTL_APP_GET_DELAY:
953 if (copy_to_user(argp, &flag, sizeof(flag))) {
964 static int gyro_dev_open(struct inode *inode, struct file *file)
966 //struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_GYROSCOPE];
967 //struct i2c_client *client = sensor->client;
976 static int gyro_dev_release(struct inode *inode, struct file *file)
978 //struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_GYROSCOPE];
979 //struct i2c_client *client = sensor->client;
988 /* ioctl - I/O control */
989 static long gyro_dev_ioctl(struct file *file,
990 unsigned int cmd, unsigned long arg)
992 struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_GYROSCOPE];
993 struct i2c_client *client = sensor->client;
994 void __user *argp = (void __user *)arg;
998 case L3G4200D_IOCTL_GET_ENABLE:
999 result = !sensor->status_cur;
1000 if (copy_to_user(argp, &result, sizeof(result)))
1002 printk("%s:failed to copy status to user space.\n",__FUNCTION__);
1006 DBG("%s :L3G4200D_IOCTL_GET_ENABLE,status=%d\n",__FUNCTION__,result);
1008 case L3G4200D_IOCTL_SET_ENABLE:
1009 DBG("%s :L3G4200D_IOCTL_SET_ENABLE,flag=%d\n",__FUNCTION__,*(unsigned int *)argp);
1010 mutex_lock(&sensor->operation_mutex);
1011 if(*(unsigned int *)argp)
1013 if(sensor->status_cur == SENSOR_OFF)
1015 if ( (result = sensor->ops->active(client, 1, ODR100_BW12_5) ) < 0 ) {
1016 mutex_unlock(&sensor->operation_mutex);
1017 printk("%s:fail to active sensor,ret=%d\n",__func__,result);
1020 if(sensor->pdata->irq_enable)
1022 DBG("%s:enable irq,irq=%d\n",__func__,client->irq);
1023 enable_irq(client->irq); //enable irq
1027 schedule_delayed_work(&sensor->delaywork, msecs_to_jiffies(sensor->pdata->poll_delay_ms));
1029 sensor->status_cur = SENSOR_ON;
1034 if(sensor->status_cur == SENSOR_ON)
1036 if ( (result = sensor->ops->active(client, 0, 0) ) < 0 ) {
1037 mutex_unlock(&sensor->operation_mutex);
1041 if(sensor->pdata->irq_enable)
1043 DBG("%s:disable irq,irq=%d\n",__func__,client->irq);
1044 disable_irq_nosync(client->irq);//disable irq
1047 cancel_delayed_work_sync(&sensor->delaywork);
1048 sensor->status_cur = SENSOR_OFF;
1052 result = sensor->status_cur;
1053 if (copy_to_user(argp, &result, sizeof(result)))
1055 mutex_unlock(&sensor->operation_mutex);
1056 printk("%s:failed to copy sense data to user space.\n",__FUNCTION__);
1060 mutex_unlock(&sensor->operation_mutex);
1061 DBG("%s:L3G4200D_IOCTL_SET_ENABLE OK\n", __func__);
1063 case L3G4200D_IOCTL_SET_DELAY:
1064 if (copy_from_user(&rate, argp, sizeof(rate)))
1066 mutex_lock(&sensor->operation_mutex);
1067 if(sensor->status_cur == SENSOR_OFF)
1069 if ( (result = sensor->ops->active(client, 1, rate) ) < 0 ) {
1070 mutex_unlock(&sensor->operation_mutex);
1071 printk("%s:fail to active sensor,ret=%d\n",__func__,result);
1075 if(sensor->pdata->irq_enable)
1077 DBG("%s:enable irq,irq=%d\n",__func__,client->irq);
1078 enable_irq(client->irq); //enable irq
1082 schedule_delayed_work(&sensor->delaywork, msecs_to_jiffies(sensor->pdata->poll_delay_ms));
1084 sensor->status_cur = SENSOR_ON;
1087 mutex_unlock(&sensor->operation_mutex);
1088 DBG("%s :L3G4200D_IOCTL_SET_DELAY,rate=%d\n",__FUNCTION__,rate);
1092 printk("%s:error,cmd=0x%x\n",__func__,cmd);
1096 DBG("%s:line=%d,cmd=0x%x\n",__func__,__LINE__,cmd);
1102 static int light_dev_open(struct inode *inode, struct file *file)
1104 //struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_LIGHT];
1105 //struct i2c_client *client = sensor->client;
1115 static int light_dev_release(struct inode *inode, struct file *file)
1117 //struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_LIGHT];
1118 //struct i2c_client *client = sensor->client;
1125 #ifdef CONFIG_COMPAT
1126 static long light_dev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1129 void __user *arg64 = compat_ptr(arg);
1131 if (!file->f_op || !file->f_op->unlocked_ioctl) {
1132 pr_err("[DEBUG] file->f_op or file->f_op->unlocked_ioctl is null\n");
1137 case COMPAT_LIGHTSENSOR_IOCTL_GET_ENABLED:
1138 if (file->f_op->unlocked_ioctl)
1139 ret = file->f_op->unlocked_ioctl(file, LIGHTSENSOR_IOCTL_GET_ENABLED, (unsigned long)arg64);
1141 case COMPAT_LIGHTSENSOR_IOCTL_ENABLE:
1142 if (file->f_op->unlocked_ioctl)
1143 ret = file->f_op->unlocked_ioctl(file, LIGHTSENSOR_IOCTL_ENABLE, (unsigned long)arg64);
1153 /* ioctl - I/O control */
1154 static long light_dev_ioctl(struct file *file,
1155 unsigned int cmd, unsigned long arg)
1157 struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_LIGHT];
1158 struct i2c_client *client = sensor->client;
1159 unsigned int *argp = (unsigned int *)arg;
1164 case LIGHTSENSOR_IOCTL_GET_ENABLED:
1165 *argp = sensor->status_cur;
1167 case LIGHTSENSOR_IOCTL_ENABLE:
1168 DBG("%s:LIGHTSENSOR_IOCTL_ENABLE start\n", __func__);
1169 mutex_lock(&sensor->operation_mutex);
1170 if(*(unsigned int *)argp)
1172 if(sensor->status_cur == SENSOR_OFF)
1174 if ( (result = sensor->ops->active(client, SENSOR_ON, 0) ) < 0 ) {
1175 mutex_unlock(&sensor->operation_mutex);
1176 printk("%s:fail to active sensor,ret=%d\n",__func__,result);
1179 if(sensor->pdata->irq_enable)
1181 if(!(sensor->ops->trig & IRQF_SHARED))
1183 DBG("%s:enable irq,irq=%d\n",__func__,client->irq);
1184 enable_irq(client->irq); //enable irq
1189 schedule_delayed_work(&sensor->delaywork, msecs_to_jiffies(sensor->pdata->poll_delay_ms));
1192 sensor->status_cur = SENSOR_ON;
1197 if(sensor->status_cur == SENSOR_ON)
1199 if ( (result = sensor->ops->active(client, SENSOR_OFF, 0) ) < 0 ) {
1200 mutex_unlock(&sensor->operation_mutex);
1204 if(sensor->pdata->irq_enable)
1206 if(!(sensor->ops->trig & IRQF_SHARED))
1208 DBG("%s:disable irq,irq=%d\n",__func__,client->irq);
1209 disable_irq_nosync(client->irq);//disable irq
1213 cancel_delayed_work_sync(&sensor->delaywork);
1215 sensor->status_cur = SENSOR_OFF;
1218 mutex_unlock(&sensor->operation_mutex);
1219 DBG("%s:LIGHTSENSOR_IOCTL_ENABLE OK\n", __func__);
1231 static int proximity_dev_open(struct inode *inode, struct file *file)
1233 //struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_PROXIMITY];
1234 //struct i2c_client *client = sensor->client;
1242 static int proximity_dev_release(struct inode *inode, struct file *file)
1244 //struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_PROXIMITY];
1245 //struct i2c_client *client = sensor->client;
1252 #ifdef CONFIG_COMPAT
1253 static long proximity_dev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1256 void __user *arg64 = compat_ptr(arg);
1258 if (!file->f_op || !file->f_op->unlocked_ioctl) {
1259 pr_err("file->f_op or file->f_op->unlocked_ioctl is null\n");
1264 case COMPAT_PSENSOR_IOCTL_GET_ENABLED:
1265 if (file->f_op->unlocked_ioctl)
1266 ret = file->f_op->unlocked_ioctl(file, PSENSOR_IOCTL_GET_ENABLED, (unsigned long)arg64);
1268 case COMPAT_PSENSOR_IOCTL_ENABLE:
1269 if (file->f_op->unlocked_ioctl)
1270 ret = file->f_op->unlocked_ioctl(file, PSENSOR_IOCTL_ENABLE, (unsigned long)arg64);
1280 /* ioctl - I/O control */
1281 static long proximity_dev_ioctl(struct file *file,
1282 unsigned int cmd, unsigned long arg)
1284 struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_PROXIMITY];
1285 struct i2c_client *client = sensor->client;
1286 unsigned int *argp = (unsigned int *)arg;
1290 case PSENSOR_IOCTL_GET_ENABLED:
1291 *argp = sensor->status_cur;
1293 case PSENSOR_IOCTL_ENABLE:
1294 DBG("%s:PSENSOR_IOCTL_ENABLE start\n", __func__);
1295 mutex_lock(&sensor->operation_mutex);
1296 if(*(unsigned int *)argp)
1298 if(sensor->status_cur == SENSOR_OFF)
1300 if ( (result = sensor->ops->active(client, SENSOR_ON, 0) ) < 0 ) {
1301 mutex_unlock(&sensor->operation_mutex);
1302 printk("%s:fail to active sensor,ret=%d\n",__func__,result);
1306 if(sensor->pdata->irq_enable)
1308 if(!(sensor->ops->trig & IRQF_SHARED))
1310 DBG("%s:enable irq,irq=%d\n",__func__,client->irq);
1311 enable_irq(client->irq); //enable irq
1316 schedule_delayed_work(&sensor->delaywork, msecs_to_jiffies(sensor->pdata->poll_delay_ms));
1319 sensor->status_cur = SENSOR_ON;
1324 if(sensor->status_cur == SENSOR_ON)
1326 if ( (result = sensor->ops->active(client, SENSOR_OFF, 0) ) < 0 ) {
1327 mutex_unlock(&sensor->operation_mutex);
1330 if(sensor->pdata->irq_enable)
1332 if(!(sensor->ops->trig & IRQF_SHARED))
1334 DBG("%s:disable irq,irq=%d\n",__func__,client->irq);
1335 disable_irq_nosync(client->irq);//disable irq
1339 cancel_delayed_work_sync(&sensor->delaywork);
1340 sensor->status_cur = SENSOR_OFF;
1343 mutex_unlock(&sensor->operation_mutex);
1344 DBG("%s:PSENSOR_IOCTL_ENABLE OK\n", __func__);
1355 static int temperature_dev_open(struct inode *inode, struct file *file)
1357 //struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_TEMPERATURE];
1358 //struct i2c_client *client = sensor->client;
1367 static int temperature_dev_release(struct inode *inode, struct file *file)
1369 //struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_TEMPERATURE];
1370 //struct i2c_client *client = sensor->client;
1379 /* ioctl - I/O control */
1380 static long temperature_dev_ioctl(struct file *file,
1381 unsigned int cmd, unsigned long arg)
1383 struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_TEMPERATURE];
1384 struct i2c_client *client = sensor->client;
1385 unsigned int *argp = (unsigned int *)arg;
1390 case TEMPERATURE_IOCTL_GET_ENABLED:
1391 *argp = sensor->status_cur;
1393 case TEMPERATURE_IOCTL_ENABLE:
1394 DBG("%s:LIGHTSENSOR_IOCTL_ENABLE start\n", __func__);
1395 mutex_lock(&sensor->operation_mutex);
1396 if(*(unsigned int *)argp)
1398 if(sensor->status_cur == SENSOR_OFF)
1400 if ( (result = sensor->ops->active(client, SENSOR_ON, 0) ) < 0 ) {
1401 mutex_unlock(&sensor->operation_mutex);
1402 printk("%s:fail to active sensor,ret=%d\n",__func__,result);
1405 if(sensor->pdata->irq_enable)
1407 if(!(sensor->ops->trig & IRQF_SHARED))
1409 DBG("%s:enable irq,irq=%d\n",__func__,client->irq);
1410 enable_irq(client->irq); //enable irq
1415 schedule_delayed_work(&sensor->delaywork, msecs_to_jiffies(sensor->pdata->poll_delay_ms));
1418 sensor->status_cur = SENSOR_ON;
1423 if(sensor->status_cur == SENSOR_ON)
1425 if ( (result = sensor->ops->active(client, SENSOR_OFF, 0) ) < 0 ) {
1426 mutex_unlock(&sensor->operation_mutex);
1430 if(sensor->pdata->irq_enable)
1432 if(!(sensor->ops->trig & IRQF_SHARED))
1434 DBG("%s:disable irq,irq=%d\n",__func__,client->irq);
1435 disable_irq_nosync(client->irq);//disable irq
1439 cancel_delayed_work_sync(&sensor->delaywork);
1441 sensor->status_cur = SENSOR_OFF;
1444 mutex_unlock(&sensor->operation_mutex);
1445 DBG("%s:LIGHTSENSOR_IOCTL_ENABLE OK\n", __func__);
1457 static int pressure_dev_open(struct inode *inode, struct file *file)
1459 //struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_PRESSURE];
1460 //struct i2c_client *client = sensor->client;
1469 static int pressure_dev_release(struct inode *inode, struct file *file)
1471 //struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_PRESSURE];
1472 //struct i2c_client *client = sensor->client;
1481 /* ioctl - I/O control */
1482 static long pressure_dev_ioctl(struct file *file,
1483 unsigned int cmd, unsigned long arg)
1485 struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_PRESSURE];
1486 struct i2c_client *client = sensor->client;
1487 unsigned int *argp = (unsigned int *)arg;
1492 case PRESSURE_IOCTL_GET_ENABLED:
1493 *argp = sensor->status_cur;
1495 case PRESSURE_IOCTL_ENABLE:
1496 DBG("%s:LIGHTSENSOR_IOCTL_ENABLE start\n", __func__);
1497 mutex_lock(&sensor->operation_mutex);
1498 if(*(unsigned int *)argp)
1500 if(sensor->status_cur == SENSOR_OFF)
1502 if ( (result = sensor->ops->active(client, SENSOR_ON, 0) ) < 0 ) {
1503 mutex_unlock(&sensor->operation_mutex);
1504 printk("%s:fail to active sensor,ret=%d\n",__func__,result);
1507 if(sensor->pdata->irq_enable)
1509 if(!(sensor->ops->trig & IRQF_SHARED))
1511 DBG("%s:enable irq,irq=%d\n",__func__,client->irq);
1512 enable_irq(client->irq); //enable irq
1517 schedule_delayed_work(&sensor->delaywork, msecs_to_jiffies(sensor->pdata->poll_delay_ms));
1520 sensor->status_cur = SENSOR_ON;
1525 if(sensor->status_cur == SENSOR_ON)
1527 if ( (result = sensor->ops->active(client, SENSOR_OFF, 0) ) < 0 ) {
1528 mutex_unlock(&sensor->operation_mutex);
1532 if(sensor->pdata->irq_enable)
1534 if(!(sensor->ops->trig & IRQF_SHARED))
1536 DBG("%s:disable irq,irq=%d\n",__func__,client->irq);
1537 disable_irq_nosync(client->irq);//disable irq
1541 cancel_delayed_work_sync(&sensor->delaywork);
1543 sensor->status_cur = SENSOR_OFF;
1546 mutex_unlock(&sensor->operation_mutex);
1547 DBG("%s:LIGHTSENSOR_IOCTL_ENABLE OK\n", __func__);
1561 static int sensor_misc_device_register(struct sensor_private_data *sensor, int type)
1567 case SENSOR_TYPE_ANGLE:
1568 if(!sensor->ops->misc_dev)
1570 sensor->fops.owner = THIS_MODULE;
1571 sensor->fops.unlocked_ioctl = angle_dev_ioctl;
1572 sensor->fops.open = angle_dev_open;
1573 sensor->fops.release = angle_dev_release;
1575 sensor->miscdev.minor = MISC_DYNAMIC_MINOR;
1576 sensor->miscdev.name = "angle";
1577 sensor->miscdev.fops = &sensor->fops;
1581 memcpy(&sensor->miscdev, sensor->ops->misc_dev, sizeof(*sensor->ops->misc_dev));
1587 case SENSOR_TYPE_ACCEL:
1588 if(!sensor->ops->misc_dev)
1590 sensor->fops.owner = THIS_MODULE;
1591 sensor->fops.unlocked_ioctl = gsensor_dev_ioctl;
1592 #ifdef CONFIG_COMPAT
1593 sensor->fops.compat_ioctl = gsensor_dev_ioctl;
1595 sensor->fops.open = gsensor_dev_open;
1596 sensor->fops.release = gsensor_dev_release;
1598 sensor->miscdev.minor = MISC_DYNAMIC_MINOR;
1599 sensor->miscdev.name = "mma8452_daemon";
1600 sensor->miscdev.fops = &sensor->fops;
1604 memcpy(&sensor->miscdev, sensor->ops->misc_dev, sizeof(*sensor->ops->misc_dev));
1610 case SENSOR_TYPE_COMPASS:
1611 if(!sensor->ops->misc_dev)
1613 sensor->fops.owner = THIS_MODULE;
1614 sensor->fops.unlocked_ioctl = compass_dev_ioctl;
1615 #ifdef CONFIG_COMPAT
1616 sensor->fops.compat_ioctl = compass_dev_compat_ioctl;
1618 sensor->fops.open = compass_dev_open;
1619 sensor->fops.release = compass_dev_release;
1621 sensor->miscdev.minor = MISC_DYNAMIC_MINOR;
1622 sensor->miscdev.name = "compass";
1623 sensor->miscdev.fops = &sensor->fops;
1627 memcpy(&sensor->miscdev, sensor->ops->misc_dev, sizeof(*sensor->ops->misc_dev));
1633 case SENSOR_TYPE_GYROSCOPE:
1634 if(!sensor->ops->misc_dev)
1636 sensor->fops.owner = THIS_MODULE;
1637 sensor->fops.unlocked_ioctl = gyro_dev_ioctl;
1638 sensor->fops.open = gyro_dev_open;
1639 sensor->fops.release = gyro_dev_release;
1641 sensor->miscdev.minor = MISC_DYNAMIC_MINOR;
1642 sensor->miscdev.name = "gyrosensor";
1643 sensor->miscdev.fops = &sensor->fops;
1647 memcpy(&sensor->miscdev, sensor->ops->misc_dev, sizeof(*sensor->ops->misc_dev));
1653 case SENSOR_TYPE_LIGHT:
1654 if(!sensor->ops->misc_dev)
1656 sensor->fops.owner = THIS_MODULE;
1657 sensor->fops.unlocked_ioctl = light_dev_ioctl;
1658 #ifdef CONFIG_COMPAT
1659 sensor->fops.compat_ioctl = light_dev_compat_ioctl;
1661 sensor->fops.open = light_dev_open;
1662 sensor->fops.release = light_dev_release;
1664 sensor->miscdev.minor = MISC_DYNAMIC_MINOR;
1665 sensor->miscdev.name = "lightsensor";
1666 sensor->miscdev.fops = &sensor->fops;
1670 memcpy(&sensor->miscdev, sensor->ops->misc_dev, sizeof(*sensor->ops->misc_dev));
1675 case SENSOR_TYPE_PROXIMITY:
1676 if(!sensor->ops->misc_dev)
1678 sensor->fops.owner = THIS_MODULE;
1679 sensor->fops.unlocked_ioctl = proximity_dev_ioctl;
1680 #ifdef CONFIG_COMPAT
1681 sensor->fops.compat_ioctl = proximity_dev_compat_ioctl;
1683 sensor->fops.open = proximity_dev_open;
1684 sensor->fops.release = proximity_dev_release;
1686 sensor->miscdev.minor = MISC_DYNAMIC_MINOR;
1687 sensor->miscdev.name = "psensor";
1688 sensor->miscdev.fops = &sensor->fops;
1692 memcpy(&sensor->miscdev, sensor->ops->misc_dev, sizeof(*sensor->ops->misc_dev));
1697 case SENSOR_TYPE_TEMPERATURE:
1698 if(!sensor->ops->misc_dev)
1700 sensor->fops.owner = THIS_MODULE;
1701 sensor->fops.unlocked_ioctl = temperature_dev_ioctl;
1702 sensor->fops.open = temperature_dev_open;
1703 sensor->fops.release = temperature_dev_release;
1705 sensor->miscdev.minor = MISC_DYNAMIC_MINOR;
1706 sensor->miscdev.name = "temperature";
1707 sensor->miscdev.fops = &sensor->fops;
1711 memcpy(&sensor->miscdev, sensor->ops->misc_dev, sizeof(*sensor->ops->misc_dev));
1717 case SENSOR_TYPE_PRESSURE:
1718 if(!sensor->ops->misc_dev)
1720 sensor->fops.owner = THIS_MODULE;
1721 sensor->fops.unlocked_ioctl = pressure_dev_ioctl;
1722 sensor->fops.open = pressure_dev_open;
1723 sensor->fops.release = pressure_dev_release;
1725 sensor->miscdev.minor = MISC_DYNAMIC_MINOR;
1726 sensor->miscdev.name = "pressure";
1727 sensor->miscdev.fops = &sensor->fops;
1731 memcpy(&sensor->miscdev, sensor->ops->misc_dev, sizeof(*sensor->ops->misc_dev));
1738 printk("%s:unknow sensor type=%d\n",__func__,type);
1743 sensor->miscdev.parent = &sensor->client->dev;
1744 result = misc_register(&sensor->miscdev);
1746 dev_err(&sensor->client->dev,
1747 "fail to register misc device %s\n", sensor->miscdev.name);
1751 printk("%s:miscdevice: %s\n",__func__,sensor->miscdev.name);
1759 int sensor_register_slave(int type,struct i2c_client *client,
1760 struct sensor_platform_data *slave_pdata,
1761 struct sensor_operate *(*get_sensor_ops)(void))
1764 struct sensor_operate *ops = get_sensor_ops();
1765 if((ops->id_i2c >= SENSOR_NUM_ID) || (ops->id_i2c <= ID_INVALID))
1767 printk("%s:%s id is error %d\n", __func__, ops->name, ops->id_i2c);
1770 sensor_ops[ops->id_i2c] = ops;
1771 printk("%s:%s,id=%d\n",__func__,sensor_ops[ops->id_i2c]->name, ops->id_i2c);
1776 int sensor_unregister_slave(int type,struct i2c_client *client,
1777 struct sensor_platform_data *slave_pdata,
1778 struct sensor_operate *(*get_sensor_ops)(void))
1781 struct sensor_operate *ops = get_sensor_ops();
1782 if((ops->id_i2c >= SENSOR_NUM_ID) || (ops->id_i2c <= ID_INVALID))
1784 printk("%s:%s id is error %d\n", __func__, ops->name, ops->id_i2c);
1787 printk("%s:%s,id=%d\n",__func__,sensor_ops[ops->id_i2c]->name, ops->id_i2c);
1788 sensor_ops[ops->id_i2c] = NULL;
1793 int sensor_probe(struct i2c_client *client, const struct i2c_device_id *devid)
1795 struct sensor_private_data *sensor =
1796 (struct sensor_private_data *) i2c_get_clientdata(client);
1797 struct sensor_platform_data *pdata;
1798 struct device_node *np = client->dev.of_node;
1799 enum of_gpio_flags rst_flags, pwr_flags;
1800 unsigned long irq_flags;
1804 dev_info(&client->adapter->dev, "%s: %s,%p\n", __func__, devid->name, client);
1806 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1811 dev_err(&client->dev, "no device tree\n");
1814 pdata = devm_kzalloc(&client->dev,sizeof(*pdata), GFP_KERNEL);
1819 sensor = devm_kzalloc(&client->dev,sizeof(*sensor), GFP_KERNEL);
1825 of_property_read_u32(np,"type",&(pdata->type));
1827 pdata->irq_pin = of_get_named_gpio_flags(np, "irq-gpio", 0,(enum of_gpio_flags *)&irq_flags);
1828 pdata->reset_pin = of_get_named_gpio_flags(np, "reset-gpio",0,&rst_flags);
1829 pdata->power_pin = of_get_named_gpio_flags(np, "power-gpio",0,&pwr_flags);
1831 of_property_read_u32(np,"irq_enable",&(pdata->irq_enable));
1832 of_property_read_u32(np,"poll_delay_ms",&(pdata->poll_delay_ms));
1834 of_property_read_u32(np,"x_min",&(pdata->x_min));
1835 of_property_read_u32(np,"y_min",&(pdata->y_min));
1836 of_property_read_u32(np,"z_min",&(pdata->z_min));
1837 of_property_read_u32(np,"factory",&(pdata->factory));
1838 of_property_read_u32(np,"layout",&(pdata->layout));
1840 of_property_read_u8(np,"address",&(pdata->address));
1841 of_get_property(np, "project_name", pdata->project_name);
1843 of_property_read_u32(np, "power-off-in-suspend",
1844 &pdata->power_off_in_suspend);
1846 switch(pdata->layout)
1849 pdata->orientation[0] = 1;
1850 pdata->orientation[1] = 0;
1851 pdata->orientation[2] = 0;
1853 pdata->orientation[3] = 0;
1854 pdata->orientation[4] = 1;
1855 pdata->orientation[5] = 0;
1857 pdata->orientation[6] = 0;
1858 pdata->orientation[7] = 0;
1859 pdata->orientation[8] = 1;
1863 pdata->orientation[0] = 0;
1864 pdata->orientation[1] = -1;
1865 pdata->orientation[2] = 0;
1867 pdata->orientation[3] = 1;
1868 pdata->orientation[4] = 0;
1869 pdata->orientation[5] = 0;
1871 pdata->orientation[6] = 0;
1872 pdata->orientation[7] = 0;
1873 pdata->orientation[8] = 1;
1877 pdata->orientation[0] = -1;
1878 pdata->orientation[1] = 0;
1879 pdata->orientation[2] = 0;
1881 pdata->orientation[3] = 0;
1882 pdata->orientation[4] = -1;
1883 pdata->orientation[5] = 0;
1885 pdata->orientation[6] = 0;
1886 pdata->orientation[7] = 0;
1887 pdata->orientation[8] = 1;
1891 pdata->orientation[0] = 0;
1892 pdata->orientation[1] = 1;
1893 pdata->orientation[2] = 0;
1895 pdata->orientation[3] = -1;
1896 pdata->orientation[4] = 0;
1897 pdata->orientation[5] = 0;
1899 pdata->orientation[6] = 0;
1900 pdata->orientation[7] = 0;
1901 pdata->orientation[8] = 1;
1905 pdata->orientation[0] = 1;
1906 pdata->orientation[1] = 0;
1907 pdata->orientation[2] = 0;
1909 pdata->orientation[3] = 0;
1910 pdata->orientation[4] = -1;
1911 pdata->orientation[5] = 0;
1913 pdata->orientation[6] = 0;
1914 pdata->orientation[7] = 0;
1915 pdata->orientation[8] = -1;
1919 pdata->orientation[0] = 0;
1920 pdata->orientation[1] = -1;
1921 pdata->orientation[2] = 0;
1923 pdata->orientation[3] = -1;
1924 pdata->orientation[4] = 0;
1925 pdata->orientation[5] = 0;
1927 pdata->orientation[6] = 0;
1928 pdata->orientation[7] = 0;
1929 pdata->orientation[8] = -1;
1933 pdata->orientation[0] = -1;
1934 pdata->orientation[1] = 0;
1935 pdata->orientation[2] = 0;
1937 pdata->orientation[3] = 0;
1938 pdata->orientation[4] = 1;
1939 pdata->orientation[5] = 0;
1941 pdata->orientation[6] = 0;
1942 pdata->orientation[7] = 0;
1943 pdata->orientation[8] = -1;
1947 pdata->orientation[0] = 0;
1948 pdata->orientation[1] = 1;
1949 pdata->orientation[2] = 0;
1951 pdata->orientation[3] = 1;
1952 pdata->orientation[4] = 0;
1953 pdata->orientation[5] = 0;
1955 pdata->orientation[6] = 0;
1956 pdata->orientation[7] = 0;
1957 pdata->orientation[8] = -1;
1961 pdata->orientation[0] = 1;
1962 pdata->orientation[1] = 0;
1963 pdata->orientation[2] = 0;
1965 pdata->orientation[3] = 0;
1966 pdata->orientation[4] = 1;
1967 pdata->orientation[5] = 0;
1969 pdata->orientation[6] = 0;
1970 pdata->orientation[7] = 0;
1971 pdata->orientation[8] = 1;
1975 client->irq = pdata->irq_pin;
1977 pdata->irq_flags = irq_flags;
1978 DBG("irq_flags = %lu padta->irq_flags = %lu\n",irq_flags, pdata->irq_flags);
1979 DBG("type = %d \n",pdata->type);
1980 DBG("irq = %d \n",pdata->irq);
1981 DBG("irq_pin = %d \n",pdata->irq_pin);
1982 DBG("pwer_pin = %d \n",pdata->power_pin);
1983 DBG("reset_pin = %d \n",pdata->reset_pin);
1984 DBG("irq_enable = %d \n",pdata->irq_enable);
1986 DBG("poll_delay_ms = %d \n",pdata->poll_delay_ms);
1987 DBG("x_min = %d \n",pdata->x_min);
1988 DBG("y_min = %d \n",pdata->y_min);
1989 DBG("z_min = %d \n",pdata->z_min);
1990 DBG("factory = %d \n",pdata->factory);
1991 DBG("layout = %d \n",pdata->layout);
1992 DBG("address = 0x%x \n",pdata->address);
1993 DBG("project_name = [%s] \n",pdata->project_name);
1995 DBG(" == %d,%d ,%d \t ,%d ,%d ,%d , \t ,%d, %d, %d ,==%d\n",pdata->orientation[0],pdata->orientation[1],pdata->orientation[2]
1996 ,pdata->orientation[3],pdata->orientation[4],pdata->orientation[5]
1997 ,pdata->orientation[6],pdata->orientation[7],pdata->orientation[8],ARRAY_SIZE(pdata->orientation));
2000 if((type >= SENSOR_NUM_TYPES) || (type <= SENSOR_TYPE_NULL))
2002 dev_err(&client->adapter->dev, "sensor type is error %d\n", type);
2006 if(((int)devid->driver_data >= SENSOR_NUM_ID) || ((int)devid->driver_data <= ID_INVALID))
2008 dev_err(&client->adapter->dev, "sensor id is error %d\n", (int)devid->driver_data);
2012 i2c_set_clientdata(client, sensor);
2013 sensor->client = client;
2014 sensor->pdata = pdata;
2015 sensor->type = type;
2016 sensor->i2c_id = (struct i2c_device_id *)devid;
2019 memset(&(sensor->axis), 0, sizeof(struct sensor_axis) );
2020 atomic_set(&(sensor->data_ready), 0);
2021 init_waitqueue_head(&(sensor->data_ready_wq));
2022 mutex_init(&sensor->data_mutex);
2023 mutex_init(&sensor->operation_mutex);
2024 mutex_init(&sensor->sensor_mutex);
2025 mutex_init(&sensor->i2c_mutex);
2027 /* As default, report all information */
2028 atomic_set(&sensor->flags.m_flag, 1);
2029 atomic_set(&sensor->flags.a_flag, 1);
2030 atomic_set(&sensor->flags.mv_flag, 1);
2031 atomic_set(&sensor->flags.open_flag, 0);
2032 atomic_set(&sensor->flags.debug_flag, 1);
2033 init_waitqueue_head(&sensor->flags.open_wq);
2034 sensor->flags.delay = 100;
2036 sensor->status_cur = SENSOR_OFF;
2041 result = sensor_chip_init(sensor->client);
2043 goto out_free_memory;
2045 sensor->input_dev = devm_input_allocate_device(&client->dev);
2046 if (!sensor->input_dev) {
2048 dev_err(&client->dev,
2049 "Failed to allocate input device\n");
2050 goto out_free_memory;
2055 case SENSOR_TYPE_ANGLE:
2056 sensor->input_dev->name = "angle";
2057 set_bit(EV_ABS, sensor->input_dev->evbit);
2058 /* x-axis acceleration */
2059 input_set_abs_params(sensor->input_dev, ABS_X, sensor->ops->range[0], sensor->ops->range[1], 0, 0); //2g full scale range
2060 /* y-axis acceleration */
2061 input_set_abs_params(sensor->input_dev, ABS_Y, sensor->ops->range[0], sensor->ops->range[1], 0, 0); //2g full scale range
2062 /* z-axis acceleration */
2063 input_set_abs_params(sensor->input_dev, ABS_Z, sensor->ops->range[0], sensor->ops->range[1], 0, 0); //2g full scale range
2066 case SENSOR_TYPE_ACCEL:
2067 sensor->input_dev->name = "gsensor";
2068 set_bit(EV_ABS, sensor->input_dev->evbit);
2069 /* x-axis acceleration */
2070 input_set_abs_params(sensor->input_dev, ABS_X, sensor->ops->range[0], sensor->ops->range[1], 0, 0); //2g full scale range
2071 /* y-axis acceleration */
2072 input_set_abs_params(sensor->input_dev, ABS_Y, sensor->ops->range[0], sensor->ops->range[1], 0, 0); //2g full scale range
2073 /* z-axis acceleration */
2074 input_set_abs_params(sensor->input_dev, ABS_Z, sensor->ops->range[0], sensor->ops->range[1], 0, 0); //2g full scale range
2076 case SENSOR_TYPE_COMPASS:
2077 sensor->input_dev->name = "compass";
2078 /* Setup input device */
2079 set_bit(EV_ABS, sensor->input_dev->evbit);
2081 input_set_abs_params(sensor->input_dev, ABS_RX, 0, 23040, 0, 0);
2082 /* pitch (-180, 180) */
2083 input_set_abs_params(sensor->input_dev, ABS_RY, -11520, 11520, 0, 0);
2084 /* roll (-90, 90) */
2085 input_set_abs_params(sensor->input_dev, ABS_RZ, -5760, 5760, 0, 0);
2086 /* x-axis acceleration (720 x 8G) */
2087 input_set_abs_params(sensor->input_dev, ABS_X, -5760, 5760, 0, 0);
2088 /* y-axis acceleration (720 x 8G) */
2089 input_set_abs_params(sensor->input_dev, ABS_Y, -5760, 5760, 0, 0);
2090 /* z-axis acceleration (720 x 8G) */
2091 input_set_abs_params(sensor->input_dev, ABS_Z, -5760, 5760, 0, 0);
2092 /* status of magnetic sensor */
2093 input_set_abs_params(sensor->input_dev, ABS_RUDDER, -32768, 3, 0, 0);
2094 /* status of acceleration sensor */
2095 input_set_abs_params(sensor->input_dev, ABS_WHEEL, -32768, 3, 0, 0);
2096 /* x-axis of raw magnetic vector (-4096, 4095) */
2097 input_set_abs_params(sensor->input_dev, ABS_HAT0X, -20480, 20479, 0, 0);
2098 /* y-axis of raw magnetic vector (-4096, 4095) */
2099 input_set_abs_params(sensor->input_dev, ABS_HAT0Y, -20480, 20479, 0, 0);
2100 /* z-axis of raw magnetic vector (-4096, 4095) */
2101 input_set_abs_params(sensor->input_dev, ABS_BRAKE, -20480, 20479, 0, 0);
2103 case SENSOR_TYPE_GYROSCOPE:
2104 sensor->input_dev->name = "gyro";
2105 /* x-axis acceleration */
2106 input_set_capability(sensor->input_dev, EV_REL, REL_RX);
2107 input_set_abs_params(sensor->input_dev, ABS_RX, sensor->ops->range[0], sensor->ops->range[1], 0, 0);
2108 /* y-axis acceleration */
2109 input_set_capability(sensor->input_dev, EV_REL, REL_RY);
2110 input_set_abs_params(sensor->input_dev, ABS_RY, sensor->ops->range[0], sensor->ops->range[1], 0, 0);
2111 /* z-axis acceleration */
2112 input_set_capability(sensor->input_dev, EV_REL, REL_RZ);
2113 input_set_abs_params(sensor->input_dev, ABS_RZ, sensor->ops->range[0], sensor->ops->range[1], 0, 0);
2115 case SENSOR_TYPE_LIGHT:
2116 sensor->input_dev->name = "lightsensor-level";
2117 set_bit(EV_ABS, sensor->input_dev->evbit);
2118 input_set_abs_params(sensor->input_dev, ABS_MISC, sensor->ops->range[0], sensor->ops->range[1], 0, 0);
2119 input_set_abs_params(sensor->input_dev, ABS_TOOL_WIDTH , sensor->ops->brightness[0],sensor->ops->brightness[1], 0, 0);
2121 case SENSOR_TYPE_PROXIMITY:
2122 sensor->input_dev->name = "proximity";
2123 set_bit(EV_ABS, sensor->input_dev->evbit);
2124 input_set_abs_params(sensor->input_dev, ABS_DISTANCE, sensor->ops->range[0], sensor->ops->range[1], 0, 0);
2126 case SENSOR_TYPE_TEMPERATURE:
2127 sensor->input_dev->name = "temperature";
2128 set_bit(EV_ABS, sensor->input_dev->evbit);
2129 input_set_abs_params(sensor->input_dev, ABS_THROTTLE, sensor->ops->range[0], sensor->ops->range[1], 0, 0);
2131 case SENSOR_TYPE_PRESSURE:
2132 sensor->input_dev->name = "pressure";
2133 set_bit(EV_ABS, sensor->input_dev->evbit);
2134 input_set_abs_params(sensor->input_dev, ABS_PRESSURE, sensor->ops->range[0], sensor->ops->range[1], 0, 0);
2137 printk("%s:unknow sensor type=%d\n",__func__,type);
2141 sensor->input_dev->dev.parent = &client->dev;
2143 result = input_register_device(sensor->input_dev);
2145 dev_err(&client->dev,
2146 "Unable to register input device %s\n", sensor->input_dev->name);
2147 goto out_input_register_device_failed;
2150 result = sensor_irq_init(sensor->client);
2152 dev_err(&client->dev,
2153 "fail to init sensor irq,ret=%d\n",result);
2154 goto out_input_register_device_failed;
2158 sensor->miscdev.parent = &client->dev;
2159 result = sensor_misc_device_register(sensor, type);
2161 dev_err(&client->dev,
2162 "fail to register misc device %s\n", sensor->miscdev.name);
2163 goto out_misc_device_register_device_failed;
2166 g_sensor[type] = sensor;
2168 if((type == SENSOR_TYPE_ACCEL) && (sensor->pdata->factory)) //only support setting gsensor orientation online now
2170 result = gsensor_class_init();
2172 dev_err(&client->dev,
2173 "fail to register misc device %s\n", sensor->i2c_id->name);
2174 goto out_misc_device_register_device_failed;
2178 #ifdef CONFIG_HAS_EARLYSUSPEND
2179 if((sensor->ops->suspend) && (sensor->ops->resume))
2181 sensor->early_suspend.suspend = sensor_suspend;
2182 sensor->early_suspend.resume = sensor_resume;
2183 sensor->early_suspend.level = 0x02;
2184 register_early_suspend(&sensor->early_suspend);
2188 printk("%s:initialized ok,sensor name:%s,type:%d,id=%d\n\n",__func__,sensor->ops->name,type,(int)sensor->i2c_id->driver_data);
2192 out_misc_device_register_device_failed:
2193 out_input_register_device_failed:
2196 dev_err(&client->adapter->dev, "%s failed %d\n\n", __func__, result);
2201 static void sensor_shut_down(struct i2c_client *client)
2203 #ifdef CONFIG_HAS_EARLYSUSPEND
2204 struct sensor_private_data *sensor =
2205 (struct sensor_private_data *) i2c_get_clientdata(client);
2206 if((sensor->ops->suspend) && (sensor->ops->resume))
2207 unregister_early_suspend(&sensor->early_suspend);
2208 DBG("%s:%s\n",__func__,sensor->i2c_id->name);
2212 static int sensor_remove(struct i2c_client *client)
2214 struct sensor_private_data *sensor =
2215 (struct sensor_private_data *) i2c_get_clientdata(client);
2218 cancel_delayed_work_sync(&sensor->delaywork);
2219 misc_deregister(&sensor->miscdev);
2220 #ifdef CONFIG_HAS_EARLYSUSPEND
2221 if((sensor->ops->suspend) && (sensor->ops->resume))
2222 unregister_early_suspend(&sensor->early_suspend);
2227 static const struct i2c_device_id sensor_id[] = {
2229 {"angle_kxtik", ANGLE_ID_KXTIK},
2230 {"angle_lis3dh", ANGLE_ID_LIS3DH},
2232 {"gsensor", ACCEL_ID_ALL},
2233 {"gs_mma8452", ACCEL_ID_MMA845X},
2234 {"gs_kxtik", ACCEL_ID_KXTIK},
2235 {"gs_kxtj9", ACCEL_ID_KXTJ9},
2236 {"gs_lis3dh", ACCEL_ID_LIS3DH},
2237 {"gs_mma7660", ACCEL_ID_MMA7660},
2238 {"gs_mxc6225", ACCEL_ID_MXC6225},
2239 {"gs_dmard10", ACCEL_ID_DMARD10},
2240 {"gs_lsm303d", ACCEL_ID_LSM303D},
2241 {"gs_mc3230",ACCEL_ID_MC3230},
2242 {"mpu6880_acc",ACCEL_ID_MPU6880},
2243 {"mpu6500_acc",ACCEL_ID_MPU6500},
2244 {"lsm330_acc", ACCEL_ID_LSM330},
2246 {"compass", COMPASS_ID_ALL},
2247 {"ak8975", COMPASS_ID_AK8975},
2248 {"ak8963", COMPASS_ID_AK8963},
2249 {"ak09911", COMPASS_ID_AK09911},
2250 {"mmc314x", COMPASS_ID_MMC314X},
2252 {"gyro", GYRO_ID_ALL},
2253 {"l3g4200d_gyro", GYRO_ID_L3G4200D},
2254 {"l3g20d_gyro", GYRO_ID_L3G20D},
2255 {"ewtsa_gyro", GYRO_ID_EWTSA},
2256 {"k3g", GYRO_ID_K3G},
2257 {"mpu6880_gyro",GYRO_ID_MPU6880},
2258 {"lsm330_gyro", GYRO_ID_LSM330},
2260 {"lightsensor", LIGHT_ID_ALL},
2261 {"light_cm3217", LIGHT_ID_CM3217},
2262 {"light_cm3218", LIGHT_ID_CM3218},
2263 {"light_cm3232", LIGHT_ID_CM3232},
2264 {"light_al3006", LIGHT_ID_AL3006},
2265 {"ls_stk3171", LIGHT_ID_STK3171},
2266 {"ls_isl29023", LIGHT_ID_ISL29023},
2267 {"ls_ap321xx", LIGHT_ID_AP321XX},
2268 {"ls_photoresistor", LIGHT_ID_PHOTORESISTOR},
2269 {"ls_us5152", LIGHT_ID_US5152},
2270 /*proximity sensor*/
2271 {"psensor", PROXIMITY_ID_ALL},
2272 {"proximity_al3006", PROXIMITY_ID_AL3006},
2273 {"ps_stk3171", PROXIMITY_ID_STK3171},
2274 {"ps_ap321xx", PROXIMITY_ID_AP321XX},
2277 {"temperature", TEMPERATURE_ID_ALL},
2278 {"tmp_ms5607", TEMPERATURE_ID_MS5607},
2281 {"pressure", PRESSURE_ID_ALL},
2282 {"pr_ms5607", PRESSURE_ID_MS5607},
2287 static struct of_device_id sensor_dt_ids[] = {
2289 { .compatible = "gs_mma8452" },
2290 { .compatible = "gs_lis3dh" },
2291 { .compatible = "gs_lsm303d" },
2292 { .compatible = "gs_mma7660" },
2293 { .compatible = "gs_mxc6225" },
2294 { .compatible = "gs_mc3230" },
2295 { .compatible = "lsm330_acc" },
2297 { .compatible = "ak8975" },
2298 { .compatible = "ak8963" },
2299 { .compatible = "ak09911" },
2300 { .compatible = "mmc314x" },
2303 { .compatible = "l3g4200d_gyro" },
2304 { .compatible = "l3g20d_gyro" },
2305 { .compatible = "ewtsa_gyro" },
2306 { .compatible = "k3g" },
2307 { .compatible = "lsm330_gyro" },
2310 { .compatible = "light_cm3217" },
2311 { .compatible = "light_cm3232" },
2312 { .compatible = "light_al3006" },
2313 { .compatible = "ls_stk3171" },
2314 { .compatible = "ls_ap321xx" },
2316 { .compatible = "ls_photoresistor" },
2317 { .compatible = "ls_us5152" },
2319 /*temperature sensor*/
2320 { .compatible = "tmp_ms5607" },
2323 { .compatible = "pr_ms5607" },
2326 { .compatible = "hall_och165t" },
2331 static struct i2c_driver sensor_driver = {
2332 .probe = sensor_probe,
2333 .remove = sensor_remove,
2334 .shutdown = sensor_shut_down,
2335 .id_table = sensor_id,
2337 .owner = THIS_MODULE,
2339 .of_match_table = of_match_ptr(sensor_dt_ids),
2340 .pm = SENSOR_PM_OPS,
2344 static int __init sensor_init(void)
2346 int res = i2c_add_driver(&sensor_driver);
2347 struct proc_dir_entry *sensor_proc_entry;
2348 pr_info("%s: Probe name %s\n", __func__, sensor_driver.driver.name);
2350 pr_err("%s failed\n", __func__);
2352 sensor_proc_entry = proc_create("driver/sensor_dbg", 0660, NULL, &sensor_proc_fops);
2353 printk("%s\n", SENSOR_VERSION_AND_TIME);
2357 static void __exit sensor_exit(void)
2359 pr_info("%s\n", __func__);
2360 i2c_del_driver(&sensor_driver);
2363 late_initcall(sensor_init);
2364 module_exit(sensor_exit);
2366 MODULE_AUTHOR("ROCKCHIP Corporation:lw@rock-chips.com");
2367 MODULE_DESCRIPTION("User space character device interface for sensors");
2368 MODULE_LICENSE("GPL");