aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/iio/gyro/adis16130_core.c
diff options
context:
space:
mode:
authorJonathan Cameron <jic23@cam.ac.uk>2011-08-12 12:08:41 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2011-08-23 16:31:07 -0400
commita5e7363ca46d58eafa904130d801b23c59bd1ec4 (patch)
tree891a62ef3bfbbfc71cb385fdf097792f364e1227 /drivers/staging/iio/gyro/adis16130_core.c
parentb066b4f89bebb13febdbe179f9000d68a02f0996 (diff)
staging:iio:gyro:adis16130 drop control of adc resolution.
There is no clear use case for this functionality in a driver that only supports slow reading via sysfs. The interface use was non compliant with the abi motiving it being dropped. It can go back in if anyone ever implements buffered reading support for this device. Then it will be controlled as part of the buffering abi where this should indeed be correctly supported. Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk> Acked-by: Michael Hennerich <michael.hennerich@analog.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/iio/gyro/adis16130_core.c')
-rw-r--r--drivers/staging/iio/gyro/adis16130_core.c76
1 files changed, 4 insertions, 72 deletions
diff --git a/drivers/staging/iio/gyro/adis16130_core.c b/drivers/staging/iio/gyro/adis16130_core.c
index caf067ce98c..6d3cd6c2bff 100644
--- a/drivers/staging/iio/gyro/adis16130_core.c
+++ b/drivers/staging/iio/gyro/adis16130_core.c
@@ -41,34 +41,15 @@
41/** 41/**
42 * struct adis16130_state - device instance specific data 42 * struct adis16130_state - device instance specific data
43 * @us: actual spi_device to write data 43 * @us: actual spi_device to write data
44 * @mode: 24 bits (1) or 16 bits (0)
45 * @buf_lock: mutex to protect tx and rx 44 * @buf_lock: mutex to protect tx and rx
46 * @buf: unified tx/rx buffer 45 * @buf: unified tx/rx buffer
47 **/ 46 **/
48struct adis16130_state { 47struct adis16130_state {
49 struct spi_device *us; 48 struct spi_device *us;
50 u32 mode;
51 struct mutex buf_lock; 49 struct mutex buf_lock;
52 u8 buf[4] ____cacheline_aligned; 50 u8 buf[4] ____cacheline_aligned;
53}; 51};
54 52
55static int adis16130_spi_write(struct device *dev, u8 reg_addr,
56 u8 val)
57{
58 int ret;
59 struct iio_dev *indio_dev = dev_get_drvdata(dev);
60 struct adis16130_state *st = iio_priv(indio_dev);
61
62 mutex_lock(&st->buf_lock);
63 st->buf[0] = reg_addr;
64 st->buf[1] = val;
65
66 ret = spi_write(st->us, st->buf, 2);
67 mutex_unlock(&st->buf_lock);
68
69 return ret;
70}
71
72static int adis16130_spi_read(struct device *dev, u8 reg_addr, 53static int adis16130_spi_read(struct device *dev, u8 reg_addr,
73 u32 *val) 54 u32 *val)
74{ 55{
@@ -79,6 +60,7 @@ static int adis16130_spi_read(struct device *dev, u8 reg_addr,
79 struct spi_transfer xfer = { 60 struct spi_transfer xfer = {
80 .tx_buf = st->buf, 61 .tx_buf = st->buf,
81 .rx_buf = st->buf, 62 .rx_buf = st->buf,
63 .len = 4,
82 }; 64 };
83 65
84 mutex_lock(&st->buf_lock); 66 mutex_lock(&st->buf_lock);
@@ -86,22 +68,13 @@ static int adis16130_spi_read(struct device *dev, u8 reg_addr,
86 st->buf[0] = ADIS16130_CON_RD | reg_addr; 68 st->buf[0] = ADIS16130_CON_RD | reg_addr;
87 st->buf[1] = st->buf[2] = st->buf[3] = 0; 69 st->buf[1] = st->buf[2] = st->buf[3] = 0;
88 70
89 if (st->mode)
90 xfer.len = 4;
91 else
92 xfer.len = 3;
93 spi_message_init(&msg); 71 spi_message_init(&msg);
94 spi_message_add_tail(&xfer, &msg); 72 spi_message_add_tail(&xfer, &msg);
95 ret = spi_sync(st->us, &msg); 73 ret = spi_sync(st->us, &msg);
96 if (ret == 0) { 74 ret = spi_read(st->us, st->buf, 4);
97 if (st->mode)
98 *val = (st->buf[1] << 16) |
99 (st->buf[2] << 8) |
100 st->buf[3];
101 else
102 *val = (st->buf[1] << 8) | st->buf[2];
103 }
104 75
76 if (ret == 0)
77 *val = (st->buf[1] << 16) | (st->buf[2] << 8) | st->buf[3];
105 mutex_unlock(&st->buf_lock); 78 mutex_unlock(&st->buf_lock);
106 79
107 return ret; 80 return ret;
@@ -127,54 +100,14 @@ static ssize_t adis16130_val_read(struct device *dev,
127 return ret; 100 return ret;
128} 101}
129 102
130static ssize_t adis16130_bitsmode_read(struct device *dev,
131 struct device_attribute *attr,
132 char *buf)
133{
134 struct iio_dev *indio_dev = dev_get_drvdata(dev);
135 struct adis16130_state *st = iio_priv(indio_dev);
136
137 if (st->mode == 1)
138 return sprintf(buf, "s24\n");
139 else
140 return sprintf(buf, "s16\n");
141}
142
143static ssize_t adis16130_bitsmode_write(struct device *dev,
144 struct device_attribute *attr,
145 const char *buf,
146 size_t len)
147{
148 int ret;
149 u8 val;
150
151 if (sysfs_streq(buf, "s16"))
152 val = 0;
153 else if (sysfs_streq(buf, "s24"))
154 val = 1;
155 else
156 return -EINVAL;
157
158 ret = adis16130_spi_write(dev, ADIS16130_MODE, val);
159
160 return ret ? ret : len;
161}
162static IIO_DEVICE_ATTR(temp_raw, S_IRUGO, adis16130_val_read, NULL, 103static IIO_DEVICE_ATTR(temp_raw, S_IRUGO, adis16130_val_read, NULL,
163 ADIS16130_TEMPDATA); 104 ADIS16130_TEMPDATA);
164 105
165static IIO_DEV_ATTR_GYRO_Z(adis16130_val_read, ADIS16130_RATEDATA); 106static IIO_DEV_ATTR_GYRO_Z(adis16130_val_read, ADIS16130_RATEDATA);
166 107
167static IIO_DEVICE_ATTR(gyro_z_type, S_IWUSR | S_IRUGO, adis16130_bitsmode_read,
168 adis16130_bitsmode_write,
169 ADIS16130_MODE);
170
171static IIO_CONST_ATTR(gyro_z_type_available, "s16 s24");
172
173static struct attribute *adis16130_attributes[] = { 108static struct attribute *adis16130_attributes[] = {
174 &iio_dev_attr_temp_raw.dev_attr.attr, 109 &iio_dev_attr_temp_raw.dev_attr.attr,
175 &iio_dev_attr_gyro_z_raw.dev_attr.attr, 110 &iio_dev_attr_gyro_z_raw.dev_attr.attr,
176 &iio_dev_attr_gyro_z_type.dev_attr.attr,
177 &iio_const_attr_gyro_z_type_available.dev_attr.attr,
178 NULL 111 NULL
179}; 112};
180 113
@@ -208,7 +141,6 @@ static int __devinit adis16130_probe(struct spi_device *spi)
208 indio_dev->dev.parent = &spi->dev; 141 indio_dev->dev.parent = &spi->dev;
209 indio_dev->info = &adis16130_info; 142 indio_dev->info = &adis16130_info;
210 indio_dev->modes = INDIO_DIRECT_MODE; 143 indio_dev->modes = INDIO_DIRECT_MODE;
211 st->mode = 1;
212 144
213 ret = iio_device_register(indio_dev); 145 ret = iio_device_register(indio_dev);
214 if (ret) 146 if (ret)