2 * AD7291 digital temperature sensor driver supporting AD7291
4 * Copyright 2010 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
9 #include <linux/interrupt.h>
10 #include <linux/gpio.h>
11 #include <linux/device.h>
12 #include <linux/kernel.h>
13 #include <linux/slab.h>
14 #include <linux/sysfs.h>
15 #include <linux/list.h>
16 #include <linux/i2c.h>
17 #include <linux/module.h>
23 * AD7291 registers definition
25 #define AD7291_COMMAND 0
26 #define AD7291_VOLTAGE 1
27 #define AD7291_T_SENSE 2
28 #define AD7291_T_AVERAGE 3
29 #define AD7291_VOLTAGE_LIMIT_BASE 4
30 #define AD7291_VOLTAGE_LIMIT_COUNT 8
31 #define AD7291_T_SENSE_HIGH 0x1c
32 #define AD7291_T_SENSE_LOW 0x1d
33 #define AD7291_T_SENSE_HYST 0x1e
34 #define AD7291_VOLTAGE_ALERT_STATUS 0x1f
35 #define AD7291_T_ALERT_STATUS 0x20
40 #define AD7291_AUTOCYCLE 0x1
41 #define AD7291_RESET 0x2
42 #define AD7291_ALART_CLEAR 0x4
43 #define AD7291_ALART_POLARITY 0x8
44 #define AD7291_EXT_REF 0x10
45 #define AD7291_NOISE_DELAY 0x20
46 #define AD7291_T_SENSE_MASK 0x40
47 #define AD7291_VOLTAGE_MASK 0xff00
48 #define AD7291_VOLTAGE_OFFSET 0x8
53 #define AD7291_CHANNEL_MASK 0xf000
54 #define AD7291_VALUE_MASK 0xfff
55 #define AD7291_T_VALUE_SIGN 0x400
56 #define AD7291_T_VALUE_FLOAT_OFFSET 2
57 #define AD7291_T_VALUE_FLOAT_MASK 0x2
60 * struct ad7291_chip_info - chip specifc information
63 struct ad7291_chip_info {
64 struct i2c_client *client;
66 u8 channels; /* Active voltage channels */
70 * struct ad7291_chip_info - chip specifc information
73 struct ad7291_limit_regs {
80 * ad7291 register access by I2C
82 static int ad7291_i2c_read(struct ad7291_chip_info *chip, u8 reg, u16 *data)
84 struct i2c_client *client = chip->client;
87 ret = i2c_smbus_read_word_data(client, reg);
89 dev_err(&client->dev, "I2C read error\n");
93 *data = swab16((u16)ret);
98 static int ad7291_i2c_write(struct ad7291_chip_info *chip, u8 reg, u16 data)
100 struct i2c_client *client = chip->client;
103 ret = i2c_smbus_write_word_data(client, reg, swab16(data));
105 dev_err(&client->dev, "I2C write error\n");
110 /* Returns negative errno, or else the number of words read. */
111 static int ad7291_i2c_read_data(struct ad7291_chip_info *chip, u8 reg, u16 *data)
113 struct i2c_client *client = chip->client;
118 if (reg == AD7291_T_SENSE || reg == AD7291_T_AVERAGE)
120 else if (reg == AD7291_VOLTAGE) {
121 if (!chip->channels) {
122 dev_err(&client->dev, "No voltage channel is selected.\n");
125 count = 2 + chip->channels * 2;
127 dev_err(&client->dev, "I2C wrong data register\n");
132 commands[1] = (chip->command >> 8) & 0xff;
133 commands[2] = chip->command & 0xff;
136 ret = i2c_master_send(client, commands, 4);
138 dev_err(&client->dev, "I2C master send error\n");
142 ret = i2c_master_recv(client, (u8 *)data, count);
144 dev_err(&client->dev, "I2C master receive error\n");
149 for (i = 0; i < ret; i++)
150 data[i] = swab16(data[i]);
155 static ssize_t ad7291_show_mode(struct device *dev,
156 struct device_attribute *attr,
159 struct iio_dev *dev_info = dev_get_drvdata(dev);
160 struct ad7291_chip_info *chip = iio_priv(dev_info);
162 if (chip->command & AD7291_AUTOCYCLE)
163 return sprintf(buf, "autocycle\n");
165 return sprintf(buf, "command\n");
168 static ssize_t ad7291_store_mode(struct device *dev,
169 struct device_attribute *attr,
173 struct iio_dev *dev_info = dev_get_drvdata(dev);
174 struct ad7291_chip_info *chip = iio_priv(dev_info);
178 command = chip->command & (~AD7291_AUTOCYCLE);
179 if (strcmp(buf, "autocycle"))
180 command |= AD7291_AUTOCYCLE;
182 ret = ad7291_i2c_write(chip, AD7291_COMMAND, command);
186 chip->command = command;
191 static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
196 static ssize_t ad7291_show_available_modes(struct device *dev,
197 struct device_attribute *attr,
200 return sprintf(buf, "command\nautocycle\n");
203 static IIO_DEVICE_ATTR(available_modes, S_IRUGO, ad7291_show_available_modes, NULL, 0);
205 static ssize_t ad7291_store_reset(struct device *dev,
206 struct device_attribute *attr,
210 struct iio_dev *dev_info = dev_get_drvdata(dev);
211 struct ad7291_chip_info *chip = iio_priv(dev_info);
215 command = chip->command | AD7291_RESET;
217 ret = ad7291_i2c_write(chip, AD7291_COMMAND, command);
224 static IIO_DEVICE_ATTR(reset, S_IWUSR,
229 static ssize_t ad7291_show_ext_ref(struct device *dev,
230 struct device_attribute *attr,
233 struct iio_dev *dev_info = dev_get_drvdata(dev);
234 struct ad7291_chip_info *chip = iio_priv(dev_info);
236 return sprintf(buf, "%d\n", !!(chip->command & AD7291_EXT_REF));
239 static ssize_t ad7291_store_ext_ref(struct device *dev,
240 struct device_attribute *attr,
244 struct iio_dev *dev_info = dev_get_drvdata(dev);
245 struct ad7291_chip_info *chip = iio_priv(dev_info);
249 command = chip->command & (~AD7291_EXT_REF);
250 if (strcmp(buf, "1"))
251 command |= AD7291_EXT_REF;
253 ret = ad7291_i2c_write(chip, AD7291_COMMAND, command);
257 chip->command = command;
262 static IIO_DEVICE_ATTR(ext_ref, S_IRUGO | S_IWUSR,
264 ad7291_store_ext_ref,
267 static ssize_t ad7291_show_noise_delay(struct device *dev,
268 struct device_attribute *attr,
271 struct iio_dev *dev_info = dev_get_drvdata(dev);
272 struct ad7291_chip_info *chip = iio_priv(dev_info);
274 return sprintf(buf, "%d\n", !!(chip->command & AD7291_NOISE_DELAY));
277 static ssize_t ad7291_store_noise_delay(struct device *dev,
278 struct device_attribute *attr,
282 struct iio_dev *dev_info = dev_get_drvdata(dev);
283 struct ad7291_chip_info *chip = iio_priv(dev_info);
287 command = chip->command & (~AD7291_NOISE_DELAY);
288 if (strcmp(buf, "1"))
289 command |= AD7291_NOISE_DELAY;
291 ret = ad7291_i2c_write(chip, AD7291_COMMAND, command);
295 chip->command = command;
300 static IIO_DEVICE_ATTR(noise_delay, S_IRUGO | S_IWUSR,
301 ad7291_show_noise_delay,
302 ad7291_store_noise_delay,
305 static ssize_t ad7291_show_t_sense(struct device *dev,
306 struct device_attribute *attr,
309 struct iio_dev *dev_info = dev_get_drvdata(dev);
310 struct ad7291_chip_info *chip = iio_priv(dev_info);
315 ret = ad7291_i2c_read_data(chip, AD7291_T_SENSE, &data);
319 if (data & AD7291_T_VALUE_SIGN) {
320 /* convert supplement to positive value */
321 data = (AD7291_T_VALUE_SIGN << 1) - data;
325 return sprintf(buf, "%c%d.%.2d\n", sign,
326 (data >> AD7291_T_VALUE_FLOAT_OFFSET),
327 (data & AD7291_T_VALUE_FLOAT_MASK) * 25);
330 static IIO_DEVICE_ATTR(t_sense, S_IRUGO, ad7291_show_t_sense, NULL, 0);
332 static ssize_t ad7291_show_t_average(struct device *dev,
333 struct device_attribute *attr,
336 struct iio_dev *dev_info = dev_get_drvdata(dev);
337 struct ad7291_chip_info *chip = iio_priv(dev_info);
342 ret = ad7291_i2c_read_data(chip, AD7291_T_AVERAGE, &data);
346 if (data & AD7291_T_VALUE_SIGN) {
347 /* convert supplement to positive value */
348 data = (AD7291_T_VALUE_SIGN << 1) - data;
352 return sprintf(buf, "%c%d.%.2d\n", sign,
353 (data >> AD7291_T_VALUE_FLOAT_OFFSET),
354 (data & AD7291_T_VALUE_FLOAT_MASK) * 25);
357 static IIO_DEVICE_ATTR(t_average, S_IRUGO, ad7291_show_t_average, NULL, 0);
359 static ssize_t ad7291_show_voltage(struct device *dev,
360 struct device_attribute *attr,
363 struct iio_dev *dev_info = dev_get_drvdata(dev);
364 struct ad7291_chip_info *chip = iio_priv(dev_info);
365 u16 data[AD7291_VOLTAGE_LIMIT_COUNT];
368 ret = ad7291_i2c_read_data(chip, AD7291_VOLTAGE, data);
372 for (i = 0; i < AD7291_VOLTAGE_LIMIT_COUNT; i++) {
373 if (chip->command & (AD7291_T_SENSE_MASK << i)) {
374 ret = sprintf(buf, "channel[%d]=%d\n", i,
375 data[i] & AD7291_VALUE_MASK);
386 static IIO_DEVICE_ATTR(voltage, S_IRUGO, ad7291_show_voltage, NULL, 0);
388 static ssize_t ad7291_show_channel_mask(struct device *dev,
389 struct device_attribute *attr,
392 struct iio_dev *dev_info = dev_get_drvdata(dev);
393 struct ad7291_chip_info *chip = iio_priv(dev_info);
395 return sprintf(buf, "0x%x\n", (chip->command & AD7291_VOLTAGE_MASK) >>
396 AD7291_VOLTAGE_OFFSET);
399 static ssize_t ad7291_store_channel_mask(struct device *dev,
400 struct device_attribute *attr,
404 struct iio_dev *dev_info = dev_get_drvdata(dev);
405 struct ad7291_chip_info *chip = iio_priv(dev_info);
410 ret = strict_strtoul(buf, 16, &data);
411 if (ret || data > 0xff)
414 command = chip->command & (~AD7291_VOLTAGE_MASK);
415 command |= data << AD7291_VOLTAGE_OFFSET;
417 ret = ad7291_i2c_write(chip, AD7291_COMMAND, command);
421 chip->command = command;
423 for (i = 0, chip->channels = 0; i < AD7291_VOLTAGE_LIMIT_COUNT; i++) {
424 if (chip->command & (AD7291_T_SENSE_MASK << i))
431 static IIO_DEVICE_ATTR(channel_mask, S_IRUGO | S_IWUSR,
432 ad7291_show_channel_mask,
433 ad7291_store_channel_mask,
436 static struct attribute *ad7291_attributes[] = {
437 &iio_dev_attr_available_modes.dev_attr.attr,
438 &iio_dev_attr_mode.dev_attr.attr,
439 &iio_dev_attr_reset.dev_attr.attr,
440 &iio_dev_attr_ext_ref.dev_attr.attr,
441 &iio_dev_attr_noise_delay.dev_attr.attr,
442 &iio_dev_attr_t_sense.dev_attr.attr,
443 &iio_dev_attr_t_average.dev_attr.attr,
444 &iio_dev_attr_voltage.dev_attr.attr,
445 &iio_dev_attr_channel_mask.dev_attr.attr,
449 static const struct attribute_group ad7291_attribute_group = {
450 .attrs = ad7291_attributes,
454 * temperature bound events
457 static irqreturn_t ad7291_event_handler(int irq, void *private)
459 struct iio_dev *indio_dev = private;
460 struct ad7291_chip_info *chip = iio_priv(private);
461 u16 t_status, v_status;
464 s64 timestamp = iio_get_time_ns();
466 if (ad7291_i2c_read(chip, AD7291_T_ALERT_STATUS, &t_status))
469 if (ad7291_i2c_read(chip, AD7291_VOLTAGE_ALERT_STATUS, &v_status))
472 if (!(t_status || v_status))
475 command = chip->command | AD7291_ALART_CLEAR;
476 ad7291_i2c_write(chip, AD7291_COMMAND, command);
478 command = chip->command & ~AD7291_ALART_CLEAR;
479 ad7291_i2c_write(chip, AD7291_COMMAND, command);
481 if (t_status & (1 << 0))
482 iio_push_event(indio_dev, 0,
483 IIO_UNMOD_EVENT_CODE(IIO_TEMP,
488 if (t_status & (1 << 1))
489 iio_push_event(indio_dev, 0,
490 IIO_UNMOD_EVENT_CODE(IIO_TEMP,
495 if (t_status & (1 << 2))
496 iio_push_event(indio_dev, 0,
497 IIO_UNMOD_EVENT_CODE(IIO_TEMP,
502 if (t_status & (1 << 3))
503 iio_push_event(indio_dev, 0,
504 IIO_UNMOD_EVENT_CODE(IIO_TEMP,
510 for (i = 0; i < AD7291_VOLTAGE_LIMIT_COUNT*2; i += 2) {
511 if (v_status & (1 << i))
512 iio_push_event(indio_dev, 0,
513 IIO_UNMOD_EVENT_CODE(IIO_IN,
518 if (v_status & (1 << (i + 1)))
519 iio_push_event(indio_dev, 0,
520 IIO_UNMOD_EVENT_CODE(IIO_IN,
530 static inline ssize_t ad7291_show_t_bound(struct device *dev,
531 struct device_attribute *attr,
534 struct iio_dev *dev_info = dev_get_drvdata(dev);
535 struct ad7291_chip_info *chip = iio_priv(dev_info);
536 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
541 ret = ad7291_i2c_read(chip, this_attr->address, &data);
545 data &= AD7291_VALUE_MASK;
546 if (data & AD7291_T_VALUE_SIGN) {
547 /* convert supplement to positive value */
548 data = (AD7291_T_VALUE_SIGN << 1) - data;
552 return sprintf(buf, "%c%d.%.2d\n", sign,
553 data >> AD7291_T_VALUE_FLOAT_OFFSET,
554 (data & AD7291_T_VALUE_FLOAT_MASK) * 25);
557 static inline ssize_t ad7291_set_t_bound(struct device *dev,
558 struct device_attribute *attr,
562 struct iio_dev *dev_info = dev_get_drvdata(dev);
563 struct ad7291_chip_info *chip = iio_priv(dev_info);
564 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
570 pos = strchr(buf, '.');
572 ret = strict_strtol(buf, 10, &tmp1);
574 if (ret || tmp1 > 127 || tmp1 < -128)
579 if (len > AD7291_T_VALUE_FLOAT_OFFSET)
580 len = AD7291_T_VALUE_FLOAT_OFFSET;
582 ret = strict_strtol(pos, 10, &tmp2);
585 tmp2 = (tmp2 / 25) * 25;
592 data = (data << AD7291_T_VALUE_FLOAT_OFFSET) |
593 (tmp2 & AD7291_T_VALUE_FLOAT_MASK);
595 /* convert positive value to supplyment */
596 data = (AD7291_T_VALUE_SIGN << 1) - data;
598 ret = ad7291_i2c_write(chip, this_attr->address, data);
605 static inline ssize_t ad7291_show_v_bound(struct device *dev,
606 struct device_attribute *attr,
610 struct iio_dev *dev_info = dev_get_drvdata(dev);
611 struct ad7291_chip_info *chip = iio_priv(dev_info);
615 if (bound_reg < AD7291_VOLTAGE_LIMIT_BASE ||
616 bound_reg >= AD7291_VOLTAGE_LIMIT_BASE +
617 AD7291_VOLTAGE_LIMIT_COUNT)
620 ret = ad7291_i2c_read(chip, bound_reg, &data);
624 data &= AD7291_VALUE_MASK;
626 return sprintf(buf, "%d\n", data);
629 static inline ssize_t ad7291_set_v_bound(struct device *dev,
630 struct device_attribute *attr,
635 struct iio_dev *dev_info = dev_get_drvdata(dev);
636 struct ad7291_chip_info *chip = iio_priv(dev_info);
641 if (bound_reg < AD7291_VOLTAGE_LIMIT_BASE ||
642 bound_reg >= AD7291_VOLTAGE_LIMIT_BASE +
643 AD7291_VOLTAGE_LIMIT_COUNT)
646 ret = strict_strtoul(buf, 10, &value);
648 if (ret || value >= 4096)
652 ret = ad7291_i2c_write(chip, bound_reg, data);
659 static IIO_DEVICE_ATTR(t_sense_high_value,
661 ad7291_show_t_bound, ad7291_set_t_bound,
662 AD7291_T_SENSE_HIGH);
663 static IIO_DEVICE_ATTR(t_sense_low_value,
665 ad7291_show_t_bound, ad7291_set_t_bound,
667 static IIO_DEVICE_ATTR(t_sense_hyst_value,
669 ad7291_show_t_bound, ad7291_set_t_bound,
670 AD7291_T_SENSE_HYST);
671 static IIO_DEVICE_ATTR(v0_high,
673 ad7291_show_t_bound, ad7291_set_t_bound, 0x04);
674 static IIO_DEVICE_ATTR(v0_low,
676 ad7291_show_t_bound, ad7291_set_t_bound, 0x05);
677 static IIO_DEVICE_ATTR(v0_hyst,
679 ad7291_show_t_bound, ad7291_set_t_bound, 0x06);
680 static IIO_DEVICE_ATTR(v1_high,
682 ad7291_show_t_bound, ad7291_set_t_bound, 0x07);
683 static IIO_DEVICE_ATTR(v1_low,
685 ad7291_show_t_bound, ad7291_set_t_bound, 0x08);
686 static IIO_DEVICE_ATTR(v1_hyst,
688 ad7291_show_t_bound, ad7291_set_t_bound, 0x09);
689 static IIO_DEVICE_ATTR(v2_high,
691 ad7291_show_t_bound, ad7291_set_t_bound, 0x0A);
692 static IIO_DEVICE_ATTR(v2_low,
694 ad7291_show_t_bound, ad7291_set_t_bound, 0x0B);
695 static IIO_DEVICE_ATTR(v2_hyst,
697 ad7291_show_t_bound, ad7291_set_t_bound, 0x0C);
698 static IIO_DEVICE_ATTR(v3_high,
700 /* Datasheet suggests this one and this one only
701 has the registers in different order */
702 ad7291_show_t_bound, ad7291_set_t_bound, 0x0E);
703 static IIO_DEVICE_ATTR(v3_low,
705 ad7291_show_t_bound, ad7291_set_t_bound, 0x0D);
706 static IIO_DEVICE_ATTR(v3_hyst,
708 ad7291_show_t_bound, ad7291_set_t_bound, 0x0F);
709 static IIO_DEVICE_ATTR(v4_high,
711 ad7291_show_t_bound, ad7291_set_t_bound, 0x10);
712 static IIO_DEVICE_ATTR(v4_low,
714 ad7291_show_t_bound, ad7291_set_t_bound, 0x11);
715 static IIO_DEVICE_ATTR(v4_hyst,
717 ad7291_show_t_bound, ad7291_set_t_bound, 0x12);
718 static IIO_DEVICE_ATTR(v5_high,
720 ad7291_show_t_bound, ad7291_set_t_bound, 0x13);
721 static IIO_DEVICE_ATTR(v5_low,
723 ad7291_show_t_bound, ad7291_set_t_bound, 0x14);
724 static IIO_DEVICE_ATTR(v5_hyst,
726 ad7291_show_t_bound, ad7291_set_t_bound, 0x15);
727 static IIO_DEVICE_ATTR(v6_high,
729 ad7291_show_t_bound, ad7291_set_t_bound, 0x16);
730 static IIO_DEVICE_ATTR(v6_low,
732 ad7291_show_t_bound, ad7291_set_t_bound, 0x17);
733 static IIO_DEVICE_ATTR(v6_hyst,
735 ad7291_show_t_bound, ad7291_set_t_bound, 0x18);
736 static IIO_DEVICE_ATTR(v7_high,
738 ad7291_show_t_bound, ad7291_set_t_bound, 0x19);
739 static IIO_DEVICE_ATTR(v7_low,
741 ad7291_show_t_bound, ad7291_set_t_bound, 0x1A);
742 static IIO_DEVICE_ATTR(v7_hyst,
744 ad7291_show_t_bound, ad7291_set_t_bound, 0x1B);
746 static struct attribute *ad7291_event_attributes[] = {
747 &iio_dev_attr_t_sense_high_value.dev_attr.attr,
748 &iio_dev_attr_t_sense_low_value.dev_attr.attr,
749 &iio_dev_attr_t_sense_hyst_value.dev_attr.attr,
750 &iio_dev_attr_v0_high.dev_attr.attr,
751 &iio_dev_attr_v0_low.dev_attr.attr,
752 &iio_dev_attr_v0_hyst.dev_attr.attr,
753 &iio_dev_attr_v1_high.dev_attr.attr,
754 &iio_dev_attr_v1_low.dev_attr.attr,
755 &iio_dev_attr_v1_hyst.dev_attr.attr,
756 &iio_dev_attr_v2_high.dev_attr.attr,
757 &iio_dev_attr_v2_low.dev_attr.attr,
758 &iio_dev_attr_v2_hyst.dev_attr.attr,
759 &iio_dev_attr_v3_high.dev_attr.attr,
760 &iio_dev_attr_v3_low.dev_attr.attr,
761 &iio_dev_attr_v3_hyst.dev_attr.attr,
762 &iio_dev_attr_v4_high.dev_attr.attr,
763 &iio_dev_attr_v4_low.dev_attr.attr,
764 &iio_dev_attr_v4_hyst.dev_attr.attr,
765 &iio_dev_attr_v5_high.dev_attr.attr,
766 &iio_dev_attr_v5_low.dev_attr.attr,
767 &iio_dev_attr_v5_hyst.dev_attr.attr,
768 &iio_dev_attr_v6_high.dev_attr.attr,
769 &iio_dev_attr_v6_low.dev_attr.attr,
770 &iio_dev_attr_v6_hyst.dev_attr.attr,
771 &iio_dev_attr_v7_high.dev_attr.attr,
772 &iio_dev_attr_v7_low.dev_attr.attr,
773 &iio_dev_attr_v7_hyst.dev_attr.attr,
777 static struct attribute_group ad7291_event_attribute_group = {
778 .attrs = ad7291_event_attributes,
781 static const struct iio_info ad7291_info = {
782 .attrs = &ad7291_attribute_group,
783 .num_interrupt_lines = 1,
784 .event_attrs = &ad7291_event_attribute_group,
788 * device probe and remove
791 static int __devinit ad7291_probe(struct i2c_client *client,
792 const struct i2c_device_id *id)
794 struct ad7291_chip_info *chip;
795 struct iio_dev *indio_dev;
798 indio_dev = iio_allocate_device(sizeof(*chip));
799 if (indio_dev == NULL) {
803 chip = iio_priv(indio_dev);
804 /* this is only used for device removal purposes */
805 i2c_set_clientdata(client, indio_dev);
807 chip->client = client;
808 chip->command = AD7291_NOISE_DELAY | AD7291_T_SENSE_MASK;
810 indio_dev->name = id->name;
811 indio_dev->dev.parent = &client->dev;
812 indio_dev->info = &ad7291_info;
813 indio_dev->modes = INDIO_DIRECT_MODE;
815 ret = iio_device_register(indio_dev);
819 if (client->irq > 0) {
820 ret = request_threaded_irq(client->irq,
822 &ad7291_event_handler,
823 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
827 goto error_unreg_dev;
829 /* set irq polarity low level */
830 chip->command |= AD7291_ALART_POLARITY;
833 ret = ad7291_i2c_write(chip, AD7291_COMMAND, chip->command);
836 goto error_unreg_irq;
839 dev_info(&client->dev, "%s temperature sensor registered.\n",
845 free_irq(client->irq, indio_dev);
847 iio_device_unregister(indio_dev);
849 iio_free_device(indio_dev);
854 static int __devexit ad7291_remove(struct i2c_client *client)
856 struct iio_dev *indio_dev = i2c_get_clientdata(client);
859 free_irq(client->irq, indio_dev);
860 iio_device_unregister(indio_dev);
861 iio_free_device(indio_dev);
866 static const struct i2c_device_id ad7291_id[] = {
871 MODULE_DEVICE_TABLE(i2c, ad7291_id);
873 static struct i2c_driver ad7291_driver = {
877 .probe = ad7291_probe,
878 .remove = __devexit_p(ad7291_remove),
879 .id_table = ad7291_id,
882 static __init int ad7291_init(void)
884 return i2c_add_driver(&ad7291_driver);
887 static __exit void ad7291_exit(void)
889 i2c_del_driver(&ad7291_driver);
892 MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
893 MODULE_DESCRIPTION("Analog Devices AD7291 digital"
894 " temperature sensor driver");
895 MODULE_LICENSE("GPL v2");
897 module_init(ad7291_init);
898 module_exit(ad7291_exit);