]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - drivers/staging/iio/light/iqs253.c
staging: iio: light: iqs253: tune iqs263
[sojka/nv-tegra/linux-3.10.git] / drivers / staging / iio / light / iqs253.c
1 /*
2  * A iio driver for the capacitive sensor IQS253.
3  *
4  * IIO Light driver for monitoring proximity.
5  *
6  * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms and conditions of the GNU General Public License,
10  * version 2, as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  * more details.
16  */
17
18 #include <linux/module.h>
19 #include <linux/i2c.h>
20 #include <linux/err.h>
21 #include <linux/mutex.h>
22 #include <linux/pm_runtime.h>
23 #include <linux/regulator/consumer.h>
24 #include <linux/platform_device.h>
25 #include <linux/gpio.h>
26 #include <linux/of_gpio.h>
27 #include <linux/slab.h>
28 #include <linux/delay.h>
29 #include <linux/irqchip/tegra.h>
30 #include <linux/input.h>
31 #include <linux/iio/iio.h>
32 #include <linux/iio/sysfs.h>
33 #include <linux/iio/light/ls_sysfs.h>
34 #include <linux/iio/light/ls_dt.h>
35
36 /* registers */
37 #define SYSFLAGS                0x10
38 #define PROX_STATUS             0x31
39 #define TOUCH_STATUS            0x35
40 #define TARGET                  0xC4
41 #define COMP0                   0xC5
42 #define CH0_ATI_BASE            0xC8
43 #define CH1_ATI_BASE            0xC9
44 #define CH2_ATI_BASE            0xCA
45 #define CH0_PTH                 0xCB
46 #define CH1_PTH                 0xCC
47 #define CH2_PTH                 0xCD
48 #define PROX_SETTINGS0          0xD1
49 #define PROX_SETTINGS1          0xD2
50 #define PROX_SETTINGS2          0xD3
51 #define PROX_SETTINGS3          0xD4
52 #define ACTIVE_CHAN             0xD5
53 #define LOW_POWER               0xD6
54 #define DYCAL_CHANS             0xD8
55 #define EVENT_MODE_MASK         0xD9
56 #define DEFAULT_COMMS_POINTER   0xDD
57
58 #define IQS253_PROD_ID          41
59 #define IQS263_PROD_ID          0x3C
60
61 #define PROX_CH0                0x01
62 #define PROX_CH1                0x02
63 #define PROX_CH2                0x04
64
65 #define STYLUS_ONLY             PROX_CH0
66 #define PROXIMITY_ONLY          (PROX_CH1 | PROX_CH2)
67
68 #define CH0_COMPENSATION        0x55
69
70 #define PROX_TH_CH0             0x03
71 #define PROX_TH_CH1             0x03
72 #define PROX_TH_CH2             0x03
73
74 #define DISABLE_DYCAL           0x00
75
76 #define CH0_ATI_TH              0xCC
77 #define CH1_ATI_TH              0x40
78 #define CH2_ATI_TH              0x40
79
80 #define EVENT_PROX_ONLY         0x01
81
82 #define PROX_SETTING_NORMAL     0x25
83 #define PROX_SETTING_STYLUS     0x26
84
85 #define AUTO_ATI_DISABLE        BIT(7)
86 #define ATI_IN_PROGRESS         0x04
87
88 /* initial values */
89
90 #define EVENT_MODE_DISABLE_MASK 0x04
91 #define LTA_DISABLE             BIT(5)
92 #define ACF_DISABLE             BIT(4)
93 /* LTA always halt */
94 #define LTA_HALT_11             (BIT(0) | BIT(1))
95
96 #define ATI_ENABLED_MASK        0x80
97
98 #define IQS253_RESET            BIT(5)
99
100 #define ATI                     0xAF
101
102 #define NUM_REG 17
103
104
105 /* iqs263 registers and values */
106 #define DEV_INFO     0x00
107 #define SYST_FLAGS   0x01
108 #define CO_NATES     0x02
109 #define TOUCH_STAT   0x03
110 #define COUNTS       0x04
111 #define LTA          0x05
112 #define DELTAS       0x06
113 #define MULTIPLERS   0x07
114 #define COMPENSATION 0x08
115 #define PROX_SETTINGS 0x09
116 #define THRESHOLDS   0x0A
117 #define TIM_TARGETS  0x0B
118 #define GESTURE_TIME 0x0C
119 #define ACTIVE_CH    0x0D
120
121 #define PROX_THR     0x04
122 #define TOUCH_THR1   0x14
123 #define TOUCH_THR2   0x02
124 #define TOUCH_THR3   0x03
125 #define MOV_THR      0x04   /* 0x15 -->0x4 (Enable motion detection) */
126 #define MOV_DEB      0x00
127 #define HALT_TIME    0x30  /* 0xFF -> 0x64(2min) -> 0x30(55sec) --> 0x16 (30 sec) */
128 #define HALT_RESEED  0x00   /* RESEED CMD */
129 #define I2C_TIMEOUT  0x04
130
131 #define SYST_SET     0x80
132 #define CH0_MULT     0x1B
133 #define CH1_MULT     0x08
134 #define CH2_MULT     0x08
135 #define CH3_MULT     0x00
136
137 #define CH_BASE      0x11
138
139 #define PROX_SET0    0x00
140 #define PROX_SET1    0x00
141 #define PROX_SET2    0x00
142 #define PROX_SET3    0x00
143 #define EVENT_MASK   0x00
144
145 #define LP_TIME      0x00
146 #define TARGET_T     0x64    /* set the target of 1000, 0x80 */
147 #define TARGET_P     0x64
148
149 #define TAP_TIM      0x00
150 #define FLICK_TIM    0x00
151 #define FLICK_THR    0x07
152
153 #define IQS263_RESET 0x80
154 #define IQS263_EV_MASK 0x04
155
156 #define ACT_CH0      0x0
157
158
159
160 struct iqs253_chip {
161         struct i2c_client       *client;
162         const struct i2c_device_id      *id;
163         u32                     rdy_gpio;
164         u32                     wake_gpio;
165         u32                     sar_gpio;
166         u32                     version;
167         u32                     value;
168         struct regulator        *vddhi;
169         u32                     using_regulator;
170
171         struct workqueue_struct *sar_wq;
172         struct delayed_work     sar_dw;
173 };
174
175 enum mode {
176         MODE_NONE = -1,
177         INIT_MODE,
178         FORCE_ATI_MODE,
179         POST_INIT_MODE,
180         NUM_MODE
181 };
182
183 struct reg_val_pair {
184         u8 reg;
185         u8 val;
186 };
187
188 struct reg_val_pair reg_val_map_iqs253[NUM_MODE][NUM_REG] = {
189         {       /* init settings */
190                 { ACTIVE_CHAN, PROXIMITY_ONLY},
191                 { CH0_PTH, PROX_TH_CH0},
192                 { CH1_PTH, PROX_TH_CH1},
193                 { CH2_PTH, PROX_TH_CH2},
194                 { TARGET, 0xE6},
195                 { CH1_ATI_BASE, CH1_ATI_TH},
196                 { CH2_ATI_BASE, CH2_ATI_TH},
197                 { PROX_SETTINGS3, 0x05},
198         },
199         {       /* force on ATI */
200                 { PROX_SETTINGS0, 0x57}, /* enable ATI and force auto ATI */
201                 { ATI, 0x0}, /* wait for ATI to finish */
202         },
203         {
204                 { PROX_SETTINGS1, 0x40},
205                 { PROX_SETTINGS2, 0x57},
206         },
207 };
208
209 struct cmd_val_pair {
210         u8 cmd;
211         int len;
212         u8 *vals;
213 };
214
215 static u8 beforeinit_prox_settings[10] = { PROX_SET0 | 0x80, PROX_SET1 | 0x0,
216                                            PROX_SET2 , PROX_SET3 | 0x01,
217                                            EVENT_MASK };
218 static u8 active_ch[] = { ACT_CH0 | 0x05 };
219 static u8 set_thresholds[] = { PROX_THR, TOUCH_THR1, TOUCH_THR2, TOUCH_THR3,
220                                MOV_THR, HALT_RESEED, HALT_TIME, I2C_TIMEOUT };
221 static u8 set_multipliers[] = { CH0_MULT, CH1_MULT, CH2_MULT, CH3_MULT,
222                                  CH_BASE | 0x00};
223 static u8 set_tim_targets[] = { LP_TIME, TARGET_T, TARGET_P };
224 static u8 afterinit_prox_settings[] = { PROX_SET0 | 0x10, PROX_SET1 | 0x02,
225                                         PROX_SET2 | 0x04, PROX_SET3 | 0x05,
226                                         EVENT_MASK };
227 static u8 set_ati[] = {0 };
228
229 struct cmd_val_pair cmd_val_map_iqs263[] = {
230         /* iqs263 init sequence */
231         { PROX_SETTINGS, 5, beforeinit_prox_settings},
232         { ACTIVE_CH, 1, active_ch},
233         { THRESHOLDS, 8, set_thresholds},
234         { MULTIPLERS, 5, set_multipliers},
235         { TIM_TARGETS, 3, set_tim_targets},
236         { PROX_SETTINGS, 5, afterinit_prox_settings},
237         { ATI, 0x0, set_ati}, /* wait for ATI to finish */
238 };
239
240 static void iqs253_detect_comwindow(struct iqs253_chip *chip)
241 {
242         int gpio_count = 10000; /* wait for a maximum of 1 second */
243         while (gpio_get_value(chip->rdy_gpio) && gpio_count--)
244                 usleep_range(100, 110);
245 }
246
247 static int iqs253_i2c_firsthand_shake(struct iqs253_chip *iqs253_chip)
248 {
249         int retry_count = 10;
250         int ret = 0;
251
252         pr_debug("%s :<-- HANDSHAKE START -->\n", __func__);
253
254         do {
255                 gpio_direction_output(iqs253_chip->rdy_gpio, 0);
256                 usleep_range(12 * 1000, 12 * 1000);
257                 /* put to tristate */
258                 gpio_direction_input(iqs253_chip->rdy_gpio);
259                 iqs253_detect_comwindow(iqs253_chip);
260         } while (gpio_get_value(iqs253_chip->rdy_gpio) && retry_count--);
261
262         /* got the window */
263         ret = i2c_smbus_write_byte_data(iqs253_chip->client,
264                                         PROX_SETTINGS2 , 0x17);
265         if (ret)
266                 return ret;
267         usleep_range(1000, 1100);
268
269         pr_debug("%s :<-- HANDSHAKE DONE -->\n", __func__);
270         return 0;
271 }
272
273 static int iqs253_i2c_read_byte(struct iqs253_chip *chip, int reg)
274 {
275         int ret = 0;
276         iqs253_detect_comwindow(chip);
277         ret = i2c_smbus_read_byte_data(chip->client, reg);
278         usleep_range(1000, 1100);
279         return ret;
280 }
281
282 static int iqs253_i2c_write_byte(struct iqs253_chip *chip, int reg, int val)
283 {
284         int ret = 0;
285
286         iqs253_detect_comwindow(chip);
287         ret = i2c_smbus_write_byte_data(chip->client, reg, val);
288         usleep_range(1000, 1100);
289         return ret;
290 }
291
292 static void iqs253_wait_for_ati_finish(struct iqs253_chip *iqs253_chip)
293 {
294         int ret;
295         do {
296                 usleep_range(10 * 1000, 10 * 1000);
297                 ret = iqs253_i2c_read_byte(iqs253_chip, SYSFLAGS);
298         } while (ret & ATI_IN_PROGRESS);
299 }
300
301 /* must call holding lock */
302 static int iqs253_set(struct iqs253_chip *iqs253_chip)
303 {
304         int ret = 0, i, j;
305         struct reg_val_pair *reg_val_pair_map;
306         int modes[NUM_MODE] = {INIT_MODE, FORCE_ATI_MODE, POST_INIT_MODE};
307
308         if (iqs253_chip->version != 253)
309                 return 0;
310
311         for (j = 0; j < NUM_MODE; j++) {
312
313                 if (modes[j] == MODE_NONE)
314                         break;
315
316                 reg_val_pair_map = reg_val_map_iqs253[modes[j]];
317
318                 for (i = 0; i < NUM_REG; i++) {
319                         if (!reg_val_pair_map[i].reg &&
320                             !reg_val_pair_map[i].val)
321                                 continue;
322
323                         if (reg_val_pair_map[i].reg == ATI) {
324                                 iqs253_wait_for_ati_finish(iqs253_chip);
325                                 continue;
326                         }
327
328                         ret = iqs253_i2c_write_byte(iqs253_chip,
329                                                 reg_val_pair_map[i].reg,
330                                                 reg_val_pair_map[i].val);
331                         if (ret) {
332                                 dev_err(&iqs253_chip->client->dev,
333                                         "iqs253 write val:%x to reg:%x fail\n",
334                                         reg_val_pair_map[i].val,
335                                         reg_val_pair_map[i].reg);
336                                 return ret;
337                         }
338                 }
339         }
340         return 0;
341 }
342
343 static int iqs263_i2c_read_bytes(struct iqs253_chip *chip,
344                                   u8 cmd)
345 {
346         int ret = 0;
347
348         iqs253_detect_comwindow(chip);
349         ret = i2c_smbus_read_word_data(chip->client, cmd);
350         if (ret < 0)
351                 pr_err("iqs263 i2c read from %d failed", cmd);
352         usleep_range(1000, 1100);
353         return ret;
354 }
355
356 static void iqs263_wait_for_ati_finish(struct iqs253_chip *iqs253_chip)
357 {
358         int ret;
359
360         do {
361                 iqs253_detect_comwindow(iqs253_chip);
362                 ret = iqs263_i2c_read_bytes(iqs253_chip, SYST_FLAGS);
363         } while (ret & ATI_IN_PROGRESS);
364 }
365
366 /* must call holding lock */
367 static int iqs263_i2c_write_bytes(struct iqs253_chip *chip,
368                                   struct cmd_val_pair *cmd_val)
369 {
370         int ret = 0;
371
372         iqs253_detect_comwindow(chip);
373         ret = i2c_smbus_write_i2c_block_data(chip->client, cmd_val->cmd,
374                                              cmd_val->len, cmd_val->vals);
375         if (ret < 0)
376                 pr_err("iqs263 i2c write to %d failed", cmd_val->cmd);
377         usleep_range(1000, 1100);
378         return ret;
379 }
380
381 static int iqs263_i2c_read_word(struct iqs253_chip *chip, u8 cmd)
382 {
383         int ret = 0;
384         u8 data_buffer[2];
385
386         iqs253_detect_comwindow(chip);
387         ret = i2c_smbus_read_i2c_block_data(chip->client, cmd, 2, data_buffer);
388         if (ret < 0)
389                 pr_err("iqs263 i2c word read  : %d failed", cmd);
390         else
391                 ret = (data_buffer[0] & 0x0f) | ((data_buffer[1] << 8) & 0xF0);
392
393         return ret;
394 }
395
396 /* must call holding lock */
397 static int iqs263_set(struct iqs253_chip *iqs253_chip)
398 {
399         int ret = 0, j;
400         struct cmd_val_pair *cmd_val_pair_map;
401
402         pr_debug("%s :<-- INIT START -->\n", __func__);
403
404         if (iqs253_chip->version != 263)
405                 return 0;
406
407         for (j = 0; j < ARRAY_SIZE(cmd_val_map_iqs263); j++) {
408
409                 cmd_val_pair_map = &cmd_val_map_iqs263[j];
410
411                 if (cmd_val_pair_map->cmd == ATI) {
412                         iqs263_wait_for_ati_finish(iqs253_chip);
413                         continue;
414                 }
415
416                 if (!cmd_val_pair_map->len)
417                         continue;
418
419                 ret = iqs263_i2c_write_bytes(iqs253_chip,
420                                              cmd_val_pair_map);
421                 if (ret)
422                         return ret;
423         }
424
425         pr_debug("%s :<--INIT DONE -->\n", __func__);
426         return 0;
427 }
428
429 static void iqs253_sar_proximity_detect_work(struct work_struct *ws)
430 {
431         int ret;
432         struct iqs253_chip *chip;
433
434         chip = container_of(ws, struct iqs253_chip, sar_dw.work);
435
436         if (!chip->using_regulator) {
437                 ret = regulator_enable(chip->vddhi);
438                 if (ret)
439                         goto finish;
440                 chip->using_regulator = true;
441         }
442
443         if (chip->version == 253) {
444                 ret = iqs253_i2c_read_byte(chip, PROX_STATUS);
445                 if (ret < 0)
446                         return;
447                 /* need to cross check thie */
448                 if (ret & BIT(5)) {
449                         ret = iqs253_set(chip);
450                         if (ret)
451                                 goto finish;
452                 }
453         } else {
454                 /* if this does not work, try ret = iqs263_i2c_read_word, then ret = ret >> 8; then check ret & 0x80*/
455                 ret = iqs263_i2c_read_bytes(chip, 0x03);
456                 if (ret & 0x80) {
457                     #if 0
458                     ret = iqs263_set(chip);
459                     if (ret)
460                         goto finish;
461                     #endif
462                 }
463         }
464
465        if (chip->version == 253) {
466                 ret = iqs253_i2c_read_byte(chip, PROX_STATUS);
467                 chip->value = -1;
468                 if (ret >= 0) {
469                     ret = ret & PROXIMITY_ONLY;
470                 /*
471                  * if both channel detect proximity => distance = 0;
472                  * if one channel detects proximity => distance = 1;
473                  * if no channel detects proximity => distance = 2;
474                  */
475                     chip->value = (ret == (PROX_CH1 | PROX_CH2)) ? 0 :
476                                                         ret ? 1 : 2;
477                 }
478                 if (chip->value == -1)
479                         goto finish;
480                 /* provide input to SAR */
481                 if (chip->value/2) {
482                         /* pr_info("%s :<-- undetect -->\n", __func__); */
483                         gpio_direction_output(chip->sar_gpio, 1);
484                 } else {
485                         /* pr_info("%s :--> detect <--\n", __func__); */
486                         gpio_direction_output(chip->sar_gpio, 0);
487                 }
488        } else {
489                     ret= iqs263_i2c_read_word(chip,0x03);
490                     chip->value = ret;
491                      /* provide input to SAR 0x0c -> 0x4 */
492                      if ((chip->value&0x04) !=0) {
493                         /* pr_info("%s :<-- detect  status: 0x%x -->\n", __func__ , chip->value); */
494                         gpio_direction_output(chip->sar_gpio, 0);
495                      } else {
496                         /* pr_info("%s :--> Undetect Status: 0x%x  <--\n", __func__, chip->value); */
497                         gpio_direction_output(chip->sar_gpio, 1);
498                      }
499        }
500
501         ret = regulator_disable(chip->vddhi);
502         if (ret)
503                 goto finish;
504         chip->using_regulator = false;
505
506 finish:
507         queue_delayed_work(chip->sar_wq, &chip->sar_dw, msecs_to_jiffies(1000));
508 }
509
510 static ssize_t show_proximity_status(struct device * dev,
511         struct device_attribute *attr, char *buf)
512 {
513         struct iio_dev *indio_dev = dev_to_iio_dev(dev);
514         struct iqs253_chip *chip = iio_priv(indio_dev);
515         if (chip->version == 253) {
516                 if (chip->value / 2)
517                         return sprintf(buf, "1"); /* undetect */
518                 return sprintf(buf, "0"); /* detect */
519         } else {
520                 if ((chip->value & 0x04) != 0)
521                         return sprintf(buf, "0"); /* detect */
522                 return sprintf(buf, "1"); /* undetect */
523         }
524         return sprintf(buf, "invalid iqs sensor version..\n");
525 }
526
527 static IIO_CONST_ATTR(name, "iqs_sar_sensor");
528 static IIO_DEVICE_ATTR(proximity_status, S_IRUGO, show_proximity_status,
529                        NULL, 0);
530
531 static struct attribute *iqs253_iio_attr[] = {
532         &iio_dev_attr_proximity_status.dev_attr.attr,
533         &iio_const_attr_name.dev_attr.attr,
534         NULL
535 };
536
537 static const struct attribute_group iqs253_iio_attr_grp = {
538         .attrs = iqs253_iio_attr,
539 };
540
541 static const struct iio_info iqs253_iio_info = {
542         .attrs = &iqs253_iio_attr_grp,
543         .driver_module = THIS_MODULE,
544 };
545
546 static int iqs253_probe(struct i2c_client *client,
547                         const struct i2c_device_id *id)
548 {
549         int ret;
550         struct iqs253_chip *iqs253_chip;
551         struct iio_dev *indio_dev;
552         int rdy_gpio = -1, wake_gpio = -1, sar_gpio = -1;
553
554         rdy_gpio = of_get_named_gpio(client->dev.of_node, "rdy-gpio", 0);
555         if (rdy_gpio == -EPROBE_DEFER)
556                 return -EPROBE_DEFER;
557
558         if (!gpio_is_valid(rdy_gpio))
559                 return -EINVAL;
560
561         wake_gpio = of_get_named_gpio(client->dev.of_node, "wake-gpio", 0);
562         if (wake_gpio == -EPROBE_DEFER)
563                 return -EPROBE_DEFER;
564
565         if (!gpio_is_valid(wake_gpio))
566                 return -EINVAL;
567
568         sar_gpio = of_get_named_gpio(client->dev.of_node, "sar-gpio", 0);
569         if (sar_gpio == -EPROBE_DEFER)
570                 return -EPROBE_DEFER;
571
572         ret = gpio_request_one(sar_gpio, GPIOF_OUT_INIT_LOW, NULL);
573         if (ret < 0)
574                 return -EINVAL;
575
576         indio_dev = iio_device_alloc(sizeof(*iqs253_chip));
577         if (!indio_dev)
578                 return -ENOMEM;
579
580         i2c_set_clientdata(client, indio_dev);
581         iqs253_chip = iio_priv(indio_dev);
582
583         iqs253_chip->client = client;
584         iqs253_chip->id = id;
585         iqs253_chip->vddhi = devm_regulator_get(&client->dev, "vddhi");
586         if (IS_ERR(iqs253_chip->vddhi)) {
587                 dev_err(&client->dev,
588                         "devname:%s func:%s regulator vddhi not found\n",
589                         id->name, __func__);
590                 goto err_regulator_get;
591         }
592
593         ret = gpio_request(rdy_gpio, "iqs253");
594         if (ret) {
595                         dev_err(&client->dev,
596                         "devname:%s func:%s regulator vddhi not found\n",
597                         id->name, __func__);
598                 goto err_gpio_request;
599         }
600         iqs253_chip->rdy_gpio = rdy_gpio;
601         iqs253_chip->wake_gpio = wake_gpio;
602         iqs253_chip->sar_gpio = sar_gpio;
603
604         ret = regulator_enable(iqs253_chip->vddhi);
605         if (ret) {
606                 dev_err(&client->dev,
607                         "devname:%s func:%s regulator enable failed\n",
608                         id->name, __func__);
609                 goto err_gpio_request;
610         }
611         /*
612          * XXX: Do not set using_regulator = true here as
613          * it affects proximity detection
614          */
615
616         ret = iqs253_i2c_read_byte(iqs253_chip, 0);
617         if (ret == IQS253_PROD_ID) {
618                 pr_info("%s :-->Chipid Detected: %d <--\n", __func__, iqs253_chip->version);
619                 iqs253_i2c_firsthand_shake(iqs253_chip);
620                 iqs253_chip->version = 253;
621         } else if (ret == IQS263_PROD_ID) {
622                pr_info("%s :-->Chipid Detected:  %d <--\n", __func__, iqs253_chip->version);
623                 iqs253_chip->version = 263;
624                 ret = iqs263_set(iqs253_chip);
625         } else {
626                 dev_err(&client->dev,
627                         "devname:%s func:%s device not present\n",
628                         id->name, __func__);
629                 goto err_gpio_request;
630         }
631
632         iqs253_chip->sar_wq = create_freezable_workqueue("iqs253_sar");
633         if (!iqs253_chip->sar_wq) {
634                 dev_err(&iqs253_chip->client->dev, "unable to create work queue\n");
635                 goto err_gpio_request;
636         }
637
638         INIT_DELAYED_WORK(&iqs253_chip->sar_dw,
639                                 iqs253_sar_proximity_detect_work);
640
641         queue_delayed_work(iqs253_chip->sar_wq, &iqs253_chip->sar_dw, 0);
642
643         indio_dev->info = &iqs253_iio_info;
644         indio_dev->dev.parent = &client->dev;
645         indio_dev->modes = INDIO_DIRECT_MODE;
646         ret = iio_device_register(indio_dev);
647         if (ret) {
648                 dev_err(&client->dev, "%s iio_device_register err\n", __func__);
649                 goto err_iio_register;
650         }
651
652         dev_info(&client->dev, "devname:%s func:%s line:%d probe success\n",
653                         id->name, __func__, __LINE__);
654
655         return 0;
656
657 err_iio_register:
658 err_gpio_request:
659         if (iqs253_chip->sar_wq)
660                 destroy_workqueue(iqs253_chip->sar_wq);
661 err_regulator_get:
662         iio_device_free(indio_dev);
663
664         dev_err(&client->dev, "devname:%s func:%s line:%d probe failed\n",
665                         id->name, __func__, __LINE__);
666         return ret;
667 }
668
669 static int iqs253_remove(struct i2c_client *client)
670 {
671         struct iio_dev *indio_dev = i2c_get_clientdata(client);
672         struct iqs253_chip *chip = iio_priv(indio_dev);
673         gpio_free(chip->rdy_gpio);
674
675         if (chip->sar_wq)
676                 destroy_workqueue(chip->sar_wq);
677         iio_device_free(indio_dev);
678         return 0;
679 }
680
681 static void iqs253_shutdown(struct i2c_client *client)
682 {
683         struct iio_dev *indio_dev = i2c_get_clientdata(client);
684         struct iqs253_chip *chip = iio_priv(indio_dev);
685
686         if (chip->sar_wq)
687                 cancel_delayed_work_sync(&chip->sar_dw);
688 }
689
690 static const struct i2c_device_id iqs253_id[] = {
691         {"iqs253", 0},
692         {}
693 };
694
695 MODULE_DEVICE_TABLE(i2c, iqs253_id);
696
697 static const struct of_device_id iqs253_of_match[] = {
698         { .compatible = "azoteq,iqs253", },
699         { },
700 };
701 MODULE_DEVICE_TABLE(of, iqs253_of_match);
702
703 static struct i2c_driver iqs253_driver = {
704         .class = I2C_CLASS_HWMON,
705         .driver = {
706                 .name = "iqs253",
707                 .owner = THIS_MODULE,
708                 .of_match_table = of_match_ptr(iqs253_of_match),
709         },
710         .probe = iqs253_probe,
711         .remove = iqs253_remove,
712         .shutdown = iqs253_shutdown,
713         .id_table = iqs253_id,
714 };
715
716 module_i2c_driver(iqs253_driver);
717
718 MODULE_LICENSE("GPL");
719 MODULE_DESCRIPTION("IQS253 Driver");
720 MODULE_AUTHOR("Sri Krishna chowdary <schowdary@nvidia.com>");