2 * ad2s1210.c support for the ADI Resolver to Digital Converters: AD2S1210
4 * Copyright (c) 2010-2010 Analog Devices Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/types.h>
12 #include <linux/mutex.h>
13 #include <linux/device.h>
14 #include <linux/spi/spi.h>
15 #include <linux/slab.h>
16 #include <linux/sysfs.h>
17 #include <linux/delay.h>
18 #include <linux/gpio.h>
23 #define DRV_NAME "ad2s1210"
25 #define DEF_CONTROL 0x7E
27 #define MSB_IS_HIGH 0x80
28 #define MSB_IS_LOW 0x7F
29 #define PHASE_LOCK_RANGE_44 0x20
30 #define ENABLE_HYSTERESIS 0x10
31 #define SET_ENRES1 0x08
32 #define SET_ENRES0 0x04
36 #define SET_ENRESOLUTION (SET_ENRES1 | SET_ENRES0)
37 #define SET_RESOLUTION (SET_RES1 | SET_RES0)
39 #define REG_POSITION 0x80
40 #define REG_VELOCITY 0x82
41 #define REG_LOS_THRD 0x88
42 #define REG_DOS_OVR_THRD 0x89
43 #define REG_DOS_MIS_THRD 0x8A
44 #define REG_DOS_RST_MAX_THRD 0x8B
45 #define REG_DOS_RST_MIN_THRD 0x8C
46 #define REG_LOT_HIGH_THRD 0x8D
47 #define REG_LOT_LOW_THRD 0x8E
48 #define REG_EXCIT_FREQ 0x91
49 #define REG_CONTROL 0x92
50 #define REG_SOFT_RESET 0xF0
51 #define REG_FAULT 0xFF
53 /* pin SAMPLE, A0, A1, RES0, RES1, is controlled by driver */
54 #define AD2S1210_SAA 3
55 #if defined(CONFIG_AD2S1210_GPIO_INPUT) || defined(CONFIG_AD2S1210_GPIO_OUTPUT)
56 # define AD2S1210_RES 2
58 # define AD2S1210_RES 0
60 #define AD2S1210_PN (AD2S1210_SAA + AD2S1210_RES)
62 #define AD2S1210_MIN_CLKIN 6144000
63 #define AD2S1210_MAX_CLKIN 10240000
64 #define AD2S1210_MIN_EXCIT 2000
65 #define AD2S1210_MAX_EXCIT 20000
66 #define AD2S1210_MIN_FCW 0x4
67 #define AD2S1210_MAX_FCW 0x50
69 /* default input clock on serial interface */
70 #define AD2S1210_DEF_CLKIN 8192000
71 /* clock period in nano second */
72 #define AD2S1210_DEF_TCK (1000000000/AD2S1210_DEF_CLKIN)
73 #define AD2S1210_DEF_EXCIT 10000
89 static unsigned int resolution_value[] = {
90 RES_10, RES_12, RES_14, RES_16};
92 struct ad2s1210_state {
95 struct spi_device *sdev;
96 struct spi_transfer xfer;
97 unsigned int hysteresis;
98 unsigned int old_data;
99 enum ad2s1210_mode mode;
100 enum ad2s1210_res resolution;
103 unsigned short sample;
112 static inline void start_sample(struct ad2s1210_state *st)
114 gpio_set_value(st->sample, 0);
117 static inline void stop_sample(struct ad2s1210_state *st)
119 gpio_set_value(st->sample, 1);
122 static inline void set_mode(enum ad2s1210_mode mode, struct ad2s1210_state *st)
126 gpio_set_value(st->a0, 0);
127 gpio_set_value(st->a1, 0);
130 gpio_set_value(st->a0, 0);
131 gpio_set_value(st->a1, 1);
134 gpio_set_value(st->a0, 1);
135 gpio_set_value(st->a1, 1);
138 /* set to reserved mode */
139 gpio_set_value(st->a0, 1);
140 gpio_set_value(st->a1, 0);
145 /* write 1 bytes (address or data) to the chip */
146 static int config_write(struct ad2s1210_state *st,
149 struct spi_message msg;
153 set_mode(MOD_CONFIG, st);
155 spi_message_init(&msg);
156 spi_message_add_tail(&st->xfer, &msg);
158 ret = spi_sync(st->sdev, &msg);
165 /* read value from one of the registers */
166 static int config_read(struct ad2s1210_state *st,
167 unsigned char address,
170 struct spi_message msg;
174 set_mode(MOD_CONFIG, st);
176 spi_message_init(&msg);
177 spi_message_add_tail(&st->xfer, &msg);
178 st->tx[0] = address | MSB_IS_HIGH;
179 st->tx[1] = REG_FAULT;
180 ret = spi_sync(st->sdev, &msg);
188 static inline void update_frequency_control_word(struct ad2s1210_state *st)
191 fcw = (unsigned char)(st->fexcit * (1 << 15) / st->fclkin);
192 if (fcw >= AD2S1210_MIN_FCW && fcw <= AD2S1210_MAX_FCW) {
193 config_write(st, REG_EXCIT_FREQ);
194 config_write(st, fcw);
196 pr_err("ad2s1210: FCW out of range\n");
199 #if defined(CONFIG_AD2S1210_GPIO_INPUT)
200 static inline unsigned char read_resolution_pin(struct ad2s1210_state *st)
203 data = (gpio_get_value(st->res0) << 1) |
204 gpio_get_value(st->res1);
205 return resolution_value[data];
207 #elif defined(CONFIG_AD2S1210_GPIO_OUTPUT)
208 static inline void set_resolution_pin(struct ad2s1210_state *st)
210 switch (st->resolution) {
212 gpio_set_value(st->res0, 0);
213 gpio_set_value(st->res1, 0);
216 gpio_set_value(st->res0, 0);
217 gpio_set_value(st->res1, 1);
220 gpio_set_value(st->res0, 1);
221 gpio_set_value(st->res1, 0);
224 gpio_set_value(st->res0, 1);
225 gpio_set_value(st->res1, 1);
231 static inline void soft_reset(struct ad2s1210_state *st)
233 config_write(st, REG_SOFT_RESET);
234 config_write(st, 0x0);
238 /* return the OLD DATA since last spi bus write */
239 static ssize_t ad2s1210_show_raw(struct device *dev,
240 struct device_attribute *attr, char *buf)
242 struct iio_dev *idev = dev_get_drvdata(dev);
243 struct ad2s1210_state *st = idev->dev_data;
246 mutex_lock(&st->lock);
248 ret = sprintf(buf, "0x%x\n", st->rx[0]);
252 mutex_unlock(&st->lock);
256 static ssize_t ad2s1210_store_raw(struct device *dev,
257 struct device_attribute *attr,
258 const char *buf, size_t len)
260 struct iio_dev *idev = dev_get_drvdata(dev);
261 struct ad2s1210_state *st = idev->dev_data;
266 ret = strict_strtoul(buf, 16, &udata);
270 mutex_lock(&st->lock);
271 config_write(st, data);
272 mutex_unlock(&st->lock);
276 static ssize_t ad2s1210_store_softreset(struct device *dev,
277 struct device_attribute *attr,
278 const char *buf, size_t len)
280 struct iio_dev *idev = dev_get_drvdata(dev);
281 struct ad2s1210_state *st = idev->dev_data;
282 mutex_lock(&st->lock);
284 mutex_unlock(&st->lock);
288 static ssize_t ad2s1210_show_fclkin(struct device *dev,
289 struct device_attribute *attr, char *buf)
291 struct iio_dev *idev = dev_get_drvdata(dev);
292 struct ad2s1210_state *st = idev->dev_data;
293 return sprintf(buf, "%d\n", st->fclkin);
296 static ssize_t ad2s1210_store_fclkin(struct device *dev,
297 struct device_attribute *attr,
298 const char *buf, size_t len)
300 struct iio_dev *idev = dev_get_drvdata(dev);
301 struct ad2s1210_state *st = idev->dev_data;
302 unsigned long fclkin;
305 ret = strict_strtoul(buf, 10, &fclkin);
306 if (!ret && fclkin >= AD2S1210_MIN_CLKIN &&
307 fclkin <= AD2S1210_MAX_CLKIN) {
308 mutex_lock(&st->lock);
311 pr_err("ad2s1210: fclkin out of range\n");
314 update_frequency_control_word(st);
316 mutex_unlock(&st->lock);
320 static ssize_t ad2s1210_show_fexcit(struct device *dev,
321 struct device_attribute *attr, char *buf)
323 struct iio_dev *idev = dev_get_drvdata(dev);
324 struct ad2s1210_state *st = idev->dev_data;
325 return sprintf(buf, "%d\n", st->fexcit);
328 static ssize_t ad2s1210_store_fexcit(struct device *dev,
329 struct device_attribute *attr,
330 const char *buf, size_t len)
332 struct iio_dev *idev = dev_get_drvdata(dev);
333 struct ad2s1210_state *st = idev->dev_data;
334 unsigned long fexcit;
337 ret = strict_strtoul(buf, 10, &fexcit);
338 if (!ret && fexcit >= AD2S1210_MIN_EXCIT &&
339 fexcit <= AD2S1210_MAX_EXCIT) {
340 mutex_lock(&st->lock);
343 pr_err("ad2s1210: excitation frequency out of range\n");
346 update_frequency_control_word(st);
348 mutex_unlock(&st->lock);
352 static ssize_t ad2s1210_show_control(struct device *dev,
353 struct device_attribute *attr, char *buf)
355 struct iio_dev *idev = dev_get_drvdata(dev);
356 struct ad2s1210_state *st = idev->dev_data;
358 mutex_lock(&st->lock);
359 config_read(st, REG_CONTROL, &data);
360 mutex_unlock(&st->lock);
361 return sprintf(buf, "0x%x\n", data);
364 static ssize_t ad2s1210_store_control(struct device *dev,
365 struct device_attribute *attr,
366 const char *buf, size_t len)
368 struct iio_dev *idev = dev_get_drvdata(dev);
369 struct ad2s1210_state *st = idev->dev_data;
374 ret = strict_strtoul(buf, 16, &udata);
379 mutex_lock(&st->lock);
380 config_write(st, REG_CONTROL);
381 data = udata & MSB_IS_LOW;
382 config_write(st, data);
383 config_read(st, REG_CONTROL, &data);
384 if (data & MSB_IS_HIGH) {
386 pr_err("ad2s1210: write control register fail\n");
389 st->resolution = resolution_value[data & SET_RESOLUTION];
390 #if defined(CONFIG_AD2S1210_GPIO_INPUT)
391 data = read_resolution_pin(st);
392 if (data != st->resolution)
393 pr_warning("ad2s1210: resolution settings not match\n");
394 #elif defined(CONFIG_AD2S1210_GPIO_OUTPUT)
395 set_resolution_pin(st);
398 if (data & ENABLE_HYSTERESIS)
403 mutex_unlock(&st->lock);
407 static ssize_t ad2s1210_show_resolution(struct device *dev,
408 struct device_attribute *attr, char *buf)
410 struct iio_dev *idev = dev_get_drvdata(dev);
411 struct ad2s1210_state *st = idev->dev_data;
412 return sprintf(buf, "%d\n", st->resolution);
415 static ssize_t ad2s1210_store_resolution(struct device *dev,
416 struct device_attribute *attr,
417 const char *buf, size_t len)
419 struct iio_dev *idev = dev_get_drvdata(dev);
420 struct ad2s1210_state *st = idev->dev_data;
425 ret = strict_strtoul(buf, 10, &udata);
426 if (ret || udata < RES_10 || udata > RES_16) {
427 pr_err("ad2s1210: resolution out of range\n");
430 mutex_lock(&st->lock);
431 config_read(st, REG_CONTROL, &data);
432 data &= ~SET_RESOLUTION;
433 data |= (udata - RES_10) >> 1;
434 config_write(st, REG_CONTROL);
435 config_write(st, data & MSB_IS_LOW);
436 config_read(st, REG_CONTROL, &data);
437 if (data & MSB_IS_HIGH) {
439 pr_err("ad2s1210: setting resolution fail\n");
442 st->resolution = resolution_value[data & SET_RESOLUTION];
443 #if defined(CONFIG_AD2S1210_GPIO_INPUT)
444 data = read_resolution_pin(st);
445 if (data != st->resolution)
446 pr_warning("ad2s1210: resolution settings not match\n");
447 #elif defined(CONFIG_AD2S1210_GPIO_OUTPUT)
448 set_resolution_pin(st);
452 mutex_unlock(&st->lock);
455 /* read the fault register since last sample */
456 static ssize_t ad2s1210_show_fault(struct device *dev,
457 struct device_attribute *attr, char *buf)
462 struct iio_dev *idev = dev_get_drvdata(dev);
463 struct ad2s1210_state *st = idev->dev_data;
465 mutex_lock(&st->lock);
466 ret = config_read(st, REG_FAULT, &data);
470 len = sprintf(buf, "0x%x\n", data);
472 mutex_unlock(&st->lock);
473 return ret ? ret : len;
476 static ssize_t ad2s1210_clear_fault(struct device *dev,
477 struct device_attribute *attr,
478 const char *buf, size_t len)
480 struct iio_dev *idev = dev_get_drvdata(dev);
481 struct ad2s1210_state *st = idev->dev_data;
484 mutex_lock(&st->lock);
486 /* delay (2 * tck + 20) nano seconds */
489 config_read(st, REG_FAULT, &data);
492 mutex_unlock(&st->lock);
497 static ssize_t ad2s1210_show_reg(struct device *dev,
498 struct device_attribute *attr, char *buf)
500 struct iio_dev *idev = dev_get_drvdata(dev);
501 struct ad2s1210_state *st = idev->dev_data;
503 struct iio_dev_attr *iattr = to_iio_dev_attr(attr);
505 mutex_lock(&st->lock);
506 config_read(st, iattr->address, &data);
507 mutex_unlock(&st->lock);
508 return sprintf(buf, "%d\n", data);
511 static ssize_t ad2s1210_store_reg(struct device *dev,
512 struct device_attribute *attr, const char *buf, size_t len)
514 struct iio_dev *idev = dev_get_drvdata(dev);
515 struct ad2s1210_state *st = idev->dev_data;
518 struct iio_dev_attr *iattr = to_iio_dev_attr(attr);
520 ret = strict_strtoul(buf, 10, &data);
523 mutex_lock(&st->lock);
524 config_write(st, iattr->address);
525 config_write(st, data & MSB_IS_LOW);
526 mutex_unlock(&st->lock);
530 static ssize_t ad2s1210_show_pos(struct device *dev,
531 struct device_attribute *attr, char *buf)
533 struct spi_message msg;
537 struct iio_dev *idev = dev_get_drvdata(dev);
538 struct ad2s1210_state *st = idev->dev_data;
541 mutex_lock(&st->lock);
543 /* delay (6 * tck + 20) nano seconds */
546 set_mode(MOD_POS, st);
548 spi_message_init(&msg);
549 spi_message_add_tail(&st->xfer, &msg);
550 ret = spi_sync(st->sdev, &msg);
553 pos = ((((u16)(st->rx[0])) << 8) | (st->rx[1]));
555 pos >>= 16 - st->resolution;
556 len = sprintf(buf, "%d\n", pos);
559 /* delay (2 * tck + 20) nano seconds */
561 mutex_unlock(&st->lock);
563 return ret ? ret : len;
566 static ssize_t ad2s1210_show_vel(struct device *dev,
567 struct device_attribute *attr, char *buf)
569 struct spi_message msg;
570 unsigned short negative;
574 struct iio_dev *idev = dev_get_drvdata(dev);
575 struct ad2s1210_state *st = idev->dev_data;
578 mutex_lock(&st->lock);
580 /* delay (6 * tck + 20) nano seconds */
583 set_mode(MOD_VEL, st);
585 spi_message_init(&msg);
586 spi_message_add_tail(&st->xfer, &msg);
587 ret = spi_sync(st->sdev, &msg);
590 negative = st->rx[0] & 0x80;
591 vel = ((((s16)(st->rx[0])) << 8) | (st->rx[1]));
592 vel >>= 16 - st->resolution;
594 negative = (0xffff >> st->resolution) << st->resolution;
597 len = sprintf(buf, "%d\n", vel);
600 /* delay (2 * tck + 20) nano seconds */
602 mutex_unlock(&st->lock);
604 return ret ? ret : len;
607 static ssize_t ad2s1210_show_pos_vel(struct device *dev,
608 struct device_attribute *attr, char *buf)
610 struct spi_message msg;
611 unsigned short negative;
616 struct iio_dev *idev = dev_get_drvdata(dev);
617 struct ad2s1210_state *st = idev->dev_data;
620 mutex_lock(&st->lock);
622 /* delay (6 * tck + 20) nano seconds */
625 set_mode(MOD_POS, st);
627 spi_message_init(&msg);
628 spi_message_add_tail(&st->xfer, &msg);
629 ret = spi_sync(st->sdev, &msg);
632 pos = ((((u16)(st->rx[0])) << 8) | (st->rx[1]));
634 pos >>= 16 - st->resolution;
635 len = sprintf(buf, "%d ", pos);
638 set_mode(MOD_VEL, st);
639 spi_message_init(&msg);
640 spi_message_add_tail(&st->xfer, &msg);
641 ret = spi_sync(st->sdev, &msg);
644 negative = st->rx[0] & 0x80;
645 vel = ((((s16)(st->rx[0])) << 8) | (st->rx[1]));
646 vel >>= 16 - st->resolution;
648 negative = (0xffff >> st->resolution) << st->resolution;
651 len += sprintf(buf + len, "%d\n", vel);
654 /* delay (2 * tck + 20) nano seconds */
656 mutex_unlock(&st->lock);
658 return ret ? ret : len;
661 static IIO_CONST_ATTR(description,
662 "Variable Resolution, 10-Bit to 16Bit R/D\n\
663 Converter with Reference Oscillator");
664 static IIO_DEVICE_ATTR(raw_io, S_IRUGO | S_IWUSR,
665 ad2s1210_show_raw, ad2s1210_store_raw, 0);
666 static IIO_DEVICE_ATTR(reset, S_IWUSR,
667 NULL, ad2s1210_store_softreset, 0);
668 static IIO_DEVICE_ATTR(fclkin, S_IRUGO | S_IWUSR,
669 ad2s1210_show_fclkin, ad2s1210_store_fclkin, 0);
670 static IIO_DEVICE_ATTR(fexcit, S_IRUGO | S_IWUSR,
671 ad2s1210_show_fexcit, ad2s1210_store_fexcit, 0);
672 static IIO_DEVICE_ATTR(control, S_IRUGO | S_IWUSR,
673 ad2s1210_show_control, ad2s1210_store_control, 0);
674 static IIO_DEVICE_ATTR(bits, S_IRUGO | S_IWUSR,
675 ad2s1210_show_resolution, ad2s1210_store_resolution, 0);
676 static IIO_DEVICE_ATTR(fault, S_IRUGO | S_IWUSR,
677 ad2s1210_show_fault, ad2s1210_clear_fault, 0);
678 static IIO_DEVICE_ATTR(pos, S_IRUGO,
679 ad2s1210_show_pos, NULL, 0);
680 static IIO_DEVICE_ATTR(vel, S_IRUGO,
681 ad2s1210_show_vel, NULL, 0);
682 static IIO_DEVICE_ATTR(pos_vel, S_IRUGO,
683 ad2s1210_show_pos_vel, NULL, 0);
684 static IIO_DEVICE_ATTR(los_thrd, S_IRUGO | S_IWUSR,
685 ad2s1210_show_reg, ad2s1210_store_reg, REG_LOS_THRD);
686 static IIO_DEVICE_ATTR(dos_ovr_thrd, S_IRUGO | S_IWUSR,
687 ad2s1210_show_reg, ad2s1210_store_reg, REG_DOS_OVR_THRD);
688 static IIO_DEVICE_ATTR(dos_mis_thrd, S_IRUGO | S_IWUSR,
689 ad2s1210_show_reg, ad2s1210_store_reg, REG_DOS_MIS_THRD);
690 static IIO_DEVICE_ATTR(dos_rst_max_thrd, S_IRUGO | S_IWUSR,
691 ad2s1210_show_reg, ad2s1210_store_reg, REG_DOS_RST_MAX_THRD);
692 static IIO_DEVICE_ATTR(dos_rst_min_thrd, S_IRUGO | S_IWUSR,
693 ad2s1210_show_reg, ad2s1210_store_reg, REG_DOS_RST_MIN_THRD);
694 static IIO_DEVICE_ATTR(lot_high_thrd, S_IRUGO | S_IWUSR,
695 ad2s1210_show_reg, ad2s1210_store_reg, REG_LOT_HIGH_THRD);
696 static IIO_DEVICE_ATTR(lot_low_thrd, S_IRUGO | S_IWUSR,
697 ad2s1210_show_reg, ad2s1210_store_reg, REG_LOT_LOW_THRD);
699 static struct attribute *ad2s1210_attributes[] = {
700 &iio_const_attr_description.dev_attr.attr,
701 &iio_dev_attr_raw_io.dev_attr.attr,
702 &iio_dev_attr_reset.dev_attr.attr,
703 &iio_dev_attr_fclkin.dev_attr.attr,
704 &iio_dev_attr_fexcit.dev_attr.attr,
705 &iio_dev_attr_control.dev_attr.attr,
706 &iio_dev_attr_bits.dev_attr.attr,
707 &iio_dev_attr_fault.dev_attr.attr,
708 &iio_dev_attr_pos.dev_attr.attr,
709 &iio_dev_attr_vel.dev_attr.attr,
710 &iio_dev_attr_pos_vel.dev_attr.attr,
711 &iio_dev_attr_los_thrd.dev_attr.attr,
712 &iio_dev_attr_dos_ovr_thrd.dev_attr.attr,
713 &iio_dev_attr_dos_mis_thrd.dev_attr.attr,
714 &iio_dev_attr_dos_rst_max_thrd.dev_attr.attr,
715 &iio_dev_attr_dos_rst_min_thrd.dev_attr.attr,
716 &iio_dev_attr_lot_high_thrd.dev_attr.attr,
717 &iio_dev_attr_lot_low_thrd.dev_attr.attr,
721 static const struct attribute_group ad2s1210_attribute_group = {
723 .attrs = ad2s1210_attributes,
726 static int __devinit ad2s1210_initial(struct ad2s1210_state *st)
731 mutex_lock(&st->lock);
732 #if defined(CONFIG_AD2S1210_GPIO_INPUT)
733 st->resolution = read_resolution_pin(st);
734 #elif defined(CONFIG_AD2S1210_GPIO_OUTPUT)
735 set_resolution_pin(st);
738 config_write(st, REG_CONTROL);
739 data = DEF_CONTROL & ~(SET_RESOLUTION);
740 data |= (st->resolution - RES_10) >> 1;
741 config_write(st, data);
742 ret = config_read(st, REG_CONTROL, &data);
746 if (data & MSB_IS_HIGH) {
751 update_frequency_control_word(st);
754 mutex_unlock(&st->lock);
758 static const struct iio_info ad2s1210_info = {
759 .attrs = &ad2s1210_attribute_group,
760 .driver_module = THIS_MODULE,
763 static int __devinit ad2s1210_probe(struct spi_device *spi)
765 struct ad2s1210_state *st;
767 unsigned short *pins = spi->dev.platform_data;
769 for (pn = 0; pn < AD2S1210_PN; pn++) {
770 if (gpio_request(pins[pn], DRV_NAME)) {
771 pr_err("%s: request gpio pin %d failed\n",
775 if (pn < AD2S1210_SAA)
776 gpio_direction_output(pins[pn], 1);
778 #if defined(CONFIG_AD2S1210_GPIO_INPUT)
779 gpio_direction_input(pins[pn]);
780 #elif defined(CONFIG_AD2S1210_GPIO_OUTPUT)
781 gpio_direction_output(pins[pn], 1);
786 st = kzalloc(sizeof(*st), GFP_KERNEL);
791 spi_set_drvdata(spi, st);
793 mutex_init(&st->lock);
795 st->xfer.tx_buf = st->tx;
796 st->xfer.rx_buf = st->rx;
798 st->mode = MOD_CONFIG;
799 st->resolution = RES_12;
800 st->fclkin = AD2S1210_DEF_CLKIN;
801 st->fexcit = AD2S1210_DEF_EXCIT;
802 st->sample = pins[0];
808 st->idev = iio_allocate_device(0);
809 if (st->idev == NULL) {
813 st->idev->dev.parent = &spi->dev;
815 st->idev->info = &ad2s1210_info;
816 st->idev->dev_data = (void *)(st);
817 st->idev->modes = INDIO_DIRECT_MODE;
819 ret = iio_device_register(st->idev);
823 if (spi->max_speed_hz != AD2S1210_DEF_CLKIN)
824 st->fclkin = spi->max_speed_hz;
825 spi->mode = SPI_MODE_3;
828 ad2s1210_initial(st);
832 iio_free_device(st->idev);
836 for (--pn; pn >= 0; pn--)
841 static int __devexit ad2s1210_remove(struct spi_device *spi)
843 struct ad2s1210_state *st = spi_get_drvdata(spi);
845 iio_device_unregister(st->idev);
851 static struct spi_driver ad2s1210_driver = {
854 .owner = THIS_MODULE,
856 .probe = ad2s1210_probe,
857 .remove = __devexit_p(ad2s1210_remove),
860 static __init int ad2s1210_spi_init(void)
862 return spi_register_driver(&ad2s1210_driver);
864 module_init(ad2s1210_spi_init);
866 static __exit void ad2s1210_spi_exit(void)
868 spi_unregister_driver(&ad2s1210_driver);
870 module_exit(ad2s1210_spi_exit);
872 MODULE_AUTHOR("Graff Yang <graff.yang@gmail.com>");
873 MODULE_DESCRIPTION("Analog Devices AD2S1210 Resolver to Digital SPI driver");
874 MODULE_LICENSE("GPL v2");