1 /* drivers/input/misc/isl29028.c
3 * Copyright (C) 2010 ROCK-CHIPS, Inc.
4 * Author: eric <linjh@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/module.h>
18 #include <linux/kernel.h>
19 #include <linux/i2c.h>
20 #include <linux/irq.h>
21 #include <linux/gpio.h>
22 #include <linux/input.h>
23 #include <linux/platform_device.h>
25 #include <linux/uaccess.h>
26 #include <linux/miscdevice.h>
27 #include <linux/circ_buf.h>
28 #include <linux/interrupt.h>
30 #include <linux/slab.h>
32 #ifdef CONFIG_HAS_EARLYSUSPEND
33 #include <linux/earlysuspend.h>
36 #include <linux/delay.h>
37 #include <linux/wait.h>
43 #define D(x...) printk(x)
48 #define ISL_REG_CONFIG (0x01)
49 #define PROX_EN (1 << 7)
50 #define PROX_SLP(x) (x << 4)
51 #define PROX_DR_110 (0 << 3)
52 #define PROX_DR_220 (1 << 3)
53 #define ALS_EN (1 << 2)
54 #define ALS_RANGE_H (1 << 1)
55 #define ALS_RANGE_L (0 << 1)
56 #define ALS_MODE (1 << 0)
58 #define ISL_REG_INT (0x02)
59 #define PROX_FLAG_MASK ~(1 << 7)
60 #define LS_FLAG_MASK ~(1 << 3)
61 #define PROX_PRST(x) (x << 5)
62 #define ALS_PRST(x) (x << 1)
63 #define INT_AND (1 << 0)
64 #define INT_OR (0 << 0)
66 #define ISL_REG_PROX_LT (0x03)
67 #define ISL_REG_PROX_HT (0x04)
68 #define PROX_LT (0x90)
69 #define PROX_HT (0xA0)
71 #define ISL_REG_PROX_DATA (0x08)
72 #define ISL_REG_ALSIR_LDATA (0x09)
73 #define ISL_REG_ALSIR_HDATA (0x0a)
76 #define ISL_REG_ALSIR_TH1 (0x05)
77 #define ISL_REG_ALSIR_TH2 (0x06)
78 #define ISL_REG_ALSIR_TH3 (0x07)
80 struct isl29028_data {
81 struct input_dev *psensor_input_dev;
82 struct input_dev *lsensor_input_dev;
83 struct i2c_client *client;
84 struct delayed_work p_work; //for psensor
85 struct delayed_work l_work; //for light sensor
91 #ifdef CONFIG_HAS_EARLYSUSPEND
92 static struct early_suspend isl29028_early_suspend;
95 static irqreturn_t isl29028_psensor_irq_handler(int irq, void *data);
100 static const int luxValues[8] = {
102 640, 1280, 2600, 4095
106 static int isl29028_read_reg(struct i2c_client *client, char reg, char *value)
109 struct i2c_msg msg[2];
110 struct i2c_adapter *adap = client->adapter;
112 msg[0].addr = client->addr;
113 msg[0].flags = client->flags;
115 msg[0].buf = (char *)®
116 msg[0].scl_rate = 400 * 1000;
118 msg[1].addr = client->addr;
119 msg[1].flags = client->flags | I2C_M_RD;
121 msg[1].buf = (char *)value;
122 msg[1].scl_rate = 400 * 1000;
124 if ((ret = i2c_transfer(adap, (struct i2c_msg *)&msg, 2)) < 2) {
125 D("%s: read isl29028 register %#x failure\n", __FUNCTION__, reg);
132 static int isl29028_write_reg(struct i2c_client *client, char reg, char value)
137 struct i2c_adapter *adap = client->adapter;
142 msg.addr = client->addr;
143 msg.flags = client->flags;
145 msg.buf = (char *)&buf;
146 msg.scl_rate = 400 * 1000;
149 if ((ret = i2c_transfer(adap, (struct i2c_msg *)&msg, 1)) < 1) {
150 D("%s: read isl29028 register %#x failure\n", __FUNCTION__, reg);
157 static void isl29028_psensor_work_handler(struct work_struct *work)
160 struct isl29028_data *isl = (struct isl29028_data *)container_of(work, struct isl29028_data, p_work.work);
163 if (gpio_get_value(isl->client->irq)) {
164 D("line %d, input_report_abs 0 \n", __LINE__);
165 input_report_abs(isl->psensor_input_dev, ABS_DISTANCE, 1);
166 input_sync(isl->psensor_input_dev);
167 free_irq(isl->irq, (void *)isl);
168 rc = request_irq(isl->irq, isl29028_psensor_irq_handler,
169 IRQ_TYPE_EDGE_FALLING, isl->client->name, (void *)isl);
171 dev_err(&(isl->client->dev),"request_irq failed for gpio %d (%d)\n", isl->client->irq, rc);
175 D("line %d, input_report_abs 0 \n", __LINE__);
176 input_report_abs(isl->psensor_input_dev, ABS_DISTANCE, 0);
177 input_sync(isl->psensor_input_dev);
178 free_irq(isl->irq, (void *)isl);
179 rc = request_irq(isl->irq, isl29028_psensor_irq_handler,
180 IRQ_TYPE_EDGE_RISING, isl->client->name, (void *)isl);
182 dev_err(&(isl->client->dev),"request_irq failed for gpio %d (%d)\n", isl->client->irq, rc);
188 struct isl29028_data *isl = (struct isl29028_data *)container_of(work, struct isl29028_data, p_work.work);
189 char reg, value, int_flag;
191 mutex_lock(&isl->lock);
193 isl29028_read_reg(isl->client, reg, (char *)&int_flag);
195 if (!(int_flag >> 7)) {
196 D("line %d: input_report_abs 1 \n", __LINE__);
197 input_report_abs(isl->psensor_input_dev, ABS_DISTANCE, 1);
198 input_sync(isl->psensor_input_dev);
201 if (int_flag & 0x08) {
202 D("line %d; light sensor interrupt\n", __LINE__);
203 isl29028_write_reg(isl->client, reg, int_flag & 0xf7);
206 reg = ISL_REG_PROX_DATA;
207 isl29028_read_reg(isl->client, reg, (char *)&value);
208 //D("%s: int is %#x\n", __FUNCTION__, int_flag);
209 D("%s: prox_int is %d\n", __FUNCTION__, (int_flag >> 7 ));
210 D("%s: prox_data is %#x\n", __FUNCTION__, value);
211 mutex_unlock(&isl->lock);
213 enable_irq(isl->irq);
218 static irqreturn_t isl29028_psensor_irq_handler(int irq, void *data)
221 struct isl29028_data *isl = (struct isl29028_data *)data;
222 //disable_irq_nosync(isl->irq);
223 schedule_delayed_work(&isl->p_work, msecs_to_jiffies(420));
226 struct isl29028_data *isl = (struct isl29028_data *)data;
227 D("line %d, input_report_abs 0 \n", __LINE__);
228 input_report_abs(isl->psensor_input_dev, ABS_DISTANCE, 0);
229 input_sync(isl->psensor_input_dev);
231 disable_irq_nosync(isl->irq);
232 schedule_delayed_work(&isl->p_work, msecs_to_jiffies(420));
238 static int isl29028_psensor_enable(struct i2c_client *client)
240 char reg, value, int_flag;
242 struct isl29028_data *isl = (struct isl29028_data *)i2c_get_clientdata(client);
244 printk("line %d: enter func %s\n", __LINE__, __FUNCTION__);
246 mutex_lock(&isl->lock);
247 reg = ISL_REG_CONFIG;
248 ret = isl29028_read_reg(client, reg, &value);
250 ret = isl29028_write_reg(client, reg, value);
252 ret = isl29028_read_reg(client, reg, &value);
253 D("%s: configure reg value %#x ...\n", __FUNCTION__, value);
257 isl29028_read_reg(isl->client, reg, (char *)&int_flag);
258 if (!(int_flag >> 7)) {
259 printk("line %d: input_report_abs 1 \n", __LINE__);
260 input_report_abs(isl->psensor_input_dev, ABS_DISTANCE, 1);
261 input_sync(isl->psensor_input_dev);
263 mutex_unlock(&isl->lock);
265 //enable_irq(isl->irq);
270 static int isl29028_psensor_disable(struct i2c_client *client)
272 char ret, reg, reg2, value, value2;
273 struct isl29028_data *isl = (struct isl29028_data *)i2c_get_clientdata(client);
274 printk("line %d: enter func %s\n", __LINE__, __FUNCTION__);
276 //disable_irq_nosync(isl->irq);
278 mutex_lock(&isl->lock);
280 reg = ISL_REG_CONFIG;
281 ret = isl29028_read_reg(client, reg, &value);
283 ret = isl29028_write_reg(client, reg, value);
286 ret = isl29028_read_reg(client, reg2, &value2);
287 value2 &= PROX_FLAG_MASK;
288 ret = isl29028_write_reg(client, reg2, value2);
291 ret = isl29028_read_reg(client, reg, &value);
292 ret = isl29028_read_reg(client, reg2, &value2);
293 D("%s: configure reg value %#x ...\n", __FUNCTION__, value);
294 D("%s: interrupt reg value %#x ...\n", __FUNCTION__, value2);
296 mutex_unlock(&isl->lock);
298 //disable_irq(isl->irq);
299 cancel_delayed_work_sync(&isl->p_work);
300 //enable_irq(isl->irq);
305 static int isl29028_psensor_open(struct inode *inode, struct file *file);
306 static int isl29028_psensor_release(struct inode *inode, struct file *file);
307 static long isl29028_psensor_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
309 static int misc_ps_opened = 0;
310 static struct file_operations isl29028_psensor_fops = {
311 .owner = THIS_MODULE,
312 .open = isl29028_psensor_open,
313 .release = isl29028_psensor_release,
314 .unlocked_ioctl = isl29028_psensor_ioctl
317 static struct miscdevice isl29028_psensor_misc = {
318 .minor = MISC_DYNAMIC_MINOR,
320 .fops = &isl29028_psensor_fops
323 static int isl29028_psensor_open(struct inode *inode, struct file *file)
325 // struct i2c_client *client =
326 // container_of (isl29028_psensor_misc.parent, struct i2c_client, dev);
332 //return isl29028_psensor_enable(client);
335 static int isl29028_psensor_release(struct inode *inode, struct file *file)
337 // struct i2c_client *client =
338 // container_of (isl29028_psensor_misc.parent, struct i2c_client, dev);
342 //return isl29028_psensor_disable(client);
345 static long isl29028_psensor_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
347 char reg, val, enabled;
348 struct i2c_client *client =
349 container_of (isl29028_psensor_misc.parent, struct i2c_client, dev);
350 struct isl29028_data *isl = (struct isl29028_data *)i2c_get_clientdata(client);
352 D("%s cmd %d\n", __func__, _IOC_NR(cmd));
354 case PSENSOR_IOCTL_ENABLE:
355 if (get_user(val, (unsigned long __user *)arg))
358 return isl29028_psensor_enable(client);
360 return isl29028_psensor_disable(client);
362 case PSENSOR_IOCTL_GET_ENABLED:
363 mutex_lock(&isl->lock);
364 reg = ISL_REG_CONFIG;
365 isl29028_read_reg(client, reg, &val);
366 enabled = (val & (1 << 7)) ? 1 : 0;
367 mutex_unlock(&isl->lock);
368 return put_user(enabled, (unsigned long __user *)arg);
371 pr_err("%s: invalid cmd %d\n", __func__, _IOC_NR(cmd));
376 static int register_psensor_device(struct i2c_client *client, struct isl29028_data *isl)
378 struct input_dev *input_dev;
381 D("%s: allocating input device\n", __func__);
382 input_dev = input_allocate_device();
384 dev_err(&client->dev,"%s: could not allocate input device for psensor\n", __FUNCTION__);
389 isl->psensor_input_dev = input_dev;
390 input_set_drvdata(input_dev, isl);
392 input_dev->name = "proximity";
394 set_bit(EV_ABS, input_dev->evbit);
395 input_set_abs_params(input_dev, ABS_DISTANCE, 0, 1, 0, 0);
397 D("%s: registering input device\n", __func__);
398 rc = input_register_device(input_dev);
400 pr_err("%s: could not register input device for psensor\n", __func__);
401 goto err_free_input_device;
404 D("%s: registering misc device for psensor\n", __func__);
405 rc = misc_register(&isl29028_psensor_misc);
407 pr_err("%s: could not register misc device\n", __func__);
408 goto err_unregister_input_device;
411 isl29028_psensor_misc.parent = &client->dev;
412 //misc_deregister(&isl29028_psensor_misc);
414 INIT_DELAYED_WORK(&isl->p_work, isl29028_psensor_work_handler);
416 rc = gpio_request(client->irq, "isl29028 irq");
418 pr_err("%s: request gpio %d failed \n", __func__, client->irq);
419 goto err_unregister_misc;
421 rc = gpio_direction_input(client->irq);
423 pr_err("%s: failed set gpio input\n", __FUNCTION__);
426 gpio_pull_updown(client->irq, GPIOPullUp);
427 isl->irq = gpio_to_irq(client->irq);
429 rc = request_irq(isl->irq, isl29028_psensor_irq_handler,
430 IRQ_TYPE_EDGE_FALLING, client->name, (void *)isl);
432 dev_err(&client->dev,"request_irq failed for gpio %d (%d)\n", client->irq, rc);
436 //disable_irq_nosync(isl->irq);
441 gpio_free(client->irq);
443 misc_deregister(&isl29028_psensor_misc);
444 err_unregister_input_device:
445 input_unregister_device(input_dev);
446 err_free_input_device:
447 input_free_device(input_dev);
452 static void unregister_psensor_device(struct i2c_client *client, struct isl29028_data *isl)
454 misc_deregister(&isl29028_psensor_misc);
455 input_unregister_device(isl->psensor_input_dev);
456 input_free_device(isl->psensor_input_dev);
459 #define LSENSOR_POLL_PROMESHUTOK 1000
461 static int isl29028_lsensor_enable(struct i2c_client *client)
465 struct isl29028_data *isl = (struct isl29028_data *)i2c_get_clientdata(client);
467 mutex_lock(&isl->lock);
469 reg = ISL_REG_CONFIG;
470 ret = isl29028_read_reg(client, reg, &value);
472 ret = isl29028_write_reg(client, reg, value);
475 ret = isl29028_read_reg(client, reg, &value);
476 D("%s: configure reg value %#x ...\n", __FUNCTION__, value);
479 mutex_unlock(&isl->lock);
481 schedule_delayed_work(&(isl->l_work), msecs_to_jiffies(LSENSOR_POLL_PROMESHUTOK));
486 static int isl29028_lsensor_disable(struct i2c_client *client)
488 char ret, reg, reg2, value, value2;
489 struct isl29028_data *isl = (struct isl29028_data *)i2c_get_clientdata(client);
491 cancel_delayed_work_sync(&(isl->l_work));
493 mutex_lock(&isl->lock);
495 reg = ISL_REG_CONFIG;
496 ret = isl29028_read_reg(client, reg, &value);
498 ret = isl29028_write_reg(client, reg, value);
501 ret = isl29028_read_reg(client, reg2, &value2);
502 value2 &= LS_FLAG_MASK;
503 ret = isl29028_write_reg(client, reg2, value2);
506 ret = isl29028_read_reg(client, reg, &value);
507 ret = isl29028_read_reg(client, reg2, &value2);
508 D("%s: configure reg value %#x ...\n", __FUNCTION__, value);
509 D("%s: interrupt reg value %#x ...\n", __FUNCTION__, value2);
512 mutex_unlock(&isl->lock);
517 static int luxValue_to_level(int value)
520 if (value >= luxValues[7])
522 if (value <= luxValues[0])
525 if (value>=luxValues[i] && value<luxValues[i+1])
530 static void isl29028_lsensor_work_handler(struct work_struct *work)
532 struct isl29028_data *isl = (struct isl29028_data *)container_of(work, struct isl29028_data, l_work.work);
533 char reg, l_value, h_value;
534 unsigned int als_value;
537 mutex_lock(&isl->lock);
538 reg = ISL_REG_ALSIR_LDATA;
539 isl29028_read_reg(isl->client, reg, (char *)&l_value);
541 reg = ISL_REG_ALSIR_HDATA;
542 isl29028_read_reg(isl->client, reg, (char *)&h_value);
544 mutex_unlock(&isl->lock);
547 als_value = (als_value << 8) | l_value;
550 D("%s: ls_data is %#x\n", __FUNCTION__, als_value);
553 level = luxValue_to_level(als_value);
556 D("%s: ls_level is %d\n", __FUNCTION__, level);
559 if (level != g_lightlevel) {
560 g_lightlevel = level;
561 input_report_abs(isl->lsensor_input_dev, ABS_MISC, level);
562 input_sync(isl->lsensor_input_dev);
564 schedule_delayed_work(&(isl->l_work), msecs_to_jiffies(LSENSOR_POLL_PROMESHUTOK));
567 static int isl29028_lsensor_open(struct inode *inode, struct file *file);
568 static int isl29028_lsensor_release(struct inode *inode, struct file *file);
569 static long isl29028_lsensor_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
571 static int misc_ls_opened = 0;
572 static struct file_operations isl29028_lsensor_fops = {
573 .owner = THIS_MODULE,
574 .open = isl29028_lsensor_open,
575 .release = isl29028_lsensor_release,
576 .unlocked_ioctl = isl29028_lsensor_ioctl
579 static struct miscdevice isl29028_lsensor_misc = {
580 .minor = MISC_DYNAMIC_MINOR,
581 .name = "lightsensor",
582 .fops = &isl29028_lsensor_fops
585 static int isl29028_lsensor_open(struct inode *inode, struct file *file)
587 // struct i2c_client *client =
588 // container_of (isl29028_lsensor_misc.parent, struct i2c_client, dev);
594 //return isl29028_lsensor_enable(client);
597 static int isl29028_lsensor_release(struct inode *inode, struct file *file)
600 // struct i2c_client *client =
601 // container_of (isl29028_lsensor_misc.parent, struct i2c_client, dev);
605 //return isl29028_lsensor_disable(client);
608 static long isl29028_lsensor_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
610 char reg, val, enabled;
611 struct i2c_client *client =
612 container_of (isl29028_lsensor_misc.parent, struct i2c_client, dev);
613 struct isl29028_data *isl = (struct isl29028_data *)i2c_get_clientdata(client);
615 D("%s cmd %d\n", __func__, _IOC_NR(cmd));
617 case LIGHTSENSOR_IOCTL_ENABLE:
618 if (get_user(val, (unsigned long __user *)arg))
621 return isl29028_lsensor_enable(client);
623 return isl29028_lsensor_disable(client);
625 case LIGHTSENSOR_IOCTL_GET_ENABLED:
626 mutex_lock(&isl->lock);
627 reg = ISL_REG_CONFIG;
628 isl29028_read_reg(client, reg, &val);
629 mutex_unlock(&isl->lock);
630 enabled = (val & (1 << 2)) ? 1 : 0;
631 return put_user(enabled, (unsigned long __user *)arg);
634 pr_err("%s: invalid cmd %d\n", __func__, _IOC_NR(cmd));
639 static int register_lsensor_device(struct i2c_client *client, struct isl29028_data *isl)
641 struct input_dev *input_dev;
644 D("%s: allocating input device\n", __func__);
645 input_dev = input_allocate_device();
647 dev_err(&client->dev,"%s: could not allocate input device forlsensor\n", __FUNCTION__);
652 isl->lsensor_input_dev = input_dev;
653 input_set_drvdata(input_dev, isl);
655 input_dev->name = "lightsensor-level";
657 set_bit(EV_ABS, input_dev->evbit);
658 input_set_abs_params(input_dev, ABS_MISC, 0, 8, 0, 0);
660 D("%s: registering input device\n", __func__);
661 rc = input_register_device(input_dev);
663 pr_err("%s: could not register input device for lsensor\n", __func__);
664 goto err_free_input_device;
667 D("%s: registering misc device for lsensor\n", __func__);
668 rc = misc_register(&isl29028_lsensor_misc);
670 pr_err("%s: could not register misc device\n", __func__);
671 goto err_unregister_input_device;
674 isl29028_lsensor_misc.parent = &client->dev;
676 INIT_DELAYED_WORK(&isl->l_work, isl29028_lsensor_work_handler);
680 err_unregister_input_device:
681 input_unregister_device(input_dev);
682 err_free_input_device:
683 input_free_device(input_dev);
688 static void unregister_lsensor_device(struct i2c_client *client, struct isl29028_data *isl)
690 misc_deregister(&isl29028_lsensor_misc);
691 input_unregister_device(isl->lsensor_input_dev);
692 input_free_device(isl->lsensor_input_dev);
695 static int isl29028_config(struct i2c_client *client)
699 struct isl29028_data *isl = (struct isl29028_data *)i2c_get_clientdata(client);
701 D("%s: init isl29028 all register\n", __func__);
703 mutex_lock(&isl->lock);
705 /*********************** power on **************************/
708 if ((ret = i2c_master_send(client, buf, 2)) < 2) {
709 printk("%s: config isl29028 register %#x err %d\n", __FUNCTION__, buf[0], ret);
714 if ((ret = i2c_master_send(client, buf, 2)) < 2) {
715 printk("%s: config isl29028 register %#x err %d\n", __FUNCTION__, buf[0], ret);
718 buf[0] = ISL_REG_CONFIG;
720 if ((ret = i2c_master_send(client, buf, 2)) < 2) {
721 printk("%s: config isl29028 register %#x err %d\n", __FUNCTION__, buf[0], ret);
725 mutex_unlock(&isl->lock);
730 /***********************config**************************/
732 buf[0] = ISL_REG_CONFIG;
733 buf[1] = /*PROX_EN | */PROX_SLP(4) | PROX_DR_220 | ALS_RANGE_H /*| ALS_EN */;
734 if ((ret = i2c_master_send(client, buf, 2)) < 2) {
735 printk("%s: config isl29028 register %#x err %d\n", __FUNCTION__, buf[0], ret);
738 isl29028_read_reg(client, 0x01, &value);
739 printk("%s: config isl29028 CONFIGURE(0x01) reg %#x \n", __FUNCTION__, value);
742 buf[0] = ISL_REG_INT;
743 buf[1] = PROX_PRST(1) | ALS_PRST(3);
744 if ((ret = i2c_master_send(client, buf, 2)) < 2) {
745 printk("%s: config isl29028 register %#x err %d\n", __FUNCTION__, buf[0], ret);
748 isl29028_read_reg(client, 0x02, &value);
749 printk("%s: config isl29028 INTERRUPT(0x02) reg %#x \n", __FUNCTION__, value);
752 buf[0] = ISL_REG_PROX_LT;
754 if ((ret = i2c_master_send(client, buf, 2)) < 2) {
755 printk("%s: config isl29028 register %#x err %d\n", __FUNCTION__, buf[0], ret);
758 isl29028_read_reg(client, 0x03, &value);
759 printk("%s: config isl29028 PROX_LT(0x03) reg %#x \n", __FUNCTION__, value);
762 buf[0] = ISL_REG_PROX_HT;
764 if ((ret = i2c_master_send(client, buf, 2)) < 2) {
765 printk("%s: config isl29028 register %#x err %d\n", __FUNCTION__, buf[0], ret);
768 isl29028_read_reg(client, 0x04, &value);
769 printk("%s: config isl29028 PROX_HT(0x04) reg %#x \n", __FUNCTION__, value);
772 buf[0] = ISL_REG_ALSIR_TH1;
774 if ((ret = i2c_master_send(client, buf, 2)) < 2) {
775 printk("%s: config isl29028 register %#x err %d\n", __FUNCTION__, buf[0], ret);
778 buf[0] = ISL_REG_ALSIR_TH2;
780 if ((ret = i2c_master_send(client, buf, 2)) < 2) {
781 printk("%s: config isl29028 register %#x err %d\n", __FUNCTION__, buf[0], ret);
784 buf[0] = ISL_REG_ALSIR_TH3;
786 if ((ret = i2c_master_send(client, buf, 2)) < 2) {
787 printk("%s: config isl29028 register %#x err %d\n", __FUNCTION__, buf[0], ret);
790 mutex_unlock(&isl->lock);
795 #ifdef CONFIG_HAS_EARLYSUSPEND
796 static void isl29028_suspend(struct early_suspend *h)
798 struct i2c_client *client = container_of(isl29028_psensor_misc.parent, struct i2c_client, dev);
799 struct isl29028_data *isl = (struct isl29028_data *)i2c_get_clientdata(client);
801 D("isl29028 early suspend ========================= \n");
803 enable_irq_wake(isl->irq);
804 // isl29028_psensor_disable(client);
806 isl29028_lsensor_disable(client);
809 static void isl29028_resume(struct early_suspend *h)
811 struct i2c_client *client = container_of(isl29028_psensor_misc.parent, struct i2c_client, dev);
812 struct isl29028_data *isl = (struct isl29028_data *)i2c_get_clientdata(client);
814 D("isl29028 early resume ======================== \n");
816 disable_irq_wake(isl->irq);
817 // isl29028_psensor_enable(client);
819 isl29028_lsensor_enable(client);
822 #define isl29028_suspend NULL
823 #define isl29028_resume NULL
826 static int isl29028_probe(struct i2c_client *client, const struct i2c_device_id *id)
829 struct isl29028_data *isl;
831 D("\n%s: isl29028 i2c client probe\n\n", __func__);
833 isl = kzalloc(sizeof(struct isl29028_data), GFP_KERNEL);
836 dev_err(&client->dev, "failed to allocate driver data\n");
840 isl->client = client;
841 i2c_set_clientdata(client, isl);
844 mutex_init(&isl->lock);
846 rc = register_psensor_device(client, isl);
848 dev_err(&client->dev, "failed to register_psensor_device\n");
852 rc = register_lsensor_device(client, isl);
854 dev_err(&client->dev, "failed to register_lsensor_device\n");
855 goto unregister_device1;
858 rc = isl29028_config(client);
860 dev_err(&client->dev, "failed to isl29028_config\n");
861 goto unregister_device2;
864 #ifdef CONFIG_HAS_EARLYSUSPEND
865 isl29028_early_suspend.suspend = isl29028_suspend;
866 isl29028_early_suspend.resume = isl29028_resume;
867 isl29028_early_suspend.level = 0x02;
868 register_early_suspend(&isl29028_early_suspend);
871 //isl29028_psensor_enable(client);
872 //isl29028_lsensor_enable(client);
877 unregister_lsensor_device(client, isl);
879 unregister_psensor_device(client, isl);
886 static int isl29028_remove(struct i2c_client *client)
888 struct isl29028_data *isl29028 = i2c_get_clientdata(client);
890 unregister_lsensor_device(client, isl29028);
891 unregister_psensor_device(client, isl29028);
893 #ifdef CONFIG_HAS_EARLYSUSPEND
894 unregister_early_suspend(&isl29028_early_suspend);
899 static const struct i2c_device_id isl29028_id[] = {
904 static struct i2c_driver isl29028_driver = {
908 .probe = isl29028_probe,
909 .remove = isl29028_remove,
910 .id_table = isl29028_id,
914 static int __init isl29028_init(void)
917 return i2c_add_driver(&isl29028_driver);
920 static void __exit isl29028_exit(void)
922 return i2c_del_driver(&isl29028_driver);
925 module_init(isl29028_init);
926 module_exit(isl29028_exit);