i2c-eg20t: change timeout value 50msec to 1000msec
[zen-stable.git] / drivers / staging / iio / resolver / ad2s90.c
blob2a86f582ddf1065e71744ddc2e4be322cd104851
1 /*
2 * ad2s90.c simple support for the ADI Resolver to Digital Converters: AD2S90
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/module.h>
19 #include "../iio.h"
20 #include "../sysfs.h"
22 struct ad2s90_state {
23 struct mutex lock;
24 struct spi_device *sdev;
25 u8 rx[2] ____cacheline_aligned;
28 static int ad2s90_read_raw(struct iio_dev *indio_dev,
29 struct iio_chan_spec const *chan,
30 int *val,
31 int *val2,
32 long m)
34 int ret;
35 struct ad2s90_state *st = iio_priv(indio_dev);
37 mutex_lock(&st->lock);
38 ret = spi_read(st->sdev, st->rx, 2);
39 if (ret)
40 goto error_ret;
41 *val = (((u16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4);
43 error_ret:
44 mutex_unlock(&st->lock);
46 return IIO_VAL_INT;
49 static const struct iio_info ad2s90_info = {
50 .read_raw = &ad2s90_read_raw,
51 .driver_module = THIS_MODULE,
54 static const struct iio_chan_spec ad2s90_chan = {
55 .type = IIO_ANGL,
56 .indexed = 1,
57 .channel = 0,
60 static int __devinit ad2s90_probe(struct spi_device *spi)
62 struct iio_dev *indio_dev;
63 struct ad2s90_state *st;
64 int ret = 0;
66 indio_dev = iio_allocate_device(sizeof(*st));
67 if (indio_dev == NULL) {
68 ret = -ENOMEM;
69 goto error_ret;
71 st = iio_priv(indio_dev);
72 spi_set_drvdata(spi, indio_dev);
74 mutex_init(&st->lock);
75 st->sdev = spi;
76 indio_dev->dev.parent = &spi->dev;
77 indio_dev->info = &ad2s90_info;
78 indio_dev->modes = INDIO_DIRECT_MODE;
79 indio_dev->channels = &ad2s90_chan;
80 indio_dev->num_channels = 1;
81 indio_dev->name = spi_get_device_id(spi)->name;
83 ret = iio_device_register(indio_dev);
84 if (ret)
85 goto error_free_dev;
87 /* need 600ns between CS and the first falling edge of SCLK */
88 spi->max_speed_hz = 830000;
89 spi->mode = SPI_MODE_3;
90 spi_setup(spi);
92 return 0;
94 error_free_dev:
95 iio_free_device(indio_dev);
96 error_ret:
97 return ret;
100 static int __devexit ad2s90_remove(struct spi_device *spi)
102 iio_device_unregister(spi_get_drvdata(spi));
103 iio_free_device(spi_get_drvdata(spi));
105 return 0;
108 static const struct spi_device_id ad2s90_id[] = {
109 { "ad2s90" },
112 MODULE_DEVICE_TABLE(spi, ad2s90_id);
114 static struct spi_driver ad2s90_driver = {
115 .driver = {
116 .name = "ad2s90",
117 .owner = THIS_MODULE,
119 .probe = ad2s90_probe,
120 .remove = __devexit_p(ad2s90_remove),
121 .id_table = ad2s90_id,
123 module_spi_driver(ad2s90_driver);
125 MODULE_AUTHOR("Graff Yang <graff.yang@gmail.com>");
126 MODULE_DESCRIPTION("Analog Devices AD2S90 Resolver to Digital SPI driver");
127 MODULE_LICENSE("GPL v2");