aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2013-01-09 12:31:00 -0500
committerJonathan Cameron <jic23@kernel.org>2013-02-09 06:08:42 -0500
commit14543a00fc3ce6dac9f297535c502a0085a50467 (patch)
tree1c244bcc56bd4a48ee2c305856457d102d6eccbe /drivers/iio
parent6d9eecd418afb2c12e5db5be3d72f0f1df43bdd9 (diff)
iio: Use spi_sync_transfer()
Use the new spi_sync_transfer() helper function instead of open-coding it. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/accel/kxsd9.c6
-rw-r--r--drivers/iio/dac/ad5360.c7
-rw-r--r--drivers/iio/dac/ad5421.c7
-rw-r--r--drivers/iio/dac/ad5504.c6
-rw-r--r--drivers/iio/dac/ad5686.c7
-rw-r--r--drivers/iio/dac/ad5755.c7
-rw-r--r--drivers/iio/dac/ad5764.c7
-rw-r--r--drivers/iio/dac/ad5791.c6
-rw-r--r--drivers/iio/frequency/ad9523.c14
-rw-r--r--drivers/iio/gyro/adxrs450.c5
10 files changed, 11 insertions, 61 deletions
diff --git a/drivers/iio/accel/kxsd9.c b/drivers/iio/accel/kxsd9.c
index 4a24c2ee81a9..c2229a521ab9 100644
--- a/drivers/iio/accel/kxsd9.c
+++ b/drivers/iio/accel/kxsd9.c
@@ -94,7 +94,6 @@ error_ret:
94 94
95static int kxsd9_read(struct iio_dev *indio_dev, u8 address) 95static int kxsd9_read(struct iio_dev *indio_dev, u8 address)
96{ 96{
97 struct spi_message msg;
98 int ret; 97 int ret;
99 struct kxsd9_state *st = iio_priv(indio_dev); 98 struct kxsd9_state *st = iio_priv(indio_dev);
100 struct spi_transfer xfers[] = { 99 struct spi_transfer xfers[] = {
@@ -112,10 +111,7 @@ static int kxsd9_read(struct iio_dev *indio_dev, u8 address)
112 111
113 mutex_lock(&st->buf_lock); 112 mutex_lock(&st->buf_lock);
114 st->tx[0] = KXSD9_READ(address); 113 st->tx[0] = KXSD9_READ(address);
115 spi_message_init(&msg); 114 ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
116 spi_message_add_tail(&xfers[0], &msg);
117 spi_message_add_tail(&xfers[1], &msg);
118 ret = spi_sync(st->us, &msg);
119 if (ret) 115 if (ret)
120 return ret; 116 return ret;
121 return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0); 117 return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0);
diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c
index 54b46fd3aede..92771217f665 100644
--- a/drivers/iio/dac/ad5360.c
+++ b/drivers/iio/dac/ad5360.c
@@ -213,7 +213,6 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
213 unsigned int addr) 213 unsigned int addr)
214{ 214{
215 struct ad5360_state *st = iio_priv(indio_dev); 215 struct ad5360_state *st = iio_priv(indio_dev);
216 struct spi_message m;
217 int ret; 216 int ret;
218 struct spi_transfer t[] = { 217 struct spi_transfer t[] = {
219 { 218 {
@@ -226,10 +225,6 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
226 }, 225 },
227 }; 226 };
228 227
229 spi_message_init(&m);
230 spi_message_add_tail(&t[0], &m);
231 spi_message_add_tail(&t[1], &m);
232
233 mutex_lock(&indio_dev->mlock); 228 mutex_lock(&indio_dev->mlock);
234 229
235 st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) | 230 st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) |
@@ -237,7 +232,7 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
237 AD5360_READBACK_TYPE(type) | 232 AD5360_READBACK_TYPE(type) |
238 AD5360_READBACK_ADDR(addr)); 233 AD5360_READBACK_ADDR(addr));
239 234
240 ret = spi_sync(st->spi, &m); 235 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
241 if (ret >= 0) 236 if (ret >= 0)
242 ret = be32_to_cpu(st->data[1].d32) & 0xffff; 237 ret = be32_to_cpu(st->data[1].d32) & 0xffff;
243 238
diff --git a/drivers/iio/dac/ad5421.c b/drivers/iio/dac/ad5421.c
index 43be948db83e..6b86a638dad0 100644
--- a/drivers/iio/dac/ad5421.c
+++ b/drivers/iio/dac/ad5421.c
@@ -127,7 +127,6 @@ static int ad5421_write(struct iio_dev *indio_dev, unsigned int reg,
127static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg) 127static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg)
128{ 128{
129 struct ad5421_state *st = iio_priv(indio_dev); 129 struct ad5421_state *st = iio_priv(indio_dev);
130 struct spi_message m;
131 int ret; 130 int ret;
132 struct spi_transfer t[] = { 131 struct spi_transfer t[] = {
133 { 132 {
@@ -140,15 +139,11 @@ static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg)
140 }, 139 },
141 }; 140 };
142 141
143 spi_message_init(&m);
144 spi_message_add_tail(&t[0], &m);
145 spi_message_add_tail(&t[1], &m);
146
147 mutex_lock(&indio_dev->mlock); 142 mutex_lock(&indio_dev->mlock);
148 143
149 st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16)); 144 st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16));
150 145
151 ret = spi_sync(st->spi, &m); 146 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
152 if (ret >= 0) 147 if (ret >= 0)
153 ret = be32_to_cpu(st->data[1].d32) & 0xffff; 148 ret = be32_to_cpu(st->data[1].d32) & 0xffff;
154 149
diff --git a/drivers/iio/dac/ad5504.c b/drivers/iio/dac/ad5504.c
index 0661829f2773..e5e59749f109 100644
--- a/drivers/iio/dac/ad5504.c
+++ b/drivers/iio/dac/ad5504.c
@@ -85,11 +85,7 @@ static int ad5504_spi_read(struct spi_device *spi, u8 addr)
85 .rx_buf = &val, 85 .rx_buf = &val,
86 .len = 2, 86 .len = 2,
87 }; 87 };
88 struct spi_message m; 88 ret = spi_sync_transfer(spi, &t, 1);
89
90 spi_message_init(&m);
91 spi_message_add_tail(&t, &m);
92 ret = spi_sync(spi, &m);
93 89
94 if (ret < 0) 90 if (ret < 0)
95 return ret; 91 return ret;
diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index ca9609d7a15c..5e554af21703 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -117,18 +117,13 @@ static int ad5686_spi_read(struct ad5686_state *st, u8 addr)
117 .len = 3, 117 .len = 3,
118 }, 118 },
119 }; 119 };
120 struct spi_message m;
121 int ret; 120 int ret;
122 121
123 spi_message_init(&m);
124 spi_message_add_tail(&t[0], &m);
125 spi_message_add_tail(&t[1], &m);
126
127 st->data[0].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_READBACK_ENABLE) | 122 st->data[0].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_READBACK_ENABLE) |
128 AD5686_ADDR(addr)); 123 AD5686_ADDR(addr));
129 st->data[1].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_NOOP)); 124 st->data[1].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_NOOP));
130 125
131 ret = spi_sync(st->spi, &m); 126 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
132 if (ret < 0) 127 if (ret < 0)
133 return ret; 128 return ret;
134 129
diff --git a/drivers/iio/dac/ad5755.c b/drivers/iio/dac/ad5755.c
index 0869bbd27d30..71faabc6b14e 100644
--- a/drivers/iio/dac/ad5755.c
+++ b/drivers/iio/dac/ad5755.c
@@ -153,7 +153,6 @@ static int ad5755_write_ctrl(struct iio_dev *indio_dev, unsigned int channel,
153static int ad5755_read(struct iio_dev *indio_dev, unsigned int addr) 153static int ad5755_read(struct iio_dev *indio_dev, unsigned int addr)
154{ 154{
155 struct ad5755_state *st = iio_priv(indio_dev); 155 struct ad5755_state *st = iio_priv(indio_dev);
156 struct spi_message m;
157 int ret; 156 int ret;
158 struct spi_transfer t[] = { 157 struct spi_transfer t[] = {
159 { 158 {
@@ -167,16 +166,12 @@ static int ad5755_read(struct iio_dev *indio_dev, unsigned int addr)
167 }, 166 },
168 }; 167 };
169 168
170 spi_message_init(&m);
171 spi_message_add_tail(&t[0], &m);
172 spi_message_add_tail(&t[1], &m);
173
174 mutex_lock(&indio_dev->mlock); 169 mutex_lock(&indio_dev->mlock);
175 170
176 st->data[0].d32 = cpu_to_be32(AD5755_READ_FLAG | (addr << 16)); 171 st->data[0].d32 = cpu_to_be32(AD5755_READ_FLAG | (addr << 16));
177 st->data[1].d32 = cpu_to_be32(AD5755_NOOP); 172 st->data[1].d32 = cpu_to_be32(AD5755_NOOP);
178 173
179 ret = spi_sync(st->spi, &m); 174 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
180 if (ret >= 0) 175 if (ret >= 0)
181 ret = be32_to_cpu(st->data[1].d32) & 0xffff; 176 ret = be32_to_cpu(st->data[1].d32) & 0xffff;
182 177
diff --git a/drivers/iio/dac/ad5764.c b/drivers/iio/dac/ad5764.c
index 7f9045e6daa4..5b7acd3a2c77 100644
--- a/drivers/iio/dac/ad5764.c
+++ b/drivers/iio/dac/ad5764.c
@@ -135,7 +135,6 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg,
135 unsigned int *val) 135 unsigned int *val)
136{ 136{
137 struct ad5764_state *st = iio_priv(indio_dev); 137 struct ad5764_state *st = iio_priv(indio_dev);
138 struct spi_message m;
139 int ret; 138 int ret;
140 struct spi_transfer t[] = { 139 struct spi_transfer t[] = {
141 { 140 {
@@ -148,15 +147,11 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg,
148 }, 147 },
149 }; 148 };
150 149
151 spi_message_init(&m);
152 spi_message_add_tail(&t[0], &m);
153 spi_message_add_tail(&t[1], &m);
154
155 mutex_lock(&indio_dev->mlock); 150 mutex_lock(&indio_dev->mlock);
156 151
157 st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16)); 152 st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16));
158 153
159 ret = spi_sync(st->spi, &m); 154 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
160 if (ret >= 0) 155 if (ret >= 0)
161 *val = be32_to_cpu(st->data[1].d32) & 0xffff; 156 *val = be32_to_cpu(st->data[1].d32) & 0xffff;
162 157
diff --git a/drivers/iio/dac/ad5791.c b/drivers/iio/dac/ad5791.c
index 6407b5407ddd..8dfd3da8a07b 100644
--- a/drivers/iio/dac/ad5791.c
+++ b/drivers/iio/dac/ad5791.c
@@ -125,7 +125,6 @@ static int ad5791_spi_read(struct spi_device *spi, u8 addr, u32 *val)
125 u8 d8[4]; 125 u8 d8[4];
126 } data[3]; 126 } data[3];
127 int ret; 127 int ret;
128 struct spi_message msg;
129 struct spi_transfer xfers[] = { 128 struct spi_transfer xfers[] = {
130 { 129 {
131 .tx_buf = &data[0].d8[1], 130 .tx_buf = &data[0].d8[1],
@@ -144,10 +143,7 @@ static int ad5791_spi_read(struct spi_device *spi, u8 addr, u32 *val)
144 AD5791_ADDR(addr)); 143 AD5791_ADDR(addr));
145 data[1].d32 = cpu_to_be32(AD5791_ADDR(AD5791_ADDR_NOOP)); 144 data[1].d32 = cpu_to_be32(AD5791_ADDR(AD5791_ADDR_NOOP));
146 145
147 spi_message_init(&msg); 146 ret = spi_sync_transfer(spi, xfers, ARRAY_SIZE(xfers));
148 spi_message_add_tail(&xfers[0], &msg);
149 spi_message_add_tail(&xfers[1], &msg);
150 ret = spi_sync(spi, &msg);
151 147
152 *val = be32_to_cpu(data[2].d32); 148 *val = be32_to_cpu(data[2].d32);
153 149
diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
index 80307473e3a9..1ea132e239ea 100644
--- a/drivers/iio/frequency/ad9523.c
+++ b/drivers/iio/frequency/ad9523.c
@@ -287,7 +287,6 @@ struct ad9523_state {
287static int ad9523_read(struct iio_dev *indio_dev, unsigned addr) 287static int ad9523_read(struct iio_dev *indio_dev, unsigned addr)
288{ 288{
289 struct ad9523_state *st = iio_priv(indio_dev); 289 struct ad9523_state *st = iio_priv(indio_dev);
290 struct spi_message m;
291 int ret; 290 int ret;
292 291
293 /* We encode the register size 1..3 bytes into the register address. 292 /* We encode the register size 1..3 bytes into the register address.
@@ -305,15 +304,11 @@ static int ad9523_read(struct iio_dev *indio_dev, unsigned addr)
305 }, 304 },
306 }; 305 };
307 306
308 spi_message_init(&m);
309 spi_message_add_tail(&t[0], &m);
310 spi_message_add_tail(&t[1], &m);
311
312 st->data[0].d32 = cpu_to_be32(AD9523_READ | 307 st->data[0].d32 = cpu_to_be32(AD9523_READ |
313 AD9523_CNT(AD9523_TRANSF_LEN(addr)) | 308 AD9523_CNT(AD9523_TRANSF_LEN(addr)) |
314 AD9523_ADDR(addr)); 309 AD9523_ADDR(addr));
315 310
316 ret = spi_sync(st->spi, &m); 311 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
317 if (ret < 0) 312 if (ret < 0)
318 dev_err(&indio_dev->dev, "read failed (%d)", ret); 313 dev_err(&indio_dev->dev, "read failed (%d)", ret);
319 else 314 else
@@ -326,7 +321,6 @@ static int ad9523_read(struct iio_dev *indio_dev, unsigned addr)
326static int ad9523_write(struct iio_dev *indio_dev, unsigned addr, unsigned val) 321static int ad9523_write(struct iio_dev *indio_dev, unsigned addr, unsigned val)
327{ 322{
328 struct ad9523_state *st = iio_priv(indio_dev); 323 struct ad9523_state *st = iio_priv(indio_dev);
329 struct spi_message m;
330 int ret; 324 int ret;
331 struct spi_transfer t[] = { 325 struct spi_transfer t[] = {
332 { 326 {
@@ -338,16 +332,12 @@ static int ad9523_write(struct iio_dev *indio_dev, unsigned addr, unsigned val)
338 }, 332 },
339 }; 333 };
340 334
341 spi_message_init(&m);
342 spi_message_add_tail(&t[0], &m);
343 spi_message_add_tail(&t[1], &m);
344
345 st->data[0].d32 = cpu_to_be32(AD9523_WRITE | 335 st->data[0].d32 = cpu_to_be32(AD9523_WRITE |
346 AD9523_CNT(AD9523_TRANSF_LEN(addr)) | 336 AD9523_CNT(AD9523_TRANSF_LEN(addr)) |
347 AD9523_ADDR(addr)); 337 AD9523_ADDR(addr));
348 st->data[1].d32 = cpu_to_be32(val); 338 st->data[1].d32 = cpu_to_be32(val);
349 339
350 ret = spi_sync(st->spi, &m); 340 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
351 341
352 if (ret < 0) 342 if (ret < 0)
353 dev_err(&indio_dev->dev, "write failed (%d)", ret); 343 dev_err(&indio_dev->dev, "write failed (%d)", ret);
diff --git a/drivers/iio/gyro/adxrs450.c b/drivers/iio/gyro/adxrs450.c
index d9d43831c380..5b79953f7011 100644
--- a/drivers/iio/gyro/adxrs450.c
+++ b/drivers/iio/gyro/adxrs450.c
@@ -213,7 +213,6 @@ error_ret:
213static int adxrs450_spi_initial(struct adxrs450_state *st, 213static int adxrs450_spi_initial(struct adxrs450_state *st,
214 u32 *val, char chk) 214 u32 *val, char chk)
215{ 215{
216 struct spi_message msg;
217 int ret; 216 int ret;
218 u32 tx; 217 u32 tx;
219 struct spi_transfer xfers = { 218 struct spi_transfer xfers = {
@@ -228,9 +227,7 @@ static int adxrs450_spi_initial(struct adxrs450_state *st,
228 if (chk) 227 if (chk)
229 tx |= (ADXRS450_CHK | ADXRS450_P); 228 tx |= (ADXRS450_CHK | ADXRS450_P);
230 st->tx = cpu_to_be32(tx); 229 st->tx = cpu_to_be32(tx);
231 spi_message_init(&msg); 230 ret = spi_sync_transfer(st->us, &xfers, 1);
232 spi_message_add_tail(&xfers, &msg);
233 ret = spi_sync(st->us, &msg);
234 if (ret) { 231 if (ret) {
235 dev_err(&st->us->dev, "Problem while reading initializing data\n"); 232 dev_err(&st->us->dev, "Problem while reading initializing data\n");
236 goto error_ret; 233 goto error_ret;