2 * ADT7310 digital temperature sensor driver supporting ADT7310
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/workqueue.h>
12 #include <linux/device.h>
13 #include <linux/kernel.h>
14 #include <linux/slab.h>
15 #include <linux/sysfs.h>
16 #include <linux/list.h>
17 #include <linux/spi/spi.h>
18 #include <linux/rtc.h>
24 * ADT7310 registers definition
27 #define ADT7310_STATUS 0
28 #define ADT7310_CONFIG 1
29 #define ADT7310_TEMPERATURE 2
31 #define ADT7310_T_CRIT 4
32 #define ADT7310_T_HYST 5
33 #define ADT7310_T_ALARM_HIGH 6
34 #define ADT7310_T_ALARM_LOW 7
39 #define ADT7310_STAT_T_LOW 0x10
40 #define ADT7310_STAT_T_HIGH 0x20
41 #define ADT7310_STAT_T_CRIT 0x40
42 #define ADT7310_STAT_NOT_RDY 0x80
47 #define ADT7310_FAULT_QUEUE_MASK 0x3
48 #define ADT7310_CT_POLARITY 0x4
49 #define ADT7310_INT_POLARITY 0x8
50 #define ADT7310_EVENT_MODE 0x10
51 #define ADT7310_MODE_MASK 0x60
52 #define ADT7310_ONESHOT 0x20
53 #define ADT7310_SPS 0x40
54 #define ADT7310_PD 0x60
55 #define ADT7310_RESOLUTION 0x80
60 #define ADT7310_T16_VALUE_SIGN 0x8000
61 #define ADT7310_T16_VALUE_FLOAT_OFFSET 7
62 #define ADT7310_T16_VALUE_FLOAT_MASK 0x7F
63 #define ADT7310_T13_VALUE_SIGN 0x1000
64 #define ADT7310_T13_VALUE_OFFSET 3
65 #define ADT7310_T13_VALUE_FLOAT_OFFSET 4
66 #define ADT7310_T13_VALUE_FLOAT_MASK 0xF
67 #define ADT7310_T_HYST_MASK 0xF
68 #define ADT7310_DEVICE_ID_MASK 0x7
69 #define ADT7310_MANUFACTORY_ID_MASK 0xF8
70 #define ADT7310_MANUFACTORY_ID_OFFSET 3
73 #define ADT7310_CMD_REG_MASK 0x28
74 #define ADT7310_CMD_REG_OFFSET 3
75 #define ADT7310_CMD_READ 0x40
76 #define ADT7310_CMD_CON_READ 0x4
78 #define ADT7310_IRQS 2
81 * struct adt7310_chip_info - chip specifc information
84 struct adt7310_chip_info {
86 struct spi_device *spi_dev;
87 struct iio_dev *indio_dev;
88 struct work_struct thresh_work;
94 * adt7310 register access by SPI
97 static int adt7310_spi_read_word(struct adt7310_chip_info *chip, u8 reg, u16 *data)
99 struct spi_device *spi_dev = chip->spi_dev;
100 u8 command = (reg << ADT7310_CMD_REG_OFFSET) & ADT7310_CMD_REG_MASK;
103 command |= ADT7310_CMD_READ;
104 ret = spi_write(spi_dev, &command, sizeof(command));
106 dev_err(&spi_dev->dev, "SPI write command error\n");
110 ret = spi_read(spi_dev, (u8 *)data, sizeof(*data));
112 dev_err(&spi_dev->dev, "SPI read word error\n");
116 *data = be16_to_cpu(*data);
121 static int adt7310_spi_write_word(struct adt7310_chip_info *chip, u8 reg, u16 data)
123 struct spi_device *spi_dev = chip->spi_dev;
127 buf[0] = (reg << ADT7310_CMD_REG_OFFSET) & ADT7310_CMD_REG_MASK;
128 buf[1] = (u8)(data >> 8);
129 buf[2] = (u8)(data & 0xFF);
131 ret = spi_write(spi_dev, buf, 3);
133 dev_err(&spi_dev->dev, "SPI write word error\n");
140 static int adt7310_spi_read_byte(struct adt7310_chip_info *chip, u8 reg, u8 *data)
142 struct spi_device *spi_dev = chip->spi_dev;
143 u8 command = (reg << ADT7310_CMD_REG_OFFSET) & ADT7310_CMD_REG_MASK;
146 command |= ADT7310_CMD_READ;
147 ret = spi_write(spi_dev, &command, sizeof(command));
149 dev_err(&spi_dev->dev, "SPI write command error\n");
153 ret = spi_read(spi_dev, data, sizeof(*data));
155 dev_err(&spi_dev->dev, "SPI read byte error\n");
162 static int adt7310_spi_write_byte(struct adt7310_chip_info *chip, u8 reg, u8 data)
164 struct spi_device *spi_dev = chip->spi_dev;
168 buf[0] = (reg << ADT7310_CMD_REG_OFFSET) & ADT7310_CMD_REG_MASK;
171 ret = spi_write(spi_dev, buf, 2);
173 dev_err(&spi_dev->dev, "SPI write byte error\n");
180 static ssize_t adt7310_show_mode(struct device *dev,
181 struct device_attribute *attr,
184 struct iio_dev *dev_info = dev_get_drvdata(dev);
185 struct adt7310_chip_info *chip = dev_info->dev_data;
188 config = chip->config & ADT7310_MODE_MASK;
192 return sprintf(buf, "power-down\n");
193 case ADT7310_ONESHOT:
194 return sprintf(buf, "one-shot\n");
196 return sprintf(buf, "sps\n");
198 return sprintf(buf, "full\n");
202 static ssize_t adt7310_store_mode(struct device *dev,
203 struct device_attribute *attr,
207 struct iio_dev *dev_info = dev_get_drvdata(dev);
208 struct adt7310_chip_info *chip = dev_info->dev_data;
212 ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
216 config = chip->config & (~ADT7310_MODE_MASK);
217 if (strcmp(buf, "power-down"))
218 config |= ADT7310_PD;
219 else if (strcmp(buf, "one-shot"))
220 config |= ADT7310_ONESHOT;
221 else if (strcmp(buf, "sps"))
222 config |= ADT7310_SPS;
224 ret = adt7310_spi_write_byte(chip, ADT7310_CONFIG, config);
228 chip->config = config;
233 static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
238 static ssize_t adt7310_show_available_modes(struct device *dev,
239 struct device_attribute *attr,
242 return sprintf(buf, "full\none-shot\nsps\npower-down\n");
245 static IIO_DEVICE_ATTR(available_modes, S_IRUGO, adt7310_show_available_modes, NULL, 0);
247 static ssize_t adt7310_show_resolution(struct device *dev,
248 struct device_attribute *attr,
251 struct iio_dev *dev_info = dev_get_drvdata(dev);
252 struct adt7310_chip_info *chip = dev_info->dev_data;
256 ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
260 if (chip->config & ADT7310_RESOLUTION)
265 return sprintf(buf, "%d bits\n", bits);
268 static ssize_t adt7310_store_resolution(struct device *dev,
269 struct device_attribute *attr,
273 struct iio_dev *dev_info = dev_get_drvdata(dev);
274 struct adt7310_chip_info *chip = dev_info->dev_data;
279 ret = strict_strtoul(buf, 10, &data);
283 ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
287 config = chip->config & (~ADT7310_RESOLUTION);
289 config |= ADT7310_RESOLUTION;
291 ret = adt7310_spi_write_byte(chip, ADT7310_CONFIG, config);
295 chip->config = config;
300 static IIO_DEVICE_ATTR(resolution, S_IRUGO | S_IWUSR,
301 adt7310_show_resolution,
302 adt7310_store_resolution,
305 static ssize_t adt7310_show_id(struct device *dev,
306 struct device_attribute *attr,
309 struct iio_dev *dev_info = dev_get_drvdata(dev);
310 struct adt7310_chip_info *chip = dev_info->dev_data;
314 ret = adt7310_spi_read_byte(chip, ADT7310_ID, &id);
318 return sprintf(buf, "device id: 0x%x\nmanufactory id: 0x%x\n",
319 id & ADT7310_DEVICE_ID_MASK,
320 (id & ADT7310_MANUFACTORY_ID_MASK) >> ADT7310_MANUFACTORY_ID_OFFSET);
323 static IIO_DEVICE_ATTR(id, S_IRUGO | S_IWUSR,
328 static ssize_t adt7310_convert_temperature(struct adt7310_chip_info *chip,
333 if (chip->config & ADT7310_RESOLUTION) {
334 if (data & ADT7310_T16_VALUE_SIGN) {
335 /* convert supplement to positive value */
336 data = (u16)((ADT7310_T16_VALUE_SIGN << 1) - (u32)data);
339 return sprintf(buf, "%c%d.%.7d\n", sign,
340 (data >> ADT7310_T16_VALUE_FLOAT_OFFSET),
341 (data & ADT7310_T16_VALUE_FLOAT_MASK) * 78125);
343 if (data & ADT7310_T13_VALUE_SIGN) {
344 /* convert supplement to positive value */
345 data >>= ADT7310_T13_VALUE_OFFSET;
346 data = (ADT7310_T13_VALUE_SIGN << 1) - data;
349 return sprintf(buf, "%c%d.%.4d\n", sign,
350 (data >> ADT7310_T13_VALUE_FLOAT_OFFSET),
351 (data & ADT7310_T13_VALUE_FLOAT_MASK) * 625);
355 static ssize_t adt7310_show_value(struct device *dev,
356 struct device_attribute *attr,
359 struct iio_dev *dev_info = dev_get_drvdata(dev);
360 struct adt7310_chip_info *chip = dev_info->dev_data;
366 ret = adt7310_spi_read_byte(chip, ADT7310_STATUS, &status);
372 } while (status & ADT7310_STAT_NOT_RDY);
374 ret = adt7310_spi_read_word(chip, ADT7310_TEMPERATURE, &data);
378 return adt7310_convert_temperature(chip, data, buf);
381 static IIO_DEVICE_ATTR(value, S_IRUGO, adt7310_show_value, NULL, 0);
383 static ssize_t adt7310_show_name(struct device *dev,
384 struct device_attribute *attr,
387 struct iio_dev *dev_info = dev_get_drvdata(dev);
388 struct adt7310_chip_info *chip = dev_info->dev_data;
389 return sprintf(buf, "%s\n", chip->name);
392 static IIO_DEVICE_ATTR(name, S_IRUGO, adt7310_show_name, NULL, 0);
394 static struct attribute *adt7310_attributes[] = {
395 &iio_dev_attr_available_modes.dev_attr.attr,
396 &iio_dev_attr_mode.dev_attr.attr,
397 &iio_dev_attr_resolution.dev_attr.attr,
398 &iio_dev_attr_id.dev_attr.attr,
399 &iio_dev_attr_value.dev_attr.attr,
400 &iio_dev_attr_name.dev_attr.attr,
404 static const struct attribute_group adt7310_attribute_group = {
405 .attrs = adt7310_attributes,
409 * temperature bound events
412 #define IIO_EVENT_CODE_ADT7310_ABOVE_ALARM IIO_BUFFER_EVENT_CODE(0)
413 #define IIO_EVENT_CODE_ADT7310_BELLOW_ALARM IIO_BUFFER_EVENT_CODE(1)
414 #define IIO_EVENT_CODE_ADT7310_ABOVE_CRIT IIO_BUFFER_EVENT_CODE(2)
416 static void adt7310_interrupt_bh(struct work_struct *work_s)
418 struct adt7310_chip_info *chip =
419 container_of(work_s, struct adt7310_chip_info, thresh_work);
422 if (adt7310_spi_read_byte(chip, ADT7310_STATUS, &status))
425 if (status & ADT7310_STAT_T_HIGH)
426 iio_push_event(chip->indio_dev, 0,
427 IIO_EVENT_CODE_ADT7310_ABOVE_ALARM,
428 chip->last_timestamp);
429 if (status & ADT7310_STAT_T_LOW)
430 iio_push_event(chip->indio_dev, 0,
431 IIO_EVENT_CODE_ADT7310_BELLOW_ALARM,
432 chip->last_timestamp);
433 if (status & ADT7310_STAT_T_CRIT)
434 iio_push_event(chip->indio_dev, 0,
435 IIO_EVENT_CODE_ADT7310_ABOVE_CRIT,
436 chip->last_timestamp);
439 static int adt7310_interrupt(struct iio_dev *dev_info,
444 struct adt7310_chip_info *chip = dev_info->dev_data;
446 chip->last_timestamp = timestamp;
447 schedule_work(&chip->thresh_work);
452 IIO_EVENT_SH(adt7310, &adt7310_interrupt);
453 IIO_EVENT_SH(adt7310_ct, &adt7310_interrupt);
455 static ssize_t adt7310_show_event_mode(struct device *dev,
456 struct device_attribute *attr,
459 struct iio_dev *dev_info = dev_get_drvdata(dev);
460 struct adt7310_chip_info *chip = dev_info->dev_data;
463 ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
467 if (chip->config & ADT7310_EVENT_MODE)
468 return sprintf(buf, "interrupt\n");
470 return sprintf(buf, "comparator\n");
473 static ssize_t adt7310_set_event_mode(struct device *dev,
474 struct device_attribute *attr,
478 struct iio_dev *dev_info = dev_get_drvdata(dev);
479 struct adt7310_chip_info *chip = dev_info->dev_data;
483 ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
487 config = chip->config &= ~ADT7310_EVENT_MODE;
488 if (strcmp(buf, "comparator") != 0)
489 config |= ADT7310_EVENT_MODE;
491 ret = adt7310_spi_write_byte(chip, ADT7310_CONFIG, config);
495 chip->config = config;
500 static ssize_t adt7310_show_available_event_modes(struct device *dev,
501 struct device_attribute *attr,
504 return sprintf(buf, "comparator\ninterrupt\n");
507 static ssize_t adt7310_show_fault_queue(struct device *dev,
508 struct device_attribute *attr,
511 struct iio_dev *dev_info = dev_get_drvdata(dev);
512 struct adt7310_chip_info *chip = dev_info->dev_data;
515 ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
519 return sprintf(buf, "%d\n", chip->config & ADT7310_FAULT_QUEUE_MASK);
522 static ssize_t adt7310_set_fault_queue(struct device *dev,
523 struct device_attribute *attr,
527 struct iio_dev *dev_info = dev_get_drvdata(dev);
528 struct adt7310_chip_info *chip = dev_info->dev_data;
533 ret = strict_strtoul(buf, 10, &data);
537 ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
541 config = chip->config & ~ADT7310_FAULT_QUEUE_MASK;
543 ret = adt7310_spi_write_byte(chip, ADT7310_CONFIG, config);
547 chip->config = config;
552 static inline ssize_t adt7310_show_t_bound(struct device *dev,
553 struct device_attribute *attr,
557 struct iio_dev *dev_info = dev_get_drvdata(dev);
558 struct adt7310_chip_info *chip = dev_info->dev_data;
562 ret = adt7310_spi_read_word(chip, bound_reg, &data);
566 return adt7310_convert_temperature(chip, data, buf);
569 static inline ssize_t adt7310_set_t_bound(struct device *dev,
570 struct device_attribute *attr,
575 struct iio_dev *dev_info = dev_get_drvdata(dev);
576 struct adt7310_chip_info *chip = dev_info->dev_data;
582 pos = strchr(buf, '.');
584 ret = strict_strtol(buf, 10, &tmp1);
586 if (ret || tmp1 > 127 || tmp1 < -128)
592 if (chip->config & ADT7310_RESOLUTION) {
593 if (len > ADT7310_T16_VALUE_FLOAT_OFFSET)
594 len = ADT7310_T16_VALUE_FLOAT_OFFSET;
596 ret = strict_strtol(pos, 10, &tmp2);
599 tmp2 = (tmp2 / 78125) * 78125;
601 if (len > ADT7310_T13_VALUE_FLOAT_OFFSET)
602 len = ADT7310_T13_VALUE_FLOAT_OFFSET;
604 ret = strict_strtol(pos, 10, &tmp2);
607 tmp2 = (tmp2 / 625) * 625;
616 if (chip->config & ADT7310_RESOLUTION) {
617 data = (data << ADT7310_T16_VALUE_FLOAT_OFFSET) |
618 (tmp2 & ADT7310_T16_VALUE_FLOAT_MASK);
621 /* convert positive value to supplyment */
622 data = (u16)((ADT7310_T16_VALUE_SIGN << 1) - (u32)data);
624 data = (data << ADT7310_T13_VALUE_FLOAT_OFFSET) |
625 (tmp2 & ADT7310_T13_VALUE_FLOAT_MASK);
628 /* convert positive value to supplyment */
629 data = (ADT7310_T13_VALUE_SIGN << 1) - data;
630 data <<= ADT7310_T13_VALUE_OFFSET;
633 ret = adt7310_spi_write_word(chip, bound_reg, data);
640 static ssize_t adt7310_show_t_alarm_high(struct device *dev,
641 struct device_attribute *attr,
644 return adt7310_show_t_bound(dev, attr,
645 ADT7310_T_ALARM_HIGH, buf);
648 static inline ssize_t adt7310_set_t_alarm_high(struct device *dev,
649 struct device_attribute *attr,
653 return adt7310_set_t_bound(dev, attr,
654 ADT7310_T_ALARM_HIGH, buf, len);
657 static ssize_t adt7310_show_t_alarm_low(struct device *dev,
658 struct device_attribute *attr,
661 return adt7310_show_t_bound(dev, attr,
662 ADT7310_T_ALARM_LOW, buf);
665 static inline ssize_t adt7310_set_t_alarm_low(struct device *dev,
666 struct device_attribute *attr,
670 return adt7310_set_t_bound(dev, attr,
671 ADT7310_T_ALARM_LOW, buf, len);
674 static ssize_t adt7310_show_t_crit(struct device *dev,
675 struct device_attribute *attr,
678 return adt7310_show_t_bound(dev, attr,
679 ADT7310_T_CRIT, buf);
682 static inline ssize_t adt7310_set_t_crit(struct device *dev,
683 struct device_attribute *attr,
687 return adt7310_set_t_bound(dev, attr,
688 ADT7310_T_CRIT, buf, len);
691 static ssize_t adt7310_show_t_hyst(struct device *dev,
692 struct device_attribute *attr,
695 struct iio_dev *dev_info = dev_get_drvdata(dev);
696 struct adt7310_chip_info *chip = dev_info->dev_data;
700 ret = adt7310_spi_read_byte(chip, ADT7310_T_HYST, &t_hyst);
704 return sprintf(buf, "%d\n", t_hyst & ADT7310_T_HYST_MASK);
707 static inline ssize_t adt7310_set_t_hyst(struct device *dev,
708 struct device_attribute *attr,
712 struct iio_dev *dev_info = dev_get_drvdata(dev);
713 struct adt7310_chip_info *chip = dev_info->dev_data;
718 ret = strict_strtol(buf, 10, &data);
720 if (ret || data > ADT7310_T_HYST_MASK)
725 ret = adt7310_spi_write_byte(chip, ADT7310_T_HYST, t_hyst);
732 IIO_EVENT_ATTR_SH(event_mode, iio_event_adt7310,
733 adt7310_show_event_mode, adt7310_set_event_mode, 0);
734 IIO_EVENT_ATTR_SH(available_event_modes, iio_event_adt7310,
735 adt7310_show_available_event_modes, NULL, 0);
736 IIO_EVENT_ATTR_SH(fault_queue, iio_event_adt7310,
737 adt7310_show_fault_queue, adt7310_set_fault_queue, 0);
738 IIO_EVENT_ATTR_SH(t_alarm_high, iio_event_adt7310,
739 adt7310_show_t_alarm_high, adt7310_set_t_alarm_high, 0);
740 IIO_EVENT_ATTR_SH(t_alarm_low, iio_event_adt7310,
741 adt7310_show_t_alarm_low, adt7310_set_t_alarm_low, 0);
742 IIO_EVENT_ATTR_SH(t_crit, iio_event_adt7310_ct,
743 adt7310_show_t_crit, adt7310_set_t_crit, 0);
744 IIO_EVENT_ATTR_SH(t_hyst, iio_event_adt7310,
745 adt7310_show_t_hyst, adt7310_set_t_hyst, 0);
747 static struct attribute *adt7310_event_int_attributes[] = {
748 &iio_event_attr_event_mode.dev_attr.attr,
749 &iio_event_attr_available_event_modes.dev_attr.attr,
750 &iio_event_attr_fault_queue.dev_attr.attr,
751 &iio_event_attr_t_alarm_high.dev_attr.attr,
752 &iio_event_attr_t_alarm_low.dev_attr.attr,
753 &iio_event_attr_t_hyst.dev_attr.attr,
757 static struct attribute *adt7310_event_ct_attributes[] = {
758 &iio_event_attr_event_mode.dev_attr.attr,
759 &iio_event_attr_available_event_modes.dev_attr.attr,
760 &iio_event_attr_fault_queue.dev_attr.attr,
761 &iio_event_attr_t_crit.dev_attr.attr,
762 &iio_event_attr_t_hyst.dev_attr.attr,
766 static struct attribute_group adt7310_event_attribute_group[ADT7310_IRQS] = {
768 .attrs = adt7310_event_int_attributes,
771 .attrs = adt7310_event_ct_attributes,
776 * device probe and remove
779 static int __devinit adt7310_probe(struct spi_device *spi_dev)
781 struct adt7310_chip_info *chip;
783 unsigned long *adt7310_platform_data = spi_dev->dev.platform_data;
784 unsigned long irq_flags;
786 chip = kzalloc(sizeof(struct adt7310_chip_info), GFP_KERNEL);
791 /* this is only used for device removal purposes */
792 dev_set_drvdata(&spi_dev->dev, chip);
794 chip->spi_dev = spi_dev;
795 chip->name = spi_dev->modalias;
797 chip->indio_dev = iio_allocate_device();
798 if (chip->indio_dev == NULL) {
800 goto error_free_chip;
803 chip->indio_dev->dev.parent = &spi_dev->dev;
804 chip->indio_dev->attrs = &adt7310_attribute_group;
805 chip->indio_dev->event_attrs = adt7310_event_attribute_group;
806 chip->indio_dev->dev_data = (void *)chip;
807 chip->indio_dev->driver_module = THIS_MODULE;
808 chip->indio_dev->num_interrupt_lines = ADT7310_IRQS;
809 chip->indio_dev->modes = INDIO_DIRECT_MODE;
811 ret = iio_device_register(chip->indio_dev);
815 /* CT critcal temperature event. line 0 */
817 if (adt7310_platform_data[2])
818 irq_flags = adt7310_platform_data[2];
820 irq_flags = IRQF_TRIGGER_LOW;
821 ret = iio_register_interrupt_line(spi_dev->irq,
827 goto error_unreg_dev;
830 * The event handler list element refer to iio_event_adt7310.
831 * All event attributes bind to the same event handler.
832 * One event handler can only be added to one event list.
834 iio_add_event_to_list(&iio_event_adt7310,
835 &chip->indio_dev->interrupts[0]->ev_list);
838 /* INT bound temperature alarm event. line 1 */
839 if (adt7310_platform_data[0]) {
840 ret = iio_register_interrupt_line(adt7310_platform_data[0],
843 adt7310_platform_data[1],
846 goto error_unreg_ct_irq;
849 * The event handler list element refer to iio_event_adt7310.
850 * All event attributes bind to the same event handler.
851 * One event handler can only be added to one event list.
853 iio_add_event_to_list(&iio_event_adt7310_ct,
854 &chip->indio_dev->interrupts[1]->ev_list);
857 if (spi_dev->irq && adt7310_platform_data[0]) {
858 INIT_WORK(&chip->thresh_work, adt7310_interrupt_bh);
860 ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
863 goto error_unreg_int_irq;
866 /* set irq polarity low level */
867 chip->config &= ~ADT7310_CT_POLARITY;
869 if (adt7310_platform_data[1] & IRQF_TRIGGER_HIGH)
870 chip->config |= ADT7310_INT_POLARITY;
872 chip->config &= ~ADT7310_INT_POLARITY;
874 ret = adt7310_spi_write_byte(chip, ADT7310_CONFIG, chip->config);
877 goto error_unreg_int_irq;
881 dev_info(&spi_dev->dev, "%s temperature sensor registered.\n",
887 iio_unregister_interrupt_line(chip->indio_dev, 1);
889 iio_unregister_interrupt_line(chip->indio_dev, 0);
891 iio_device_unregister(chip->indio_dev);
893 iio_free_device(chip->indio_dev);
900 static int __devexit adt7310_remove(struct spi_device *spi_dev)
902 struct adt7310_chip_info *chip = dev_get_drvdata(&spi_dev->dev);
903 struct iio_dev *indio_dev = chip->indio_dev;
904 unsigned long *adt7310_platform_data = spi_dev->dev.platform_data;
906 dev_set_drvdata(&spi_dev->dev, NULL);
907 if (adt7310_platform_data[0])
908 iio_unregister_interrupt_line(indio_dev, 1);
910 iio_unregister_interrupt_line(indio_dev, 0);
911 iio_device_unregister(indio_dev);
912 iio_free_device(chip->indio_dev);
918 static const struct spi_device_id adt7310_id[] = {
923 MODULE_DEVICE_TABLE(spi, adt7310_id);
925 static struct spi_driver adt7310_driver = {
928 .bus = &spi_bus_type,
929 .owner = THIS_MODULE,
931 .probe = adt7310_probe,
932 .remove = __devexit_p(adt7310_remove),
933 .id_table = adt7310_id,
936 static __init int adt7310_init(void)
938 return spi_register_driver(&adt7310_driver);
941 static __exit void adt7310_exit(void)
943 spi_unregister_driver(&adt7310_driver);
947 MODULE_DESCRIPTION("Analog Devices ADT7310 digital"
948 " temperature sensor driver");
949 MODULE_LICENSE("GPL v2");
951 module_init(adt7310_init);
952 module_exit(adt7310_exit);