2 * Copyright (C) 2010 Samsung Electronics. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 #include <linux/interrupt.h>
20 #include <linux/irq.h>
21 #include <linux/i2c.h>
23 #include <linux/errno.h>
24 #include <linux/device.h>
25 #include <linux/delay.h>
26 #include <linux/miscdevice.h>
27 #include <linux/platform_device.h>
28 #include <linux/leds.h>
29 #include <linux/gpio.h>
30 #include <linux/wakelock.h>
31 #include <linux/slab.h>
32 #include <linux/workqueue.h>
33 #include <linux/uaccess.h>
34 #include <linux/module.h>
35 #include <linux/regulator/consumer.h>
36 #include <linux/of_device.h>
37 #include <linux/of_gpio.h>
38 #include <linux/input.h>
39 #include <linux/iio/iio.h>
40 #include <linux/iio/sysfs.h>
41 #include <linux/iio/events.h>
42 #include <linux/iio/buffer.h>
44 #include "sensors_core.h"
45 #include <linux/sensor/gp2a002.h>
47 #define REGS_PROX 0x0 /* Read Only */
48 #define REGS_GAIN 0x1 /* Write Only */
49 #define REGS_HYS 0x2 /* Write Only */
50 #define REGS_CYCLE 0x3 /* Write Only */
51 #define REGS_OPMOD 0x4 /* Write Only */
52 #define REGS_CON 0x6 /* Write Only */
54 #if defined(CONFIG_MACH_COREPRIMEVE3G)
55 #define PROX_NONDETECT 0x2F
56 #define PROX_DETECT 0x0D
58 #define PROX_NONDETECT 0x2F
59 #define PROX_DETECT 0x0F
61 #define PROX_NONDETECT_MODE1 0x43
62 #define PROX_DETECT_MODE1 0x28
63 #define PROX_NONDETECT_MODE2 0x48
64 #define PROX_DETECT_MODE2 0x42
65 #define OFFSET_FILE_PATH "/efs/FactoryApp/prox_cal"
67 #define CHIP_DEV_NAME "GP2AP002"
68 #define CHIP_DEV_VENDOR "SHARP"
71 #if defined(CONFIG_SENSORS_IIO)
72 struct iio_dev *indio_dev;
74 struct input_dev *input;
77 struct gp2a_platform_data *pdata;
78 struct i2c_client *i2c_client;
79 struct mutex power_lock;
80 struct wake_lock prx_wake_lock;
81 struct workqueue_struct *wq;
82 struct work_struct work_prox;
91 #if defined(CONFIG_SENSORS_IIO)
101 #if defined(CONFIG_SENSORS_IIO)
102 #define IIO_BUFFER_1_BYTES 9 /* data 1 bytes + timestamp 8 bytes */
104 static const struct iio_chan_spec gp2a_channels[] = {
106 .type = IIO_PROXIMITY,
109 .scan_type = IIO_ST('s', IIO_BUFFER_1_BYTES * 8,
110 IIO_BUFFER_1_BYTES * 8, 0)
115 int gp2a_i2c_read(struct gp2a_data *gp2a, u8 reg, u8 *val)
118 unsigned char data[2] = {reg, 0};
120 struct i2c_msg msg[2] = {};
121 struct i2c_client *client = gp2a->i2c_client;
123 if ((client == NULL) || (!client->adapter))
126 msg[0].addr = client->addr;
131 msg[1].addr = client->addr;
139 err = i2c_transfer(client->adapter, msg, 2);
147 pr_err("[SENSOR] %s, i2c transfer error ret = %d\n", __func__, err);
152 int gp2a_i2c_write(struct gp2a_data *gp2a, u8 reg, u8 val)
155 struct i2c_msg msg[1];
156 unsigned char data[2];
158 struct i2c_client *client = gp2a->i2c_client;
160 if ((client == NULL) || (!client->adapter))
167 msg->addr = client->addr;
172 err = i2c_transfer(client->adapter, msg, 1);
178 pr_err("[SENSOR] %s, i2c transfer error ret= %d\n", __func__, err);
183 static int gp2a_leda_onoff(struct gp2a_data *gp2a, int power)
187 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
189 ret = gpio_direction_output(gp2a->pdata->power_en, 1);
191 ret = gpio_direction_output(gp2a->pdata->power_en, 0);
194 pr_err("[SENSOR] %s, error for direction\n", __func__);
198 struct regulator *gp2a_leda;
200 pr_info("[SENSOR] %s %s\n", __func__, (power) ? "on" : "off");
202 gp2a_leda = devm_regulator_get(&gp2a->i2c_client->dev, "gp2a-leda");
203 if (IS_ERR(gp2a_leda)) {
204 pr_err("[SENSOR]: %s - cannot get gp2a_leda\n", __func__);
209 ret = regulator_enable(gp2a_leda);
211 pr_err("[SENSOR] %s: enable gp2a_leda failed (%d)\n",
216 ret = regulator_disable(gp2a_leda);
218 pr_err("[SENSOR] %s: disable gp2a_leda failed (%d)\n",
224 devm_regulator_put(gp2a_leda);
230 static int gp2a_power_onoff(struct gp2a_data *gp2a, int power)
233 pr_info("[SENOSR] %s, status(%d)\n", __func__, power);
236 gp2a_leda_onoff(gp2a, power);
238 gp2a_i2c_write(gp2a, REGS_CON, value);
240 gp2a_i2c_write(gp2a, REGS_GAIN, value);
241 value = gp2a->nondetect;
242 gp2a_i2c_write(gp2a, REGS_HYS, value);
244 gp2a_i2c_write(gp2a, REGS_CYCLE, value);
246 gp2a_i2c_write(gp2a, REGS_OPMOD, value);
248 enable_irq_wake(gp2a->irq);
249 enable_irq(gp2a->irq);
252 gp2a_i2c_write(gp2a, REGS_CON, value);
254 disable_irq_wake(gp2a->irq);
255 disable_irq(gp2a->irq);
258 gp2a_i2c_write(gp2a, REGS_OPMOD, value);
259 gp2a_leda_onoff(gp2a, power);
264 static ssize_t adc_read(struct device *dev,
265 struct device_attribute *attr, char *buf)
267 struct gp2a_data *gp2a = dev_get_drvdata(dev);
269 return snprintf(buf, PAGE_SIZE, "%d\n", gp2a->val_state);
272 static ssize_t state_read(struct device *dev,
273 struct device_attribute *attr, char *buf)
275 struct gp2a_data *gp2a = dev_get_drvdata(dev);
277 return snprintf(buf, PAGE_SIZE, "%d\n", gp2a->val_state);
280 static ssize_t name_read(struct device *dev,
281 struct device_attribute *attr, char *buf)
283 return snprintf(buf, PAGE_SIZE, "%s\n", CHIP_DEV_NAME);
286 static ssize_t vendor_read(struct device *dev,
287 struct device_attribute *attr, char *buf)
289 return snprintf(buf, PAGE_SIZE, "%s\n", CHIP_DEV_VENDOR);
292 static int gp2a_cal_mode_read_file(struct gp2a_data *gp2a)
296 struct file *cal_mode_filp = NULL;
301 cal_mode_filp = filp_open(OFFSET_FILE_PATH, O_RDONLY, 0666);
302 if (IS_ERR(cal_mode_filp)) {
303 err = PTR_ERR(cal_mode_filp);
305 pr_err("[SENOSR] %s, Can't open cal_mode file\n",
311 err = cal_mode_filp->f_op->read(cal_mode_filp,
312 (char *)&gp2a->cal_mode,
313 sizeof(u8), &cal_mode_filp->f_pos);
314 if (err != sizeof(u8)) {
315 pr_err("[SENOSR] %s, Can't read the cal_mode from file\n",
317 filp_close(cal_mode_filp, current->files);
322 filp_close(cal_mode_filp, current->files);
328 static int gp2a_cal_mode_save_file(char mode)
330 struct file *cal_mode_filp = NULL;
337 cal_mode_filp = filp_open(OFFSET_FILE_PATH,
338 O_CREAT | O_TRUNC | O_WRONLY, 0666);
339 if (IS_ERR(cal_mode_filp)) {
340 pr_err("[SENOSR] %s, Can't open cal_mode file\n",
343 err = PTR_ERR(cal_mode_filp);
344 pr_err("[SENOSR] %s, err = %d\n", __func__, err);
348 err = cal_mode_filp->f_op->write(cal_mode_filp,
349 (char *)&mode, sizeof(u8), &cal_mode_filp->f_pos);
350 if (err != sizeof(u8)) {
351 pr_err("[SENOSR] %s, Can't read the cal_mode from file\n",
356 filp_close(cal_mode_filp, current->files);
362 static ssize_t prox_cal_read(struct device *dev,
363 struct device_attribute *attr, char *buf)
365 struct gp2a_data *gp2a = dev_get_drvdata(dev);
367 return snprintf(buf, PAGE_SIZE, "%d\n", gp2a->cal_mode);
370 static ssize_t prox_cal_write(struct device *dev,
371 struct device_attribute *attr, const char *buf, size_t size)
373 struct gp2a_data *gp2a = dev_get_drvdata(dev);
376 if (sysfs_streq(buf, "1")) {
378 gp2a->nondetect = PROX_NONDETECT_MODE1;
379 gp2a->detect = PROX_DETECT_MODE1;
380 } else if (sysfs_streq(buf, "2")) {
382 gp2a->nondetect = PROX_NONDETECT_MODE2;
383 gp2a->detect = PROX_DETECT_MODE2;
384 } else if (sysfs_streq(buf, "0")) {
386 gp2a->nondetect = PROX_NONDETECT;
387 gp2a->detect = PROX_DETECT;
389 pr_err("[SENOSR] %s, invalid value %d\n", __func__, *buf);
393 if (gp2a->power_state == 1) {
394 gp2a_power_onoff(gp2a, OFF);
396 gp2a_power_onoff(gp2a, ON);
399 err = gp2a_cal_mode_save_file(gp2a->cal_mode);
401 pr_err("[SENOSR] %s, prox_cal_write() failed\n", __func__);
408 static DEVICE_ATTR(adc, 0440, adc_read, NULL);
409 static DEVICE_ATTR(state, 0440, state_read, NULL);
410 static DEVICE_ATTR(name, 0440, name_read, NULL);
411 static DEVICE_ATTR(vendor, 0440, vendor_read, NULL);
412 static DEVICE_ATTR(prox_cal, 0664, prox_cal_read, prox_cal_write);
414 static struct device_attribute *proxi_attrs[] = {
423 #if defined(CONFIG_SENSORS_GP2A_HAS_REGULATOR)
424 static int gp2a_regulator_onoff(struct device *dev, bool onoff)
426 struct regulator *gp2a_vdd;
429 pr_info("[SENOSR] %s %s\n", __func__, (onoff) ? "on" : "off");
431 gp2a_vdd = devm_regulator_get(dev, "gp2a-vdd");
432 if (IS_ERR(gp2a_vdd)) {
433 pr_err("[SENSOR]: %s - cannot get gp2a_vdd\n", __func__);
437 regulator_set_voltage(gp2a_vdd, 2850000, 2850000);
440 ret = regulator_enable(gp2a_vdd);
442 pr_err("[SENOSR] %s: enable vdd failed (%d)\n",
447 ret = regulator_disable(gp2a_vdd);
449 pr_err("[SENOSR] %s: disable vdd failed (%d)\n",
455 devm_regulator_put(gp2a_vdd);
462 static ssize_t proximity_enable_show(struct device *dev,
463 struct device_attribute *attr, char *buf)
465 #if defined(CONFIG_SENSORS_IIO)
466 struct gp2a_data *gp2a = iio_priv(dev_get_drvdata(dev));
468 struct gp2a_data *gp2a = dev_get_drvdata(dev);
471 return snprintf(buf, PAGE_SIZE, "%d\n", gp2a->power_state);
474 static ssize_t proximity_enable_store(struct device *dev,
475 struct device_attribute *attr, const char *buf, size_t size)
477 #if defined(CONFIG_SENSORS_IIO)
478 struct gp2a_data *gp2a = iio_priv(dev_get_drvdata(dev));
480 struct gp2a_data *gp2a = dev_get_drvdata(dev);
485 err = kstrtoint(buf, 10, &value);
487 pr_err("[SENOSR] %s, kstrtoint failed.", __func__);
490 if (value != 0 && value != 1) {
491 pr_err("[SENOSR] %s, wrong value(%d)\n", __func__, value);
495 mutex_lock(&gp2a->power_lock);
497 if (gp2a->power_state != value) {
498 pr_info("[SENOSR] %s, enable(%d)\n", __func__, value);
500 err = gp2a_cal_mode_read_file(gp2a);
501 if (err < 0 && err != -ENOENT)
502 pr_err("[SENOSR] %s, cal_mode read fail\n",
505 pr_info("[SENOSR] %s, mode(%d)\n", __func__,
507 if (gp2a->cal_mode == 2) {
508 gp2a->nondetect = PROX_NONDETECT_MODE2;
509 gp2a->detect = PROX_DETECT_MODE2;
510 } else if (gp2a->cal_mode == 1) {
511 gp2a->nondetect = PROX_NONDETECT_MODE1;
512 gp2a->detect = PROX_DETECT_MODE1;
514 gp2a->nondetect = PROX_NONDETECT;
515 gp2a->detect = PROX_DETECT;
518 #if defined(CONFIG_SENSORS_GP2A_HAS_REGULATOR)
519 gp2a_regulator_onoff(&gp2a->i2c_client->dev, ON);
521 gp2a_power_onoff(gp2a, ON);
522 gp2a->power_state = value;
524 gp2a->val_state = value;
525 #if !defined(CONFIG_SENSORS_IIO)
526 input_report_abs(gp2a->input, ABS_DISTANCE,
528 input_sync(gp2a->input);
531 gp2a_power_onoff(gp2a, OFF);
532 #if defined(CONFIG_SENSORS_GP2A_HAS_REGULATOR)
533 gp2a_regulator_onoff(&gp2a->i2c_client->dev, OFF);
535 gp2a->power_state = value;
538 pr_err("[SENOSR] %s, wrong cmd for enable\n", __func__);
541 mutex_unlock(&gp2a->power_lock);
545 #if defined(CONFIG_SENSORS_IIO)
546 static IIO_DEVICE_ATTR(enable, S_IRUGO | S_IWUSR | S_IWGRP,
547 proximity_enable_show, proximity_enable_store, 0);
549 static struct attribute *proximity_sysfs_attrs[] = {
550 &iio_dev_attr_enable.dev_attr.attr,
555 static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR | S_IWGRP,
556 proximity_enable_show, proximity_enable_store);
558 static struct attribute *proximity_sysfs_attrs[] = {
559 &dev_attr_enable.attr,
564 static struct attribute_group proximity_attribute_group = {
565 .attrs = proximity_sysfs_attrs,
568 #if defined(CONFIG_SENSORS_IIO)
569 static int gp2a_read_raw(struct iio_dev *indio_dev,
570 struct iio_chan_spec const *chan,
571 int *val, int *val2, long mask)
573 struct gp2a_data *data = iio_priv(indio_dev);
576 switch (chan->type) {
578 *val = data->val_state;
581 pr_err("[SENSOR] %s, invalied channel\n", __func__);
588 static const struct iio_info gp2a_info = {
589 .attrs = &proximity_attribute_group,
590 .driver_module = THIS_MODULE,
591 .read_raw = gp2a_read_raw,
595 static void gp2a_prox_work_func(struct work_struct *work)
597 struct gp2a_data *gp2a = container_of(work,
598 struct gp2a_data, work_prox);
599 #if defined(CONFIG_SENSORS_IIO)
600 struct iio_dev *indio_dev = iio_priv_to_dev(gp2a);
602 u8 buf[IIO_BUFFER_1_BYTES];
606 gp2a_i2c_read(gp2a, REGS_PROX, &vo);
610 gp2a_i2c_write(gp2a, REGS_CON, value);
613 gp2a->val_state = 0x01;
614 value = gp2a->nondetect;
616 gp2a->val_state = 0x00;
617 value = gp2a->detect;
619 gp2a_i2c_write(gp2a, REGS_HYS, value);
621 pr_info("[SENSOR] %s, %d\n", __func__, gp2a->val_state);
623 #if defined(CONFIG_SENSORS_IIO)
624 ts = ktime_to_timespec(ktime_get_boottime());
625 gp2a->timestamp = ts.tv_sec * 1000000000ULL + ts.tv_nsec;
627 memcpy(buf, &gp2a->val_state, sizeof(gp2a->val_state));
628 memcpy(buf + 1, &gp2a->timestamp, sizeof(gp2a->timestamp));
630 iio_push_to_buffers(indio_dev, buf);
632 input_report_abs(gp2a->input, ABS_DISTANCE, gp2a->val_state);
633 input_sync(gp2a->input);
638 gp2a_i2c_write(gp2a, REGS_CON, value);
641 irqreturn_t gp2a_irq_handler(int irq, void *data)
643 struct gp2a_data *gp2a = data;
644 pr_info("[SENSRO] %s, %d\n", __func__, irq);
646 schedule_work((struct work_struct *)&gp2a->work_prox);
647 wake_lock_timeout(&gp2a->prx_wake_lock, 3*HZ);
652 static int gp2a_setup_irq(struct gp2a_data *gp2a)
654 struct gp2a_platform_data *pdata = gp2a->pdata;
658 ret = gpio_request(pdata->p_out, "gpio_proximity_out");
660 pr_err("[SENSOR] %s, gpio %d request failed (%d)\n",
661 __func__, pdata->p_out, ret);
665 ret = gpio_direction_input(pdata->p_out);
667 pr_err("[SENSOR] %s, failed gpio %d as input (%d)\n",
668 __func__, pdata->p_out, ret);
669 goto err_gpio_direction_input;
673 gp2a_i2c_write(gp2a, REGS_CON, value);
675 gp2a->irq = gpio_to_irq(pdata->p_out);
676 ret = request_irq(gp2a->irq, gp2a_irq_handler,
677 IRQF_TRIGGER_FALLING | IRQF_ONESHOT | IRQF_NO_SUSPEND,
678 "proximity_int", gp2a);
680 pr_err("[SENSOR] %s, request_irq(%d) failed for gpio %d (%d)\n",
681 __func__, gp2a->irq, pdata->p_out, ret);
682 goto err_request_irq;
685 pr_info("[SENSOR] %s, request_irq(%d) success for gpio %d\n",
686 __func__, gp2a->irq, pdata->p_out);
688 disable_irq(gp2a->irq);
691 gp2a_i2c_write(gp2a, REGS_OPMOD, value);
696 err_gpio_direction_input:
697 gpio_free(pdata->p_out);
702 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
703 static int gp2a_request_gpio(struct gp2a_platform_data *pdata)
707 ret = gpio_request(pdata->power_en, "prox_en");
709 pr_err("[SENSOR] %s: gpio request fail\n", __func__);
713 ret = gpio_direction_output(pdata->power_en, 0);
715 pr_err("[SENSOR] %s: unable to set_direction [%d]\n",
716 __func__, pdata->power_en);
724 static int gp2a_parse_dt(struct device *dev, struct gp2a_platform_data *pdata)
726 struct device_node *np = dev->of_node;
727 enum of_gpio_flags flags;
732 pdata->p_out = of_get_named_gpio_flags(np, "gp2a-i2c,irq-gpio", 0,
734 if (pdata->p_out < 0) {
735 pr_err("[SENSOR] %s : get irq_gpio(%d) error\n", __func__,
740 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
741 pdata->power_en = of_get_named_gpio_flags(np, "gp2a-i2c,en-gpio", 0,
743 if (pdata->power_en < 0) {
744 pr_err("[SENSOR] %s : get power_en(%d) error\n", __func__,
754 static int gp2a_i2c_probe(struct i2c_client *client,
755 const struct i2c_device_id *id)
757 struct gp2a_data *gp2a;
758 struct gp2a_platform_data *pdata = client->dev.platform_data;
759 #if defined(CONFIG_SENSORS_IIO)
760 struct iio_dev *indio_dev;
764 pr_info("[SENSOR] %s, start\n", __func__);
766 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
767 pr_err("[SENSOR] %s, i2c functionality failed\n", __func__);
771 #if defined(CONFIG_SENSORS_GP2A_HAS_REGULATOR)
772 ret = gp2a_regulator_onoff(&client->dev, ON);
774 pr_err("[SENSOR] %s, Power Up Failed\n", __func__);
775 goto err_regulator_onoff;
779 if (client->dev.of_node) {
780 pdata = devm_kzalloc(&client->dev,
781 sizeof(struct gp2a_platform_data), GFP_KERNEL);
782 ret = gp2a_parse_dt(&client->dev, pdata);
787 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
788 ret = gp2a_request_gpio(pdata);
790 goto err_request_gpio;
793 #if defined(CONFIG_SENSORS_IIO)
794 /* Configure IIO device */
795 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*gp2a));
797 pr_err("[SENSOR] %s, iio_device_alloc failed\n", __func__);
802 gp2a = iio_priv(indio_dev);
803 dev_set_name(&indio_dev->dev, "proximity_sensor");
804 i2c_set_clientdata(client, indio_dev);
806 /* Init IIO device */
807 indio_dev->name = client->name;
808 indio_dev->channels = gp2a_channels;
809 indio_dev->num_channels = ARRAY_SIZE(gp2a_channels);
810 indio_dev->dev.parent = &client->dev;
811 indio_dev->modes = INDIO_DIRECT_MODE;
812 indio_dev->info = &gp2a_info;
814 ret = sensors_iio_configure_buffer(indio_dev);
816 pr_err("[SENSOR] %s, configure ring buffer failed\n",
818 goto err_iio_configure_buffer_failed;
821 ret = iio_device_register(indio_dev);
823 pr_err("[SENSOR] %s: iio_device_register failed(%d)\n",
825 goto err_iio_register_failed;
829 gp2a->i2c_client = client;
831 #else /* !defined(CONFIG_SENSORS_IIO)*/
833 /* Allocate memory for driver data */
834 gp2a = kzalloc(sizeof(struct gp2a_data), GFP_KERNEL);
836 pr_err("[SENSOR] %s, failed memory alloc\n", __func__);
840 i2c_set_clientdata(client, gp2a);
843 gp2a->i2c_client = client;
845 gp2a->input = input_allocate_device();
847 pr_err("[SENSOR] %s, could not allocate input device\n",
849 goto err_input_allocate_device_proximity;
852 input_set_drvdata(gp2a->input, gp2a);
853 gp2a->input->name = "proximity_sensor";
854 input_set_capability(gp2a->input, EV_ABS, ABS_DISTANCE);
855 input_set_abs_params(gp2a->input, ABS_DISTANCE, 0, 1, 0, 0);
857 ret = input_register_device(gp2a->input);
859 pr_err("[SENSOR] %s, could not register input device\n",
861 goto err_input_register_device_proximity;
863 ret = sensors_create_symlink(&gp2a->input->dev.kobj,
866 pr_err("[SENSOR] %s, create sysfs symlink error\n", __func__);
867 goto err_sysfs_create_symlink_proximity;
870 ret = sysfs_create_group(&gp2a->input->dev.kobj,
871 &proximity_attribute_group);
873 pr_err("[SENSOR] %s, create sysfs group error\n", __func__);
874 goto err_sysfs_create_group_proximity;
878 wake_lock_init(&gp2a->prx_wake_lock, WAKE_LOCK_SUSPEND,
880 mutex_init(&gp2a->power_lock);
882 INIT_WORK(&gp2a->work_prox, gp2a_prox_work_func);
884 gp2a_leda_onoff(gp2a, ON);
885 ret = gp2a_setup_irq(gp2a);
887 pr_err("[SENSOR] %s, could not setup irq\n", __func__);
891 gp2a_leda_onoff(gp2a, OFF);
893 ret = sensors_register(gp2a->dev, gp2a, proxi_attrs,
896 pr_info("[SENSOR] %s, could not sensors_register\n",
898 goto err_sensors_register;
901 pr_info("[SENSOR] %s done\n", __func__);
904 err_sensors_register:
905 free_irq(gp2a->irq, gp2a);
906 gpio_free(gp2a->pdata->p_out);
908 gp2a_leda_onoff(gp2a, OFF);
909 mutex_destroy(&gp2a->power_lock);
910 wake_lock_destroy(&gp2a->prx_wake_lock);
911 #if defined(CONFIG_SENSORS_IIO)
912 iio_device_unregister(indio_dev);
913 err_iio_register_failed:
914 sensors_iio_unconfigure_buffer(indio_dev);
915 err_iio_configure_buffer_failed:
917 sysfs_remove_group(&gp2a->input->dev.kobj,
918 &proximity_attribute_group);
919 err_sysfs_create_group_proximity:
920 sensors_remove_symlink(&gp2a->input->dev.kobj,
922 err_sysfs_create_symlink_proximity:
923 input_unregister_device(gp2a->input);
924 err_input_register_device_proximity:
925 input_free_device(gp2a->input);
926 err_input_allocate_device_proximity:
932 #if defined(CONFIG_SENSORS_GP2A_HAS_REGULATOR)
933 gp2a_regulator_onoff(&client->dev, OFF);
936 pr_err("[SENSOR] %s is FAILED (%d)\n", __func__, ret);
940 static const struct i2c_device_id gp2a_device_id[] = {
944 MODULE_DEVICE_TABLE(i2c, gp2a_device_id);
946 static struct of_device_id gp2a_i2c_match_table[] = {
947 { .compatible = "gp2a-i2c",},
951 MODULE_DEVICE_TABLE(of, gp2a_i2c_match_table);
953 static struct i2c_driver gp2a_i2c_driver = {
956 .owner = THIS_MODULE,
957 .of_match_table = gp2a_i2c_match_table,
960 .probe = gp2a_i2c_probe,
961 .id_table = gp2a_device_id,
964 module_i2c_driver(gp2a_i2c_driver);
966 MODULE_AUTHOR("mjchen@sta.samsung.com");
967 MODULE_DESCRIPTION("Optical Sensor driver for gp2ap002");
968 MODULE_LICENSE("GPL");