2bacfb5c972fe567f90bdbdb9dc7793230f4942e
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / sensors / cm36672p.c
1 /* driver/sensor/cm36672p.c
2  * Copyright (c) 2011 SAMSUNG
3  *
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  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17  * MA  02110-1301, USA.
18  */
19
20 #include <linux/interrupt.h>
21 #include <linux/irq.h>
22 #include <linux/i2c.h>
23 #include <linux/errno.h>
24 #include <linux/device.h>
25 #include <linux/gpio.h>
26 #include <linux/wakelock.h>
27 #include <linux/input.h>
28 #include <linux/workqueue.h>
29 #include <linux/slab.h>
30 #include <linux/delay.h>
31 #include <linux/fs.h>
32 #include <linux/module.h>
33 #include <linux/uaccess.h>
34 #include <linux/of_gpio.h>
35 #include <linux/regulator/consumer.h>
36
37 #include "sensors_core.h"
38 #include <linux/sensor/cm36672p.h>
39
40 /* For debugging */
41 #define CM36672P_DEBUG
42
43 #define VENDOR          "CAPELLA"
44 #define CHIP_ID         "CM36672P"
45
46 #define I2C_M_WR        0 /* for i2c Write */
47 #define I2c_M_RD        1 /* for i2c Read */
48
49 /* register addresses */
50 /* Proximity sensor */
51 #define REG_PS_CONF1    0x03
52 #define REG_PS_CONF3    0x04
53 #define REG_PS_CANC     0x05
54 #define REG_PS_THD_LOW  0x06
55 #define REG_PS_THD_HIGH 0x07
56 #define REG_PS_DATA     0x08
57
58 /* Intelligent Cancelation*/
59 #define PROXIMITY_CANCELATION
60 #ifdef PROXIMITY_CANCELATION
61 #define SUCCESS         1
62 #define FAIL            0
63 #define ERROR           -1
64 #define CAL_SKIP_ADC    8
65 #define CAL_FAIL_ADC    18
66 #define CANCELATION_FILE_PATH   "/csa/sensor/prox_cal"
67 #endif
68
69 #define PROX_READ_NUM   40
70
71  /* proximity sensor default value for register */
72 #define DEFAULT_HI_THD  0x0022
73 #define DEFAULT_LOW_THD 0x001E
74 #define CANCEL_HI_THD   0x0022
75 #define CANCEL_LOW_THD  0x001E
76
77 #define DEFAULT_CONF1   0x03A0
78 #define DEFAULT_CONF3   0x4010
79 #define DEFAULT_TRIM    0x0000
80
81
82 enum {
83         REG_ADDR = 0,
84         CMD,
85 };
86
87 enum {
88         OFF = 0,
89         ON,
90 };
91
92 enum {
93         PS_CONF1 = 0,
94         PS_CONF3,
95         PS_THD_LOW,
96         PS_THD_HIGH,
97         PS_CANCEL,
98         PS_REG_NUM,
99 };
100
101 /*
102 * NOTE:
103 * Since PS integration time and LED current would be different by HW rev or Project,
104 * we move the setting value to device tree. Please refer to the value below.
105 * PS_IT (CONF1, 0x03_L)
106 * 1T = 0, 1.5T = 1, 2T = 2, 2.5T = 3, 3T = 4, 3.5T = 5, 4T = 6, 8T = 7
107 *
108 * LED_I (CONF3, 0x04_H)
109 * 50mA = 0, 75mA = 1, 100mA = 2, 120mA = 3, 140mA = 4, 160mA = 5, 180mA = 6, 200mA = 7
110 */
111 static u16 ps_reg_init_setting[PS_REG_NUM][2] = {
112         {REG_PS_CONF1, DEFAULT_CONF1},
113         {REG_PS_CONF3, DEFAULT_CONF3},
114         {REG_PS_THD_LOW, DEFAULT_LOW_THD},
115         {REG_PS_THD_HIGH, DEFAULT_HI_THD},
116         {REG_PS_CANC, DEFAULT_TRIM},
117 };
118
119 /* driver data */
120 struct cm36672p_data {
121         struct i2c_client *i2c_client;
122         struct wake_lock prx_wake_lock;
123         struct input_dev *proximity_input_dev;
124         struct cm36672p_platform_data *pdata;
125         struct mutex read_lock;
126         struct hrtimer prox_timer;
127         struct workqueue_struct *prox_wq;
128         struct work_struct work_prox;
129         struct device *proximity_dev;
130         ktime_t prox_poll_delay;
131         atomic_t enable;
132         int irq;
133         int avg[3];
134         unsigned int uProxCalResult;
135 };
136
137 static int proximity_regulator_onoff(struct device *dev, bool onoff);
138
139 int cm36672p_i2c_read_word(struct cm36672p_data *data, u8 command, u16 *val)
140 {
141         int err = 0;
142         int retry = 3;
143         struct i2c_client *client = data->i2c_client;
144         struct i2c_msg msg[2];
145         unsigned char tmp[2] = {0,};
146         u16 value = 0;
147
148         if ((client == NULL) || (!client->adapter))
149                 return -ENODEV;
150
151         while (retry--) {
152                 /* send slave address & command */
153                 msg[0].addr = client->addr;
154                 msg[0].flags = I2C_M_WR;
155                 msg[0].len = 1;
156                 msg[0].buf = &command;
157
158                 /* read word data */
159                 msg[1].addr = client->addr;
160                 msg[1].flags = I2C_M_RD;
161                 msg[1].len = 2;
162                 msg[1].buf = tmp;
163
164                 err = i2c_transfer(client->adapter, msg, 2);
165
166                 if (err >= 0) {
167                         value = (u16)tmp[1];
168                         *val = (value << 8) | (u16)tmp[0];
169                         return err;
170                 }
171         }
172         pr_err("%s, i2c transfer error ret=%d\n", __func__, err);
173         return err;
174 }
175
176 int cm36672p_i2c_write_word(struct cm36672p_data *data, u8 command,
177         u16 val)
178 {
179         int err = 0;
180         struct i2c_client *client = data->i2c_client;
181         int retry = 3;
182
183         if ((client == NULL) || (!client->adapter))
184                 return -ENODEV;
185
186         while (retry--) {
187                 err = i2c_smbus_write_word_data(client, command, val);
188                 if (err >= 0)
189                         return 0;
190         }
191         pr_err("%s, i2c transfer error(%d)\n", __func__, err);
192         return err;
193 }
194
195 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
196 static int leden_gpio_onoff(struct cm36672p_data *data, bool onoff)
197 {
198         struct cm36672p_platform_data *pdata = data->pdata;
199
200         gpio_set_value(pdata->leden_gpio, onoff);
201         if (onoff)
202                 msleep(20);
203
204         return 0;
205 }
206 #endif
207
208 #ifdef PROXIMITY_CANCELATION
209 static int proximity_open_cancelation(struct cm36672p_data *data)
210 {
211         struct file *cancel_filp = NULL;
212         int err = 0;
213         mm_segment_t old_fs;
214
215         old_fs = get_fs();
216         set_fs(KERNEL_DS);
217
218         cancel_filp = filp_open(CANCELATION_FILE_PATH, O_RDONLY, 0666);
219         if (IS_ERR(cancel_filp)) {
220                 err = PTR_ERR(cancel_filp);
221                 if (err != -ENOENT)
222                         pr_err("%s, Can't open cancelation file\n",
223                                 __func__);
224                 set_fs(old_fs);
225                 return err;
226         }
227
228         err = cancel_filp->f_op->read(cancel_filp,
229                 (char *)&ps_reg_init_setting[PS_CANCEL][CMD],
230                 sizeof(u16), &cancel_filp->f_pos);
231         if (err != sizeof(u16)) {
232                 pr_err("%s, Can't read the cancel data from file\n", __func__);
233                 err = -EIO;
234         }
235
236         /*If there is an offset cal data. */
237         if (ps_reg_init_setting[PS_CANCEL][CMD] != data->pdata->default_trim) {
238                 ps_reg_init_setting[PS_THD_HIGH][CMD] =
239                         data->pdata->cancel_hi_thd ?
240                         data->pdata->cancel_hi_thd :
241                         CANCEL_HI_THD;
242                 ps_reg_init_setting[PS_THD_LOW][CMD] =
243                         data->pdata->cancel_low_thd ?
244                         data->pdata->cancel_low_thd :
245                         CANCEL_LOW_THD;
246         }
247
248         pr_info("%s, prox_cal= 0x%x, high_thresh= 0x%x, low_thresh= 0x%x\n",
249                 __func__,
250                 ps_reg_init_setting[PS_CANCEL][CMD],
251                 ps_reg_init_setting[PS_THD_HIGH][CMD],
252                 ps_reg_init_setting[PS_THD_LOW][CMD]);
253
254         filp_close(cancel_filp, current->files);
255         set_fs(old_fs);
256
257         return err;
258 }
259
260 static int proximity_store_cancelation(struct device *dev, bool do_calib)
261 {
262         struct cm36672p_data *data = dev_get_drvdata(dev);
263         struct file *cancel_filp = NULL;
264         mm_segment_t old_fs;
265         int err;
266         u16 ps_data = 0;
267
268         if (do_calib) {
269                 mutex_lock(&data->read_lock);
270                 cm36672p_i2c_read_word(data,
271                         REG_PS_DATA, &ps_data);
272                 mutex_unlock(&data->read_lock);
273
274                 if (ps_data < CAL_SKIP_ADC) {
275                         /*SKIP*/
276                         ps_reg_init_setting[PS_CANCEL][CMD] =
277                                 data->pdata->default_trim;
278                         pr_info("%s:crosstalk <= %d\n", __func__, CAL_SKIP_ADC);
279                         data->uProxCalResult = 2;
280                 } else if (ps_data < CAL_FAIL_ADC) {
281                         /*CANCELATION*/
282                         ps_reg_init_setting[PS_CANCEL][CMD] =
283                                 ps_data + data->pdata->default_trim;
284                         pr_info("%s:crosstalk_offset = %u", __func__, ps_data);
285                         data->uProxCalResult = 1;
286                 } else {
287                         /*FAIL*/
288                         ps_reg_init_setting[PS_CANCEL][CMD] =
289                                 data->pdata->default_trim;
290                         pr_info("%s:crosstalk > %d\n", __func__, CAL_FAIL_ADC);
291                         data->uProxCalResult = 0;
292                 }
293
294                 if (data->uProxCalResult == 1) {
295                         ps_reg_init_setting[PS_THD_HIGH][CMD] =
296                                 data->pdata->cancel_hi_thd ?
297                                 data->pdata->cancel_hi_thd :
298                                 CANCEL_HI_THD;
299                         ps_reg_init_setting[PS_THD_LOW][CMD] =
300                                 data->pdata->cancel_low_thd ?
301                                 data->pdata->cancel_low_thd :
302                                 CANCEL_LOW_THD;
303                 } else {
304                         ps_reg_init_setting[PS_THD_HIGH][CMD] =
305                                 data->pdata->default_hi_thd ?
306                                 data->pdata->default_hi_thd :
307                                 DEFAULT_HI_THD;
308                         ps_reg_init_setting[PS_THD_LOW][CMD] =
309                                 data->pdata->default_low_thd ?
310                                 data->pdata->default_low_thd :
311                                 DEFAULT_LOW_THD;
312                 }
313         } else { /* reset */
314                 ps_reg_init_setting[PS_CANCEL][CMD] =
315                         data->pdata->default_trim;
316                 ps_reg_init_setting[PS_THD_HIGH][CMD] =
317                         data->pdata->default_hi_thd ?
318                         data->pdata->default_hi_thd :
319                         DEFAULT_HI_THD;
320                 ps_reg_init_setting[PS_THD_LOW][CMD] =
321                         data->pdata->default_low_thd ?
322                         data->pdata->default_low_thd :
323                         DEFAULT_LOW_THD;
324         }
325
326         if ((data->uProxCalResult == 1) || !do_calib) {
327         err = cm36672p_i2c_write_word(data, REG_PS_CANC,
328                 ps_reg_init_setting[PS_CANCEL][CMD]);
329         if (err < 0)
330                 pr_err("%s, ps_canc_reg is failed. %d\n", __func__,
331                         err);
332         err = cm36672p_i2c_write_word(data, REG_PS_THD_HIGH,
333                 ps_reg_init_setting[PS_THD_HIGH][CMD]);
334         if (err < 0)
335                 pr_err("%s: ps_high_reg is failed. %d\n", __func__,
336                         err);
337         err = cm36672p_i2c_write_word(data, REG_PS_THD_LOW,
338                 ps_reg_init_setting[PS_THD_LOW][CMD]);
339         if (err < 0)
340                 pr_err("%s: ps_low_reg is failed. %d\n", __func__,
341                         err);
342         }
343
344         pr_info("%s: prox_cal = 0x%x, ps_high_thresh = 0x%x, ps_low_thresh = 0x%x\n",
345                 __func__,
346                 ps_reg_init_setting[PS_CANCEL][CMD],
347                 ps_reg_init_setting[PS_THD_HIGH][CMD],
348                 ps_reg_init_setting[PS_THD_LOW][CMD]);
349
350         old_fs = get_fs();
351         set_fs(KERNEL_DS);
352
353         cancel_filp = filp_open(CANCELATION_FILE_PATH,
354                 O_CREAT | O_TRUNC | O_WRONLY | O_SYNC, 0666);
355         if (IS_ERR(cancel_filp)) {
356                 pr_err("%s, Can't open cancelation file\n", __func__);
357                 set_fs(old_fs);
358                 err = PTR_ERR(cancel_filp);
359                 return err;
360         }
361
362         err = cancel_filp->f_op->write(cancel_filp,
363                 (char *)&ps_reg_init_setting[PS_CANCEL][CMD],
364                 sizeof(u16), &cancel_filp->f_pos);
365         if (err != sizeof(u16)) {
366                 pr_err("%s, Can't write the cancel data to file\n", __func__);
367                 err = -EIO;
368         }
369
370         filp_close(cancel_filp, current->files);
371         set_fs(old_fs);
372
373         if (!do_calib) /* delay for clearing */
374                 msleep(150);
375
376         return err;
377 }
378
379 static ssize_t proximity_cancel_store(struct device *dev,
380         struct device_attribute *attr, const char *buf, size_t size)
381 {
382         bool do_calib;
383         int err;
384
385         if (sysfs_streq(buf, "1")) /* calibrate cancelation value */
386                 do_calib = true;
387         else if (sysfs_streq(buf, "0")) /* reset cancelation value */
388                 do_calib = false;
389         else {
390                 pr_err("%s, invalid value %d\n", __func__, *buf);
391                 return -EINVAL;
392         }
393
394         err = proximity_store_cancelation(dev, do_calib);
395         if (err < 0) {
396                 pr_err("%s, proximity_store_cancelation() failed\n",
397                         __func__);
398                 return err;
399         }
400
401         return size;
402 }
403
404 static ssize_t proximity_cancel_show(struct device *dev,
405         struct device_attribute *attr, char *buf)
406 {
407         struct cm36672p_data *data = dev_get_drvdata(dev);
408         return snprintf(buf, PAGE_SIZE, "%u,%u,%u\n",
409                 ps_reg_init_setting[PS_CANCEL][CMD] - data->pdata->default_trim,
410                 ps_reg_init_setting[PS_THD_HIGH][CMD],
411                 ps_reg_init_setting[PS_THD_LOW][CMD]);
412 }
413
414 static ssize_t proximity_cancel_pass_show(struct device *dev,
415         struct device_attribute *attr, char *buf)
416 {
417         struct cm36672p_data *data = dev_get_drvdata(dev);
418
419         pr_info("%s, %u\n", __func__, data->uProxCalResult);
420         return snprintf(buf, PAGE_SIZE, "%u\n", data->uProxCalResult);
421 }
422 #endif
423
424 static ssize_t proximity_enable_store(struct device *dev,
425         struct device_attribute *attr, const char *buf, size_t size)
426 {
427         struct cm36672p_data *data = dev_get_drvdata(dev);
428         bool new_value;
429         int pre_enable;
430
431         if (sysfs_streq(buf, "1"))
432                 new_value = true;
433         else if (sysfs_streq(buf, "0"))
434                 new_value = false;
435         else {
436                 pr_err("%s, invalid value %d\n", __func__, *buf);
437                 return -EINVAL;
438         }
439
440         pre_enable = atomic_read(&data->enable);
441         pr_info("%s, new_value = %d, pre_enable = %d\n",
442                 __func__, new_value, pre_enable);
443
444         if (new_value && !pre_enable) {
445                 int i, ret;
446
447                 atomic_set(&data->enable, ON);
448 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
449                 leden_gpio_onoff(data, ON);
450 #endif
451 #ifdef PROXIMITY_CANCELATION
452                 /* open cancelation data */
453                 ret = proximity_open_cancelation(data);
454                 if (ret < 0 && ret != -ENOENT)
455                         pr_err("%s, proximity_open_cancelation() failed\n",
456                                 __func__);
457 #endif
458                 /* enable settings */
459                 for (i = 0; i < PS_REG_NUM; i++) {
460                         cm36672p_i2c_write_word(data,
461                                 ps_reg_init_setting[i][REG_ADDR],
462                                 ps_reg_init_setting[i][CMD]);
463                 }
464
465                 /* 0 is close, 1 is far */
466                 input_report_abs(data->proximity_input_dev, ABS_DISTANCE, 1);
467                 input_sync(data->proximity_input_dev);
468
469                 enable_irq(data->irq);
470                 enable_irq_wake(data->irq);
471         } else if (!new_value && pre_enable) {
472                 disable_irq_wake(data->irq);
473                 disable_irq(data->irq);
474                 /* disable settings */
475                 cm36672p_i2c_write_word(data, REG_PS_CONF1, 0x0001);
476 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
477                 leden_gpio_onoff(data, OFF);
478 #endif
479                 atomic_set(&data->enable, OFF);
480         }
481         pr_info("%s, enable = %d\n", __func__, atomic_read(&data->enable));
482
483         return size;
484 }
485
486 static ssize_t proximity_enable_show(struct device *dev,
487         struct device_attribute *attr, char *buf)
488 {
489         struct cm36672p_data *data = dev_get_drvdata(dev);
490
491         return snprintf(buf, PAGE_SIZE, "%d\n",
492                 atomic_read(&data->enable));
493 }
494
495 static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR | S_IWGRP,
496         proximity_enable_show, proximity_enable_store);
497
498 static struct attribute *proximity_sysfs_attrs[] = {
499         &dev_attr_enable.attr,
500         NULL
501 };
502
503 static struct attribute_group proximity_attribute_group = {
504         .attrs = proximity_sysfs_attrs,
505 };
506
507 /* proximity sysfs */
508 static ssize_t proximity_avg_show(struct device *dev,
509         struct device_attribute *attr, char *buf)
510 {
511         struct cm36672p_data *data = dev_get_drvdata(dev);
512
513         return snprintf(buf, PAGE_SIZE, "%d,%d,%d\n", data->avg[0],
514                 data->avg[1], data->avg[2]);
515 }
516
517 static ssize_t proximity_avg_store(struct device *dev,
518         struct device_attribute *attr, const char *buf, size_t size)
519 {
520         struct cm36672p_data *data = dev_get_drvdata(dev);
521         bool new_value = false;
522
523         if (sysfs_streq(buf, "1"))
524                 new_value = true;
525         else if (sysfs_streq(buf, "0"))
526                 new_value = false;
527         else {
528                 pr_err("%s, invalid value %d\n", __func__, *buf);
529                 return -EINVAL;
530         }
531
532         pr_info("%s, average enable = %d\n", __func__, new_value);
533         if (new_value) {
534                 if (atomic_read(&data->enable) == OFF) {
535 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
536                         leden_gpio_onoff(data, ON);
537 #endif
538                         cm36672p_i2c_write_word(data, REG_PS_CONF1,
539                                 ps_reg_init_setting[PS_CONF1][CMD]);
540                 }
541                 hrtimer_start(&data->prox_timer, data->prox_poll_delay,
542                         HRTIMER_MODE_REL);
543         } else if (!new_value) {
544                 hrtimer_cancel(&data->prox_timer);
545                 cancel_work_sync(&data->work_prox);
546                 if (atomic_read(&data->enable) == OFF) {
547                         cm36672p_i2c_write_word(data, REG_PS_CONF1,
548                                 0x0001);
549 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
550                         leden_gpio_onoff(data, OFF);
551 #endif
552                 }
553         }
554
555         return size;
556 }
557
558 static ssize_t proximity_trim_show(struct device *dev,
559         struct device_attribute *attr, char *buf)
560 {
561         struct cm36672p_data *data = dev_get_drvdata(dev);
562
563         return snprintf(buf, PAGE_SIZE, "%u\n",
564                 data->pdata->default_trim);
565 }
566
567 static ssize_t proximity_thresh_high_show(struct device *dev,
568         struct device_attribute *attr, char *buf)
569 {
570         pr_info("%s = %u,%u\n", __func__,
571                 ps_reg_init_setting[PS_THD_HIGH][CMD],
572                 ps_reg_init_setting[PS_THD_LOW][CMD]);
573         return snprintf(buf, PAGE_SIZE, "%u,%u\n",
574                 ps_reg_init_setting[PS_THD_HIGH][CMD],
575                 ps_reg_init_setting[PS_THD_LOW][CMD]);
576 }
577
578 static ssize_t proximity_thresh_high_store(struct device *dev,
579         struct device_attribute *attr, const char *buf, size_t size)
580 {
581         struct cm36672p_data *data = dev_get_drvdata(dev);
582         u16 thresh_value = ps_reg_init_setting[PS_THD_HIGH][CMD];
583         int err;
584
585         err = kstrtou16(buf, 10, &thresh_value);
586         if (err < 0)
587                 pr_err("%s, kstrtoint failed.\n", __func__);
588
589         if (thresh_value > 2) {
590                 ps_reg_init_setting[PS_THD_HIGH][CMD] = thresh_value;
591                 err = cm36672p_i2c_write_word(data, REG_PS_THD_HIGH,
592                         ps_reg_init_setting[PS_THD_HIGH][CMD]);
593                 if (err < 0)
594                         pr_err("%s, cm36672_ps_high_reg is failed. %d\n",
595                                 __func__, err);
596                 pr_info("%s, new high threshold = 0x%x\n",
597                         __func__, thresh_value);
598                 msleep(150);
599         } else
600                 pr_err("%s, wrong high threshold value(0x%x)!!\n",
601                         __func__, thresh_value);
602
603         return size;
604 }
605
606 static ssize_t proximity_thresh_low_show(struct device *dev,
607         struct device_attribute *attr, char *buf)
608 {
609         pr_info("%s = %u,%u\n", __func__,
610                 ps_reg_init_setting[PS_THD_HIGH][CMD],
611                 ps_reg_init_setting[PS_THD_LOW][CMD]);
612
613         return snprintf(buf, PAGE_SIZE, "%u,%u\n",
614                 ps_reg_init_setting[PS_THD_HIGH][CMD],
615                 ps_reg_init_setting[PS_THD_LOW][CMD]);
616 }
617
618 static ssize_t proximity_thresh_low_store(struct device *dev,
619         struct device_attribute *attr, const char *buf, size_t size)
620 {
621         struct cm36672p_data *data = dev_get_drvdata(dev);
622         u16 thresh_value = ps_reg_init_setting[PS_THD_LOW][CMD];
623         int err;
624
625         err = kstrtou16(buf, 10, &thresh_value);
626         if (err < 0)
627                 pr_err("%s, kstrtoint failed.", __func__);
628
629         if (thresh_value > 2) {
630                 ps_reg_init_setting[PS_THD_LOW][CMD] = thresh_value;
631                 err = cm36672p_i2c_write_word(data, REG_PS_THD_LOW,
632                         ps_reg_init_setting[PS_THD_LOW][CMD]);
633                 if (err < 0)
634                         pr_err("%s, cm36672_ps_low_reg is failed. %d\n",
635                                 __func__, err);
636                 pr_info("%s, new low threshold = 0x%x\n",
637                         __func__, thresh_value);
638                 msleep(150);
639         } else
640                 pr_err("%s, wrong low threshold value(0x%x)!!\n",
641                         __func__, thresh_value);
642
643         return size;
644 }
645
646 static ssize_t proximity_state_show(struct device *dev,
647         struct device_attribute *attr, char *buf)
648 {
649         struct cm36672p_data *data = dev_get_drvdata(dev);
650         u16 ps_data;
651
652         if (atomic_read(&data->enable) == OFF) {
653 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
654                 leden_gpio_onoff(data, ON);
655 #endif
656                 cm36672p_i2c_write_word(data, REG_PS_CONF1,
657                         ps_reg_init_setting[PS_CONF1][CMD]);
658         }
659
660         mutex_lock(&data->read_lock);
661         cm36672p_i2c_read_word(data, REG_PS_DATA, &ps_data);
662         mutex_unlock(&data->read_lock);
663
664         if (atomic_read(&data->enable) == OFF) {
665                 cm36672p_i2c_write_word(data, REG_PS_CONF1, 0x0001);
666 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
667                 leden_gpio_onoff(data, OFF);
668 #endif
669         }
670
671         return snprintf(buf, PAGE_SIZE, "%u\n", ps_data);
672 }
673
674 /* sysfs for vendor & name */
675 static ssize_t cm36672p_vendor_show(struct device *dev,
676         struct device_attribute *attr, char *buf)
677 {
678         return snprintf(buf, PAGE_SIZE, "%s\n", VENDOR);
679 }
680
681 static ssize_t cm36672p_name_show(struct device *dev,
682         struct device_attribute *attr, char *buf)
683 {
684         return snprintf(buf, PAGE_SIZE, "%s\n", CHIP_ID);
685 }
686
687
688 #ifdef PROXIMITY_CANCELATION
689 static DEVICE_ATTR(prox_cal, S_IRUGO | S_IWUSR | S_IWGRP,
690         proximity_cancel_show, proximity_cancel_store);
691 static DEVICE_ATTR(prox_offset_pass, S_IRUGO, proximity_cancel_pass_show,
692         NULL);
693 #endif
694 static DEVICE_ATTR(prox_avg, S_IRUGO | S_IWUSR | S_IWGRP,
695         proximity_avg_show, proximity_avg_store);
696 static DEVICE_ATTR(prox_trim, S_IRUSR | S_IRGRP,
697         proximity_trim_show, NULL);
698 static DEVICE_ATTR(thresh_high, S_IRUGO | S_IWUSR | S_IWGRP,
699         proximity_thresh_high_show, proximity_thresh_high_store);
700 static DEVICE_ATTR(thresh_low, S_IRUGO | S_IWUSR | S_IWGRP,
701         proximity_thresh_low_show, proximity_thresh_low_store);
702 static DEVICE_ATTR(state, S_IRUGO, proximity_state_show, NULL);
703 static DEVICE_ATTR(raw_data, S_IRUGO, proximity_state_show, NULL);
704 static DEVICE_ATTR(vendor, S_IRUSR | S_IRGRP, cm36672p_vendor_show, NULL);
705 static DEVICE_ATTR(name, S_IRUSR | S_IRGRP, cm36672p_name_show, NULL);
706
707 static struct device_attribute *prox_sensor_attrs[] = {
708 #ifdef PROXIMITY_CANCELATION
709         &dev_attr_prox_cal,
710         &dev_attr_prox_offset_pass,
711 #endif
712         &dev_attr_prox_avg,
713         &dev_attr_prox_trim,
714         &dev_attr_thresh_high,
715         &dev_attr_thresh_low,
716         &dev_attr_state,
717         &dev_attr_raw_data,
718         &dev_attr_vendor,
719         &dev_attr_name,
720         NULL,
721 };
722
723 /* interrupt happened due to transition/change of near/far proximity state */
724 irqreturn_t proximity_irq_thread_fn(int irq, void *user_data)
725 {
726         struct cm36672p_data *data = user_data;
727         u8 val;
728         u16 ps_data = 0;
729         int enabled;
730 #ifdef CM36672P_DEBUG
731         static int count;
732         pr_info("%s\n", __func__);
733 #endif
734
735         enabled = atomic_read(&data->enable);
736         val = gpio_get_value(data->pdata->irq);
737         cm36672p_i2c_read_word(data, REG_PS_DATA, &ps_data);
738 #ifdef CM36672P_DEBUG
739         pr_info("%s, enabled = %d, count = %d\n", __func__, enabled, count++);
740 #endif
741
742         if (enabled) {
743                 /* 0 is close, 1 is far */
744                 input_report_abs(data->proximity_input_dev, ABS_DISTANCE,
745                         val);
746                 input_sync(data->proximity_input_dev);
747         }
748
749         wake_lock_timeout(&data->prx_wake_lock, 3 * HZ);
750
751         pr_info("%s, val = %u, ps_data = %u (close:0, far:1)\n",
752                 __func__, val, ps_data);
753
754         return IRQ_HANDLED;
755 }
756
757 static void proximity_get_avg_val(struct cm36672p_data *data)
758 {
759         int min = 0, max = 0, avg = 0;
760         int i;
761         u16 ps_data = 0;
762
763         for (i = 0; i < PROX_READ_NUM; i++) {
764                 msleep(40);
765                 cm36672p_i2c_read_word(data, REG_PS_DATA,
766                         &ps_data);
767                 avg += ps_data;
768
769                 if (!i)
770                         min = ps_data;
771                 else if (ps_data < min)
772                         min = ps_data;
773
774                 if (ps_data > max)
775                         max = ps_data;
776         }
777         avg /= PROX_READ_NUM;
778
779         data->avg[0] = min;
780         data->avg[1] = avg;
781         data->avg[2] = max;
782 }
783
784 static void cm36672_work_func_prox(struct work_struct *work)
785 {
786         struct cm36672p_data *data = container_of(work,
787                 struct cm36672p_data, work_prox);
788         proximity_get_avg_val(data);
789 }
790
791 static enum hrtimer_restart cm36672_prox_timer_func(struct hrtimer *timer)
792 {
793         struct cm36672p_data *data = container_of(timer,
794                 struct cm36672p_data, prox_timer);
795         queue_work(data->prox_wq, &data->work_prox);
796         hrtimer_forward_now(&data->prox_timer, data->prox_poll_delay);
797         return HRTIMER_RESTART;
798 }
799
800 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
801 static int setup_leden_gpio(struct cm36672p_data *data)
802 {
803         int ret;
804         struct cm36672p_platform_data *pdata = data->pdata;
805
806         ret = gpio_request(pdata->leden_gpio, "prox_en");
807         if (ret < 0)
808                 pr_err("%s, gpio %d request failed (%d)\n",
809                         __func__, pdata->leden_gpio, ret);
810
811         ret = gpio_direction_output(pdata->leden_gpio, 1);
812         if (ret)
813                 pr_err("%s: unable to set_direction for prox_en [%d]\n",
814                         __func__, pdata->leden_gpio);
815
816         return ret;
817 }
818 #endif
819
820 static int setup_reg_cm36672p(struct cm36672p_data *data)
821 {
822         int ret, i;
823         u16 tmp;
824
825         /* PS initialization */
826         for (i = 0; i < PS_REG_NUM; i++) {
827                 ret = cm36672p_i2c_write_word(data,
828                         ps_reg_init_setting[i][REG_ADDR],
829                         ps_reg_init_setting[i][CMD]);
830                 if (ret < 0) {
831                         pr_err("%s, cm36672_ps_reg is failed. %d\n",
832                                 __func__, ret);
833                         return ret;
834                 }
835         }
836
837         /* printing the inital proximity value with no contact */
838         msleep(50);
839         mutex_lock(&data->read_lock);
840         ret = cm36672p_i2c_read_word(data, REG_PS_DATA, &tmp);
841         mutex_unlock(&data->read_lock);
842         if (ret < 0) {
843                 pr_err("%s, read ps_data failed\n", __func__);
844                 ret = -EIO;
845         }
846
847         /* turn off */
848         cm36672p_i2c_write_word(data, REG_PS_CONF1, 0x0001);
849         cm36672p_i2c_write_word(data, REG_PS_CONF3, 0x0000);
850
851         return ret;
852 }
853
854
855 static int setup_irq_cm36672p(struct cm36672p_data *data)
856 {
857         int ret;
858         struct cm36672p_platform_data *pdata = data->pdata;
859
860         ret = gpio_request(pdata->irq, "gpio_proximity_out");
861         if (ret < 0) {
862                 pr_err("%s, gpio %d request failed (%d)\n",
863                         __func__, pdata->irq, ret);
864                 return ret;
865         }
866
867         ret = gpio_direction_input(pdata->irq);
868         if (ret < 0) {
869                 pr_err("%s, failed to set gpio %d as input (%d)\n",
870                         __func__, pdata->irq, ret);
871                 gpio_free(pdata->irq);
872                 return ret;
873         }
874
875         data->irq = gpio_to_irq(pdata->irq);
876         ret = request_threaded_irq(data->irq, NULL, proximity_irq_thread_fn,
877                 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
878                 "proximity_int", data);
879         if (ret < 0) {
880                 pr_err("%s: request_irq(%d) failed for gpio %d (%d)\n",
881                         __func__, data->irq, pdata->irq, ret);
882                 gpio_free(pdata->irq);
883                 return ret;
884         }
885
886         /* start with interrupts disabled */
887         disable_irq(data->irq);
888
889         return ret;
890 }
891
892
893 static int proximity_regulator_onoff(struct device *dev, bool onoff)
894 {
895         struct regulator *led_vdd;
896         /* struct regulator *vio;*/
897         int ret;
898
899         pr_info("%s %s\n", __func__, (onoff) ? "on" : "off");
900
901         led_vdd = devm_regulator_get(dev, "cm36672p,vdd");
902         if (IS_ERR(led_vdd)) {
903                 pr_err("%s, cannot get led_vdd\n", __func__);
904                 return -ENOMEM;
905         } else if (!regulator_get_voltage(led_vdd)) {
906                 regulator_set_voltage(led_vdd, 3300000, 3300000);
907         }
908
909
910         if (onoff) {
911                 ret = regulator_enable(led_vdd);
912                 if (ret) {
913                         pr_err("%s: Failed to enable led_vdd.\n", __func__);
914                         return ret;
915                 }
916         } else {
917                 ret = regulator_disable(led_vdd);
918                 if (ret) {
919                         pr_err("%s: Failed to disable led_vdd.\n", __func__);
920                         return ret;
921                 }
922         }
923
924         devm_regulator_put(led_vdd);
925         msleep(20);
926
927         return 0;
928 }
929
930
931 #ifdef CONFIG_OF
932 /* device tree parsing function */
933 static int cm36672p_parse_dt(struct device *dev,
934         struct cm36672p_platform_data *pdata)
935 {
936         struct device_node *np = dev->of_node;
937         enum of_gpio_flags flags;
938         int ret;
939         u32 temp;
940
941 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
942         pdata->leden_gpio = of_get_named_gpio_flags(np, "cm36672p,leden_gpio",
943                 0, &flags);
944         if (pdata->leden_gpio < 0) {
945                 pr_err("%s, get prox_leden_gpio error\n", __func__);
946                 return -ENODEV;
947         }
948 #endif
949
950         pdata->irq = of_get_named_gpio_flags(np, "cm36672p,irq_gpio", 0,
951                 &flags);
952         if (pdata->irq < 0) {
953                 pr_err("%s, get prox_int error\n", __func__);
954                 return -ENODEV;
955         }
956
957         ret = of_property_read_u32(np, "cm36672p,default_hi_thd",
958                 &pdata->default_hi_thd);
959         if (ret < 0) {
960                 pr_err("%s, Cannot set default_hi_thd\n", __func__);
961                 pdata->default_hi_thd = DEFAULT_HI_THD;
962         }
963
964         ret = of_property_read_u32(np, "cm36672p,default_low_thd",
965                 &pdata->default_low_thd);
966         if (ret < 0) {
967                 pr_err("%s, Cannot set default_low_thd\n", __func__);
968                 pdata->default_low_thd = DEFAULT_LOW_THD;
969         }
970
971         ret = of_property_read_u32(np, "cm36672p,cancel_hi_thd",
972                 &pdata->cancel_hi_thd);
973         if (ret < 0) {
974                 pr_err("%s, Cannot set cancel_hi_thd\n", __func__);
975                 pdata->cancel_hi_thd = CANCEL_HI_THD;
976         }
977
978         ret = of_property_read_u32(np, "cm36672p,cancel_low_thd",
979                 &pdata->cancel_low_thd);
980         if (ret < 0) {
981                 pr_err("%s, Cannot set cancel_low_thd\n", __func__);
982                 ps_reg_init_setting[PS_THD_LOW][CMD] = CANCEL_LOW_THD;
983         }
984
985         ret = of_property_read_u32(np, "cm36672p,ps_it", &temp);
986         if (ret < 0) {
987                 pr_err("%s, Cannot set ps_it\n", __func__);
988                 ps_reg_init_setting[PS_CONF1][CMD] = DEFAULT_CONF1;
989         } else {
990                 temp = temp << 1;
991                 ps_reg_init_setting[PS_CONF1][CMD] |= temp;
992         }
993
994         ret = of_property_read_u32(np, "cm36672p,led_current", &temp);
995         if (ret < 0) {
996                 pr_err("%s, Cannot set led_current\n", __func__);
997                 ps_reg_init_setting[PS_CONF3][CMD] = DEFAULT_CONF3;
998         } else {
999                 temp = temp << 8;
1000                 ps_reg_init_setting[PS_CONF3][CMD] |= temp;
1001         }
1002
1003         ret = of_property_read_u32(np, "cm36672p,default_trim",
1004                 &pdata->default_trim);
1005         if (ret < 0) {
1006                 pr_err("%s, Cannot set default_trim\n", __func__);
1007                 pdata->default_trim = DEFAULT_TRIM;
1008         }
1009         ps_reg_init_setting[PS_THD_LOW][CMD] = pdata->default_low_thd;
1010         ps_reg_init_setting[PS_THD_HIGH][CMD] = pdata->default_hi_thd;
1011         ps_reg_init_setting[PS_CANCEL][CMD] = pdata->default_trim;
1012
1013         return 0;
1014 }
1015 #else
1016 static int cm36672p_parse_dt(struct device *dev, struct cm36672p_platform_data)
1017 {
1018         return -ENODEV;
1019 }
1020 #endif
1021
1022 static int cm36672p_i2c_probe(struct i2c_client *client,
1023         const struct i2c_device_id *id)
1024 {
1025         int ret;
1026         struct cm36672p_data *data = NULL;
1027         struct cm36672p_platform_data *pdata = NULL;
1028
1029         pr_info("%s, Probe Start!\n", __func__);
1030         if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1031                 pr_err("%s, i2c functionality check failed!\n",
1032                         __func__);
1033                 return -ENODEV;
1034         }
1035
1036         data = kzalloc(sizeof(struct cm36672p_data), GFP_KERNEL);
1037         if (!data) {
1038                 pr_err("%s, failed to alloc memory for RGB sensor module data\n",
1039                         __func__);
1040                 return -ENOMEM;
1041         }
1042
1043         if (client->dev.of_node) {
1044                 pdata = devm_kzalloc(&client->dev,
1045                 sizeof(struct cm36672p_platform_data), GFP_KERNEL);
1046                 if (!pdata) {
1047                         dev_err(&client->dev, "Failed to allocate memory\n");
1048                         ret = -ENOMEM;
1049                         goto exit;
1050                 }
1051                 ret = cm36672p_parse_dt(&client->dev, pdata);
1052                 if (ret)
1053                         goto exit;
1054         } else
1055                 pdata = client->dev.platform_data;
1056
1057         if (!pdata) {
1058                 pr_err("%s, missing pdata!\n", __func__);
1059                 ret = -ENOMEM;
1060                 goto exit;
1061         }
1062
1063         data->pdata = pdata;
1064         data->i2c_client = client;
1065         i2c_set_clientdata(client, data);
1066
1067         mutex_init(&data->read_lock);
1068         /* wake lock init for proximity sensor */
1069         wake_lock_init(&data->prx_wake_lock, WAKE_LOCK_SUSPEND,
1070                 "prx_wake_lock");
1071
1072         proximity_regulator_onoff(&client->dev, ON);
1073
1074 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
1075         /* setup led_en_gpio */
1076         ret = setup_leden_gpio(data);
1077         if (ret) {
1078                 pr_err("%s, could not setup leden_gpio\n", __func__);
1079                 goto err_setup_leden_gpio;
1080         }
1081         leden_gpio_onoff(data, ON);
1082 #endif
1083
1084         /* Check if the device is there or not. */
1085         ret = cm36672p_i2c_write_word(data, REG_PS_CONF1, 0x0001);
1086         if (ret < 0) {
1087                 pr_err("%s, cm36672 is not connected.(%d)\n", __func__,
1088                         ret);
1089                 goto err_setup_dev;
1090         }
1091
1092         /* setup initial registers */
1093         ret = setup_reg_cm36672p(data);
1094         if (ret < 0) {
1095                 pr_err("%s, could not setup regs\n", __func__);
1096                 goto err_setup_dev;
1097         }
1098
1099 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
1100         leden_gpio_onoff(data, OFF);
1101 #endif
1102
1103         /* allocate proximity input_device */
1104         data->proximity_input_dev = input_allocate_device();
1105         if (!data->proximity_input_dev) {
1106                 pr_err("%s, could not allocate proximity input device\n",
1107                         __func__);
1108                 goto err_input_alloc_device;
1109         }
1110
1111         input_set_drvdata(data->proximity_input_dev, data);
1112         data->proximity_input_dev->name = "proximity_sensor";
1113         input_set_capability(data->proximity_input_dev, EV_ABS,
1114                 ABS_DISTANCE);
1115         input_set_abs_params(data->proximity_input_dev, ABS_DISTANCE, 0, 1,
1116                 0, 0);
1117
1118         ret = input_register_device(data->proximity_input_dev);
1119         if (ret < 0) {
1120                 pr_err("%s, could not register input device\n",
1121                         __func__);
1122                 goto err_input_register_device;
1123         }
1124
1125         ret = sensors_create_symlink(&data->proximity_input_dev->dev.kobj,
1126                 data->proximity_input_dev->name);
1127         if (ret < 0) {
1128                 pr_err("%s, create_symlink error\n", __func__);
1129                 goto err_sensors_create_symlink_prox;
1130         }
1131
1132         ret = sysfs_create_group(&data->proximity_input_dev->dev.kobj,
1133                 &proximity_attribute_group);
1134         if (ret) {
1135                 pr_err("%s, could not create sysfs group\n", __func__);
1136                 goto err_sysfs_create_group_proximity;
1137         }
1138
1139         /* setup irq */
1140         ret = setup_irq_cm36672p(data);
1141         if (ret) {
1142                 pr_err("%s, could not setup irq\n", __func__);
1143                 goto err_setup_irq;
1144         }
1145
1146         /* For factory test mode, we use timer to get average proximity data. */
1147         /* prox_timer settings. we poll for light values using a timer. */
1148         hrtimer_init(&data->prox_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
1149         data->prox_poll_delay = ns_to_ktime(2000 * NSEC_PER_MSEC);/*2 sec*/
1150         data->prox_timer.function = cm36672_prox_timer_func;
1151
1152         /* the timer just fires off a work queue request.  we need a thread
1153            to read the i2c (can be slow and blocking). */
1154         data->prox_wq = create_singlethread_workqueue("cm36672_prox_wq");
1155         if (!data->prox_wq) {
1156                 ret = -ENOMEM;
1157                 pr_err("%s, could not create prox workqueue\n",
1158                         __func__);
1159                 goto err_create_prox_workqueue;
1160         }
1161         /* this is the thread function we run on the work queue */
1162         INIT_WORK(&data->work_prox, cm36672_work_func_prox);
1163
1164         /* set sysfs for proximity sensor */
1165         ret = sensors_register(data->proximity_dev,
1166                 data, prox_sensor_attrs,
1167                         "proximity_sensor");
1168         if (ret) {
1169                 pr_err("%s, cound not register proximity sensor device(%d).\n",
1170                         __func__, ret);
1171                 goto prox_sensor_register_failed;
1172         }
1173
1174 #if defined(CONFIG_MACH_J1_VZW) || defined(CONFIG_MACH_E5_USA_TFN)
1175         proximity_regulator_onoff(&client->dev, OFF);
1176 #endif
1177
1178         pr_info("%s is success.\n", __func__);
1179         return ret;
1180
1181 /* error, unwind it all */
1182 prox_sensor_register_failed:
1183         destroy_workqueue(data->prox_wq);
1184 err_create_prox_workqueue:
1185         free_irq(data->irq, data);
1186         gpio_free(data->pdata->irq);
1187 err_setup_irq:
1188         sysfs_remove_group(&data->proximity_input_dev->dev.kobj,
1189                 &proximity_attribute_group);
1190 err_sysfs_create_group_proximity:
1191         sensors_remove_symlink(&data->proximity_input_dev->dev.kobj,
1192                 data->proximity_input_dev->name);
1193 err_sensors_create_symlink_prox:
1194         input_unregister_device(data->proximity_input_dev);
1195 err_input_register_device:
1196         input_free_device(data->proximity_input_dev);
1197 err_input_alloc_device:
1198 err_setup_dev:
1199 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
1200         leden_gpio_onoff(data, OFF);
1201         gpio_free(data->pdata->leden_gpio);
1202 err_setup_leden_gpio:
1203 #endif
1204         wake_lock_destroy(&data->prx_wake_lock);
1205         mutex_destroy(&data->read_lock);
1206         proximity_regulator_onoff(&client->dev, OFF);
1207 exit:
1208         kfree(data);
1209
1210         pr_err("%s is FAILED (%d)\n", __func__, ret);
1211         return ret;
1212 }
1213
1214 static int cm36672p_i2c_remove(struct i2c_client *client)
1215 {
1216         struct cm36672p_data *data = i2c_get_clientdata(client);
1217
1218         /* free irq */
1219         if (atomic_read(&data->enable)) {
1220                 disable_irq_wake(data->irq);
1221                 disable_irq(data->irq);
1222         }
1223         free_irq(data->irq, data);
1224         gpio_free(data->pdata->irq);
1225
1226         /* device off */
1227         if (atomic_read(&data->enable))
1228                 cm36672p_i2c_write_word(data, REG_PS_CONF1,
1229                         0x0001);
1230
1231         /* destroy workqueue */
1232         destroy_workqueue(data->prox_wq);
1233
1234         /* sysfs destroy */
1235         sensors_unregister(data->proximity_dev, prox_sensor_attrs);
1236         sensors_remove_symlink(&data->proximity_input_dev->dev.kobj,
1237                 data->proximity_input_dev->name);
1238
1239         /* input device destroy */
1240         sysfs_remove_group(&data->proximity_input_dev->dev.kobj,
1241                 &proximity_attribute_group);
1242         input_unregister_device(data->proximity_input_dev);
1243
1244 #if defined(CONFIG_SENSORS_LEDA_EN_GPIO)
1245         leden_gpio_onoff(data, OFF);
1246         gpio_free(data->pdata->leden_gpio);
1247 #endif
1248
1249         /* lock destroy */
1250         mutex_destroy(&data->read_lock);
1251         wake_lock_destroy(&data->prx_wake_lock);
1252
1253         kfree(data);
1254 #ifndef CONFIG_MACH_J1_VZW
1255         proximity_regulator_onoff(&client->dev, OFF);
1256 #endif
1257
1258         return 0;
1259 }
1260
1261 static int cm36672p_suspend(struct device *dev)
1262 {
1263         pr_info("%s is called.\n", __func__);
1264         return 0;
1265 }
1266
1267 static int cm36672p_resume(struct device *dev)
1268 {
1269         pr_info("%s is called.\n", __func__);
1270         return 0;
1271 }
1272
1273 #ifdef CONFIG_OF
1274 static struct of_device_id cm36672p_match_table[] = {
1275         { .compatible = "cm36672p",},
1276         {},
1277 };
1278 #else
1279 #define cm36672p_match_table NULL
1280 #endif
1281
1282
1283 static const struct i2c_device_id cm36672p_device_id[] = {
1284         {"cm36672p", 0},
1285         {}
1286 };
1287
1288 MODULE_DEVICE_TABLE(i2c, cm36672p_device_id);
1289
1290 static const struct dev_pm_ops cm36672p_pm_ops = {
1291         .suspend = cm36672p_suspend,
1292         .resume = cm36672p_resume
1293 };
1294
1295 static struct i2c_driver cm36672p_i2c_driver = {
1296         .driver = {
1297                    .name = "cm36672p",
1298                    .owner = THIS_MODULE,
1299                    .of_match_table = cm36672p_match_table,
1300                    .pm = &cm36672p_pm_ops
1301         },
1302         .probe = cm36672p_i2c_probe,
1303         .remove = cm36672p_i2c_remove,
1304         .id_table = cm36672p_device_id,
1305 };
1306
1307 static int __init cm36672p_init(void)
1308 {
1309         return i2c_add_driver(&cm36672p_i2c_driver);
1310 }
1311
1312 static void __exit cm36672p_exit(void)
1313 {
1314         i2c_del_driver(&cm36672p_i2c_driver);
1315 }
1316
1317 module_init(cm36672p_init);
1318 module_exit(cm36672p_exit);
1319
1320 MODULE_AUTHOR("Samsung Electronics");
1321 MODULE_DESCRIPTION("Proximity Sensor device driver for CM36672P");
1322 MODULE_LICENSE("GPL");