2 * AD7150 capacitive sensor driver supporting AD7150/1/6
4 * Copyright 2010 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
9 #include <linux/interrupt.h>
10 #include <linux/device.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
19 * AD7150 registers definition
22 #define AD7150_STATUS 0
23 #define AD7150_STATUS_OUT1 (1 << 3)
24 #define AD7150_STATUS_OUT2 (1 << 5)
25 #define AD7150_CH1_DATA_HIGH 1
26 #define AD7150_CH1_DATA_LOW 2
27 #define AD7150_CH2_DATA_HIGH 3
28 #define AD7150_CH2_DATA_LOW 4
29 #define AD7150_CH1_AVG_HIGH 5
30 #define AD7150_CH1_AVG_LOW 6
31 #define AD7150_CH2_AVG_HIGH 7
32 #define AD7150_CH2_AVG_LOW 8
33 #define AD7150_CH1_SENSITIVITY 9
34 #define AD7150_CH1_THR_HOLD_H 9
35 #define AD7150_CH1_TIMEOUT 10
36 #define AD7150_CH1_THR_HOLD_L 10
37 #define AD7150_CH1_SETUP 11
38 #define AD7150_CH2_SENSITIVITY 12
39 #define AD7150_CH2_THR_HOLD_H 12
40 #define AD7150_CH2_TIMEOUT 13
41 #define AD7150_CH2_THR_HOLD_L 13
42 #define AD7150_CH2_SETUP 14
44 #define AD7150_CFG_FIX (1 << 7)
45 #define AD7150_PD_TIMER 16
46 #define AD7150_CH1_CAPDAC 17
47 #define AD7150_CH2_CAPDAC 18
54 #define AD7150_MAX_CONV_MODE 4
57 * struct ad7150_chip_info - chip specifc information
60 struct ad7150_chip_info
{
61 struct i2c_client
*client
;
63 u16 ch1_threshold
; /* Ch1 Threshold (in fixed threshold mode) */
64 u8 ch1_sensitivity
; /* Ch1 Sensitivity (in adaptive threshold mode) */
65 u8 ch1_timeout
; /* Ch1 Timeout (in adaptive threshold mode) */
67 u16 ch2_threshold
; /* Ch2 Threshold (in fixed threshold mode) */
68 u8 ch2_sensitivity
; /* Ch1 Sensitivity (in adaptive threshold mode) */
69 u8 ch2_timeout
; /* Ch1 Timeout (in adaptive threshold mode) */
72 char threshold_mode
[10]; /* adaptive/fixed threshold mode */
74 char *conversion_mode
;
77 struct ad7150_conversion_mode
{
82 static struct ad7150_conversion_mode
83 ad7150_conv_mode_table
[AD7150_MAX_CONV_MODE
] = {
85 { "continuous-conversion", 1 },
86 { "single-conversion", 2 },
91 * ad7150 register access by I2C
94 static int ad7150_i2c_read(struct ad7150_chip_info
*chip
, u8 reg
, u8
*data
, int len
)
96 struct i2c_client
*client
= chip
->client
;
99 ret
= i2c_master_send(client
, ®
, 1);
101 dev_err(&client
->dev
, "I2C write error\n");
105 ret
= i2c_master_recv(client
, data
, len
);
107 dev_err(&client
->dev
, "I2C read error\n");
114 static int ad7150_i2c_write(struct ad7150_chip_info
*chip
, u8 reg
, u8 data
)
116 struct i2c_client
*client
= chip
->client
;
124 ret
= i2c_master_send(client
, tx
, 2);
126 dev_err(&client
->dev
, "I2C write error\n");
135 #define IIO_DEV_ATTR_AVAIL_CONVERSION_MODES(_show) \
136 IIO_DEVICE_ATTR(available_conversion_modes, S_IRUGO, _show, NULL, 0)
137 #define IIO_DEV_ATTR_CONVERSION_MODE(_mode, _show, _store) \
138 IIO_DEVICE_ATTR(conversion_mode, _mode, _show, _store, 0)
139 #define IIO_DEV_ATTR_AVAIL_THRESHOLD_MODES(_show) \
140 IIO_DEVICE_ATTR(available_threshold_modes, S_IRUGO, _show, NULL, 0)
141 #define IIO_DEV_ATTR_THRESHOLD_MODE(_mode, _show, _store) \
142 IIO_DEVICE_ATTR(threshold_mode, _mode, _show, _store, 0)
143 #define IIO_DEV_ATTR_CH1_THRESHOLD(_mode, _show, _store) \
144 IIO_DEVICE_ATTR(ch1_threshold, _mode, _show, _store, 0)
145 #define IIO_DEV_ATTR_CH2_THRESHOLD(_mode, _show, _store) \
146 IIO_DEVICE_ATTR(ch2_threshold, _mode, _show, _store, 0)
147 #define IIO_DEV_ATTR_CH1_SENSITIVITY(_mode, _show, _store) \
148 IIO_DEVICE_ATTR(ch1_sensitivity, _mode, _show, _store, 0)
149 #define IIO_DEV_ATTR_CH2_SENSITIVITY(_mode, _show, _store) \
150 IIO_DEVICE_ATTR(ch2_sensitivity, _mode, _show, _store, 0)
151 #define IIO_DEV_ATTR_CH1_TIMEOUT(_mode, _show, _store) \
152 IIO_DEVICE_ATTR(ch1_timeout, _mode, _show, _store, 0)
153 #define IIO_DEV_ATTR_CH2_TIMEOUT(_mode, _show, _store) \
154 IIO_DEVICE_ATTR(ch2_timeout, _mode, _show, _store, 0)
155 #define IIO_DEV_ATTR_CH1_VALUE(_show) \
156 IIO_DEVICE_ATTR(ch1_value, S_IRUGO, _show, NULL, 0)
157 #define IIO_DEV_ATTR_CH2_VALUE(_show) \
158 IIO_DEVICE_ATTR(ch2_value, S_IRUGO, _show, NULL, 0)
159 #define IIO_DEV_ATTR_CH1_SETUP(_mode, _show, _store) \
160 IIO_DEVICE_ATTR(ch1_setup, _mode, _show, _store, 0)
161 #define IIO_DEV_ATTR_CH2_SETUP(_mode, _show, _store) \
162 IIO_DEVICE_ATTR(ch2_setup, _mode, _show, _store, 0)
163 #define IIO_DEV_ATTR_POWERDOWN_TIMER(_mode, _show, _store) \
164 IIO_DEVICE_ATTR(powerdown_timer, _mode, _show, _store, 0)
166 static ssize_t
ad7150_show_conversion_modes(struct device
*dev
,
167 struct device_attribute
*attr
,
173 for (i
= 0; i
< AD7150_MAX_CONV_MODE
; i
++)
174 len
+= sprintf(buf
+ len
, "%s\n", ad7150_conv_mode_table
[i
].name
);
179 static IIO_DEV_ATTR_AVAIL_CONVERSION_MODES(ad7150_show_conversion_modes
);
181 static ssize_t
ad7150_show_conversion_mode(struct device
*dev
,
182 struct device_attribute
*attr
,
185 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
186 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
188 return sprintf(buf
, "%s\n", chip
->conversion_mode
);
191 static ssize_t
ad7150_store_conversion_mode(struct device
*dev
,
192 struct device_attribute
*attr
,
196 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
197 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
201 ad7150_i2c_read(chip
, AD7150_CFG
, &cfg
, 1);
203 for (i
= 0; i
< AD7150_MAX_CONV_MODE
; i
++) {
204 if (strncmp(buf
, ad7150_conv_mode_table
[i
].name
,
205 strlen(ad7150_conv_mode_table
[i
].name
) - 1) == 0) {
206 chip
->conversion_mode
= ad7150_conv_mode_table
[i
].name
;
207 cfg
|= 0x18 | ad7150_conv_mode_table
[i
].reg_cfg
;
208 ad7150_i2c_write(chip
, AD7150_CFG
, cfg
);
213 dev_err(dev
, "not supported conversion mode\n");
218 static IIO_DEV_ATTR_CONVERSION_MODE(S_IRUGO
| S_IWUSR
,
219 ad7150_show_conversion_mode
,
220 ad7150_store_conversion_mode
);
222 static ssize_t
ad7150_show_threshold_modes(struct device
*dev
,
223 struct device_attribute
*attr
,
226 return sprintf(buf
, "adaptive\nfixed\n");
229 static IIO_DEV_ATTR_AVAIL_THRESHOLD_MODES(ad7150_show_threshold_modes
);
231 static ssize_t
ad7150_show_ch1_value(struct device
*dev
,
232 struct device_attribute
*attr
,
235 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
236 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
239 ad7150_i2c_read(chip
, AD7150_CH1_DATA_HIGH
, data
, 2);
240 return sprintf(buf
, "%d\n", ((int) data
[0] << 8) | data
[1]);
243 static IIO_DEV_ATTR_CH1_VALUE(ad7150_show_ch1_value
);
245 static ssize_t
ad7150_show_ch2_value(struct device
*dev
,
246 struct device_attribute
*attr
,
249 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
250 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
253 ad7150_i2c_read(chip
, AD7150_CH2_DATA_HIGH
, data
, 2);
254 return sprintf(buf
, "%d\n", ((int) data
[0] << 8) | data
[1]);
257 static IIO_DEV_ATTR_CH2_VALUE(ad7150_show_ch2_value
);
259 static ssize_t
ad7150_show_threshold_mode(struct device
*dev
,
260 struct device_attribute
*attr
,
263 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
264 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
266 return sprintf(buf
, "%s\n", chip
->threshold_mode
);
269 static ssize_t
ad7150_store_threshold_mode(struct device
*dev
,
270 struct device_attribute
*attr
,
274 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
275 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
278 ad7150_i2c_read(chip
, AD7150_CFG
, &cfg
, 1);
280 if (strncmp(buf
, "fixed", 5) == 0) {
281 strcpy(chip
->threshold_mode
, "fixed");
282 cfg
|= AD7150_CFG_FIX
;
283 ad7150_i2c_write(chip
, AD7150_CFG
, cfg
);
286 } else if (strncmp(buf
, "adaptive", 8) == 0) {
287 strcpy(chip
->threshold_mode
, "adaptive");
288 cfg
&= ~AD7150_CFG_FIX
;
289 ad7150_i2c_write(chip
, AD7150_CFG
, cfg
);
294 dev_err(dev
, "not supported threshold mode\n");
298 static IIO_DEV_ATTR_THRESHOLD_MODE(S_IRUGO
| S_IWUSR
,
299 ad7150_show_threshold_mode
,
300 ad7150_store_threshold_mode
);
302 static ssize_t
ad7150_show_ch1_threshold(struct device
*dev
,
303 struct device_attribute
*attr
,
306 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
307 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
309 return sprintf(buf
, "%d\n", chip
->ch1_threshold
);
312 static ssize_t
ad7150_store_ch1_threshold(struct device
*dev
,
313 struct device_attribute
*attr
,
317 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
318 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
322 ret
= strict_strtoul(buf
, 10, &data
);
324 if ((!ret
) && (data
< 0x10000)) {
325 ad7150_i2c_write(chip
, AD7150_CH1_THR_HOLD_H
, data
>> 8);
326 ad7150_i2c_write(chip
, AD7150_CH1_THR_HOLD_L
, data
);
327 chip
->ch1_threshold
= data
;
334 static IIO_DEV_ATTR_CH1_THRESHOLD(S_IRUGO
| S_IWUSR
,
335 ad7150_show_ch1_threshold
,
336 ad7150_store_ch1_threshold
);
338 static ssize_t
ad7150_show_ch2_threshold(struct device
*dev
,
339 struct device_attribute
*attr
,
342 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
343 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
345 return sprintf(buf
, "%d\n", chip
->ch2_threshold
);
348 static ssize_t
ad7150_store_ch2_threshold(struct device
*dev
,
349 struct device_attribute
*attr
,
353 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
354 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
358 ret
= strict_strtoul(buf
, 10, &data
);
360 if ((!ret
) && (data
< 0x10000)) {
361 ad7150_i2c_write(chip
, AD7150_CH2_THR_HOLD_H
, data
>> 8);
362 ad7150_i2c_write(chip
, AD7150_CH2_THR_HOLD_L
, data
);
363 chip
->ch2_threshold
= data
;
370 static IIO_DEV_ATTR_CH2_THRESHOLD(S_IRUGO
| S_IWUSR
,
371 ad7150_show_ch2_threshold
,
372 ad7150_store_ch2_threshold
);
374 static ssize_t
ad7150_show_ch1_sensitivity(struct device
*dev
,
375 struct device_attribute
*attr
,
378 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
379 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
381 return sprintf(buf
, "%d\n", chip
->ch1_sensitivity
);
384 static ssize_t
ad7150_store_ch1_sensitivity(struct device
*dev
,
385 struct device_attribute
*attr
,
389 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
390 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
394 ret
= strict_strtoul(buf
, 10, &data
);
396 if ((!ret
) && (data
< 0x100)) {
397 ad7150_i2c_write(chip
, AD7150_CH1_SENSITIVITY
, data
);
398 chip
->ch1_sensitivity
= data
;
405 static IIO_DEV_ATTR_CH1_SENSITIVITY(S_IRUGO
| S_IWUSR
,
406 ad7150_show_ch1_sensitivity
,
407 ad7150_store_ch1_sensitivity
);
409 static ssize_t
ad7150_show_ch2_sensitivity(struct device
*dev
,
410 struct device_attribute
*attr
,
413 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
414 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
416 return sprintf(buf
, "%d\n", chip
->ch2_sensitivity
);
419 static ssize_t
ad7150_store_ch2_sensitivity(struct device
*dev
,
420 struct device_attribute
*attr
,
424 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
425 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
429 ret
= strict_strtoul(buf
, 10, &data
);
431 if ((!ret
) && (data
< 0x100)) {
432 ad7150_i2c_write(chip
, AD7150_CH2_SENSITIVITY
, data
);
433 chip
->ch2_sensitivity
= data
;
440 static IIO_DEV_ATTR_CH2_SENSITIVITY(S_IRUGO
| S_IWUSR
,
441 ad7150_show_ch2_sensitivity
,
442 ad7150_store_ch2_sensitivity
);
444 static ssize_t
ad7150_show_ch1_timeout(struct device
*dev
,
445 struct device_attribute
*attr
,
448 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
449 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
451 return sprintf(buf
, "%d\n", chip
->ch1_timeout
);
454 static ssize_t
ad7150_store_ch1_timeout(struct device
*dev
,
455 struct device_attribute
*attr
,
459 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
460 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
464 ret
= strict_strtoul(buf
, 10, &data
);
466 if ((!ret
) && (data
< 0x100)) {
467 ad7150_i2c_write(chip
, AD7150_CH1_TIMEOUT
, data
);
468 chip
->ch1_timeout
= data
;
475 static IIO_DEV_ATTR_CH1_TIMEOUT(S_IRUGO
| S_IWUSR
,
476 ad7150_show_ch1_timeout
,
477 ad7150_store_ch1_timeout
);
479 static ssize_t
ad7150_show_ch2_timeout(struct device
*dev
,
480 struct device_attribute
*attr
,
483 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
484 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
486 return sprintf(buf
, "%d\n", chip
->ch2_timeout
);
489 static ssize_t
ad7150_store_ch2_timeout(struct device
*dev
,
490 struct device_attribute
*attr
,
494 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
495 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
499 ret
= strict_strtoul(buf
, 10, &data
);
501 if ((!ret
) && (data
< 0x100)) {
502 ad7150_i2c_write(chip
, AD7150_CH2_TIMEOUT
, data
);
503 chip
->ch2_timeout
= data
;
510 static IIO_DEV_ATTR_CH2_TIMEOUT(S_IRUGO
| S_IWUSR
,
511 ad7150_show_ch2_timeout
,
512 ad7150_store_ch2_timeout
);
514 static ssize_t
ad7150_show_ch1_setup(struct device
*dev
,
515 struct device_attribute
*attr
,
518 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
519 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
521 return sprintf(buf
, "0x%02x\n", chip
->ch1_setup
);
524 static ssize_t
ad7150_store_ch1_setup(struct device
*dev
,
525 struct device_attribute
*attr
,
529 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
530 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
534 ret
= strict_strtoul(buf
, 10, &data
);
536 if ((!ret
) && (data
< 0x100)) {
537 ad7150_i2c_write(chip
, AD7150_CH1_SETUP
, data
);
538 chip
->ch1_setup
= data
;
546 static IIO_DEV_ATTR_CH1_SETUP(S_IRUGO
| S_IWUSR
,
547 ad7150_show_ch1_setup
,
548 ad7150_store_ch1_setup
);
550 static ssize_t
ad7150_show_ch2_setup(struct device
*dev
,
551 struct device_attribute
*attr
,
554 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
555 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
557 return sprintf(buf
, "0x%02x\n", chip
->ch2_setup
);
560 static ssize_t
ad7150_store_ch2_setup(struct device
*dev
,
561 struct device_attribute
*attr
,
565 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
566 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
570 ret
= strict_strtoul(buf
, 10, &data
);
572 if ((!ret
) && (data
< 0x100)) {
573 ad7150_i2c_write(chip
, AD7150_CH2_SETUP
, data
);
574 chip
->ch2_setup
= data
;
581 static IIO_DEV_ATTR_CH2_SETUP(S_IRUGO
| S_IWUSR
,
582 ad7150_show_ch2_setup
,
583 ad7150_store_ch2_setup
);
585 static ssize_t
ad7150_show_powerdown_timer(struct device
*dev
,
586 struct device_attribute
*attr
,
589 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
590 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
592 return sprintf(buf
, "0x%02x\n", chip
->powerdown_timer
);
595 static ssize_t
ad7150_store_powerdown_timer(struct device
*dev
,
596 struct device_attribute
*attr
,
600 struct iio_dev
*dev_info
= dev_get_drvdata(dev
);
601 struct ad7150_chip_info
*chip
= iio_priv(dev_info
);
605 ret
= strict_strtoul(buf
, 10, &data
);
607 if ((!ret
) && (data
< 0x40)) {
608 chip
->powerdown_timer
= data
;
615 static IIO_DEV_ATTR_POWERDOWN_TIMER(S_IRUGO
| S_IWUSR
,
616 ad7150_show_powerdown_timer
,
617 ad7150_store_powerdown_timer
);
619 static struct attribute
*ad7150_attributes
[] = {
620 &iio_dev_attr_available_threshold_modes
.dev_attr
.attr
,
621 &iio_dev_attr_threshold_mode
.dev_attr
.attr
,
622 &iio_dev_attr_ch1_threshold
.dev_attr
.attr
,
623 &iio_dev_attr_ch2_threshold
.dev_attr
.attr
,
624 &iio_dev_attr_ch1_timeout
.dev_attr
.attr
,
625 &iio_dev_attr_ch2_timeout
.dev_attr
.attr
,
626 &iio_dev_attr_ch1_setup
.dev_attr
.attr
,
627 &iio_dev_attr_ch2_setup
.dev_attr
.attr
,
628 &iio_dev_attr_ch1_sensitivity
.dev_attr
.attr
,
629 &iio_dev_attr_ch2_sensitivity
.dev_attr
.attr
,
630 &iio_dev_attr_powerdown_timer
.dev_attr
.attr
,
631 &iio_dev_attr_ch1_value
.dev_attr
.attr
,
632 &iio_dev_attr_ch2_value
.dev_attr
.attr
,
636 static const struct attribute_group ad7150_attribute_group
= {
637 .attrs
= ad7150_attributes
,
644 static irqreturn_t
ad7150_event_handler(int irq
, void *private)
646 struct iio_dev
*indio_dev
= private;
647 struct ad7150_chip_info
*chip
= iio_priv(indio_dev
);
649 s64 timestamp
= iio_get_time_ns();
651 ad7150_i2c_read(chip
, AD7150_STATUS
, &int_status
, 1);
653 if ((int_status
& AD7150_STATUS_OUT1
) && !(chip
->old_state
& AD7150_STATUS_OUT1
))
654 iio_push_event(indio_dev
, 0,
655 IIO_UNMOD_EVENT_CODE(IIO_EV_CLASS_IN
,
660 else if ((!(int_status
& AD7150_STATUS_OUT1
)) && (chip
->old_state
& AD7150_STATUS_OUT1
))
661 iio_push_event(indio_dev
, 0,
662 IIO_UNMOD_EVENT_CODE(IIO_EV_CLASS_IN
,
668 if ((int_status
& AD7150_STATUS_OUT2
) && !(chip
->old_state
& AD7150_STATUS_OUT2
))
669 iio_push_event(indio_dev
, 0,
670 IIO_UNMOD_EVENT_CODE(IIO_EV_CLASS_IN
,
675 else if ((!(int_status
& AD7150_STATUS_OUT2
)) && (chip
->old_state
& AD7150_STATUS_OUT2
))
676 iio_push_event(indio_dev
, 0,
677 IIO_UNMOD_EVENT_CODE(IIO_EV_CLASS_IN
,
685 static IIO_CONST_ATTR(ch1_high_en
, "1");
686 static IIO_CONST_ATTR(ch2_high_en
, "1");
687 static IIO_CONST_ATTR(ch1_low_en
, "1");
688 static IIO_CONST_ATTR(ch2_low_en
, "1");
690 static struct attribute
*ad7150_event_attributes
[] = {
691 &iio_const_attr_ch1_high_en
.dev_attr
.attr
,
692 &iio_const_attr_ch2_high_en
.dev_attr
.attr
,
693 &iio_const_attr_ch1_low_en
.dev_attr
.attr
,
694 &iio_const_attr_ch2_low_en
.dev_attr
.attr
,
698 static struct attribute_group ad7150_event_attribute_group
= {
699 .attrs
= ad7150_event_attributes
,
702 static const struct iio_info ad7150_info
= {
703 .attrs
= &ad7150_attribute_group
,
704 .num_interrupt_lines
= 1,
705 .event_attrs
= &ad7150_event_attribute_group
,
706 .driver_module
= THIS_MODULE
,
709 * device probe and remove
712 static int __devinit
ad7150_probe(struct i2c_client
*client
,
713 const struct i2c_device_id
*id
)
715 int ret
= 0, regdone
= 0;
716 struct ad7150_chip_info
*chip
;
717 struct iio_dev
*indio_dev
;
719 indio_dev
= iio_allocate_device(sizeof(*chip
));
720 if (indio_dev
== NULL
) {
724 chip
= iio_priv(indio_dev
);
725 /* this is only used for device removal purposes */
726 i2c_set_clientdata(client
, indio_dev
);
728 chip
->client
= client
;
730 /* Establish that the iio_dev is a child of the i2c device */
731 indio_dev
->name
= id
->name
;
732 indio_dev
->dev
.parent
= &client
->dev
;
734 indio_dev
->info
= &ad7150_info
;
736 indio_dev
->modes
= INDIO_DIRECT_MODE
;
738 ret
= iio_device_register(indio_dev
);
744 ret
= request_threaded_irq(client
->irq
,
746 &ad7150_event_handler
,
747 IRQF_TRIGGER_RISING
|
748 IRQF_TRIGGER_FALLING
,
755 dev_err(&client
->dev
, "%s capacitive sensor registered, irq: %d\n", id
->name
, client
->irq
);
761 iio_device_unregister(indio_dev
);
763 iio_free_device(indio_dev
);
768 static int __devexit
ad7150_remove(struct i2c_client
*client
)
770 struct iio_dev
*indio_dev
= i2c_get_clientdata(client
);
773 free_irq(client
->irq
, indio_dev
);
774 iio_device_unregister(indio_dev
);
779 static const struct i2c_device_id ad7150_id
[] = {
786 MODULE_DEVICE_TABLE(i2c
, ad7150_id
);
788 static struct i2c_driver ad7150_driver
= {
792 .probe
= ad7150_probe
,
793 .remove
= __devexit_p(ad7150_remove
),
794 .id_table
= ad7150_id
,
797 static __init
int ad7150_init(void)
799 return i2c_add_driver(&ad7150_driver
);
802 static __exit
void ad7150_exit(void)
804 i2c_del_driver(&ad7150_driver
);
807 MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
808 MODULE_DESCRIPTION("Analog Devices ad7150/1/6 capacitive sensor driver");
809 MODULE_LICENSE("GPL v2");
811 module_init(ad7150_init
);
812 module_exit(ad7150_exit
);