diff options
author | David S. Miller <davem@davemloft.net> | 2013-03-20 12:46:26 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-03-20 12:46:26 -0400 |
commit | 61816596d1c9026d0ecb20c44f90452c41596ffe (patch) | |
tree | 3027ed6dc62f71e14b9d525405747fa0eb8f074d /drivers/iio/dac/ad5064.c | |
parent | 23a9072e3af0d9538e25837fb2b56bb94e4a8e67 (diff) | |
parent | da2191e31409d1058dcbed44e8f53e39a40e86b3 (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
Pull in the 'net' tree to get Daniel Borkmann's flow dissector
infrastructure change.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/iio/dac/ad5064.c')
-rw-r--r-- | drivers/iio/dac/ad5064.c | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/drivers/iio/dac/ad5064.c b/drivers/iio/dac/ad5064.c index 2fe1d4edcb2f..74f2d52795f6 100644 --- a/drivers/iio/dac/ad5064.c +++ b/drivers/iio/dac/ad5064.c | |||
@@ -27,7 +27,6 @@ | |||
27 | #define AD5064_ADDR(x) ((x) << 20) | 27 | #define AD5064_ADDR(x) ((x) << 20) |
28 | #define AD5064_CMD(x) ((x) << 24) | 28 | #define AD5064_CMD(x) ((x) << 24) |
29 | 29 | ||
30 | #define AD5064_ADDR_DAC(chan) (chan) | ||
31 | #define AD5064_ADDR_ALL_DAC 0xF | 30 | #define AD5064_ADDR_ALL_DAC 0xF |
32 | 31 | ||
33 | #define AD5064_CMD_WRITE_INPUT_N 0x0 | 32 | #define AD5064_CMD_WRITE_INPUT_N 0x0 |
@@ -131,15 +130,15 @@ static int ad5064_write(struct ad5064_state *st, unsigned int cmd, | |||
131 | } | 130 | } |
132 | 131 | ||
133 | static int ad5064_sync_powerdown_mode(struct ad5064_state *st, | 132 | static int ad5064_sync_powerdown_mode(struct ad5064_state *st, |
134 | unsigned int channel) | 133 | const struct iio_chan_spec *chan) |
135 | { | 134 | { |
136 | unsigned int val; | 135 | unsigned int val; |
137 | int ret; | 136 | int ret; |
138 | 137 | ||
139 | val = (0x1 << channel); | 138 | val = (0x1 << chan->address); |
140 | 139 | ||
141 | if (st->pwr_down[channel]) | 140 | if (st->pwr_down[chan->channel]) |
142 | val |= st->pwr_down_mode[channel] << 8; | 141 | val |= st->pwr_down_mode[chan->channel] << 8; |
143 | 142 | ||
144 | ret = ad5064_write(st, AD5064_CMD_POWERDOWN_DAC, 0, val, 0); | 143 | ret = ad5064_write(st, AD5064_CMD_POWERDOWN_DAC, 0, val, 0); |
145 | 144 | ||
@@ -169,7 +168,7 @@ static int ad5064_set_powerdown_mode(struct iio_dev *indio_dev, | |||
169 | mutex_lock(&indio_dev->mlock); | 168 | mutex_lock(&indio_dev->mlock); |
170 | st->pwr_down_mode[chan->channel] = mode + 1; | 169 | st->pwr_down_mode[chan->channel] = mode + 1; |
171 | 170 | ||
172 | ret = ad5064_sync_powerdown_mode(st, chan->channel); | 171 | ret = ad5064_sync_powerdown_mode(st, chan); |
173 | mutex_unlock(&indio_dev->mlock); | 172 | mutex_unlock(&indio_dev->mlock); |
174 | 173 | ||
175 | return ret; | 174 | return ret; |
@@ -205,7 +204,7 @@ static ssize_t ad5064_write_dac_powerdown(struct iio_dev *indio_dev, | |||
205 | mutex_lock(&indio_dev->mlock); | 204 | mutex_lock(&indio_dev->mlock); |
206 | st->pwr_down[chan->channel] = pwr_down; | 205 | st->pwr_down[chan->channel] = pwr_down; |
207 | 206 | ||
208 | ret = ad5064_sync_powerdown_mode(st, chan->channel); | 207 | ret = ad5064_sync_powerdown_mode(st, chan); |
209 | mutex_unlock(&indio_dev->mlock); | 208 | mutex_unlock(&indio_dev->mlock); |
210 | return ret ? ret : len; | 209 | return ret ? ret : len; |
211 | } | 210 | } |
@@ -258,7 +257,7 @@ static int ad5064_write_raw(struct iio_dev *indio_dev, | |||
258 | 257 | ||
259 | switch (mask) { | 258 | switch (mask) { |
260 | case IIO_CHAN_INFO_RAW: | 259 | case IIO_CHAN_INFO_RAW: |
261 | if (val > (1 << chan->scan_type.realbits) || val < 0) | 260 | if (val >= (1 << chan->scan_type.realbits) || val < 0) |
262 | return -EINVAL; | 261 | return -EINVAL; |
263 | 262 | ||
264 | mutex_lock(&indio_dev->mlock); | 263 | mutex_lock(&indio_dev->mlock); |
@@ -292,34 +291,44 @@ static const struct iio_chan_spec_ext_info ad5064_ext_info[] = { | |||
292 | { }, | 291 | { }, |
293 | }; | 292 | }; |
294 | 293 | ||
295 | #define AD5064_CHANNEL(chan, bits) { \ | 294 | #define AD5064_CHANNEL(chan, addr, bits) { \ |
296 | .type = IIO_VOLTAGE, \ | 295 | .type = IIO_VOLTAGE, \ |
297 | .indexed = 1, \ | 296 | .indexed = 1, \ |
298 | .output = 1, \ | 297 | .output = 1, \ |
299 | .channel = (chan), \ | 298 | .channel = (chan), \ |
300 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ | 299 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ |
301 | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ | 300 | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ |
302 | .address = AD5064_ADDR_DAC(chan), \ | 301 | .address = addr, \ |
303 | .scan_type = IIO_ST('u', (bits), 16, 20 - (bits)), \ | 302 | .scan_type = IIO_ST('u', (bits), 16, 20 - (bits)), \ |
304 | .ext_info = ad5064_ext_info, \ | 303 | .ext_info = ad5064_ext_info, \ |
305 | } | 304 | } |
306 | 305 | ||
307 | #define DECLARE_AD5064_CHANNELS(name, bits) \ | 306 | #define DECLARE_AD5064_CHANNELS(name, bits) \ |
308 | const struct iio_chan_spec name[] = { \ | 307 | const struct iio_chan_spec name[] = { \ |
309 | AD5064_CHANNEL(0, bits), \ | 308 | AD5064_CHANNEL(0, 0, bits), \ |
310 | AD5064_CHANNEL(1, bits), \ | 309 | AD5064_CHANNEL(1, 1, bits), \ |
311 | AD5064_CHANNEL(2, bits), \ | 310 | AD5064_CHANNEL(2, 2, bits), \ |
312 | AD5064_CHANNEL(3, bits), \ | 311 | AD5064_CHANNEL(3, 3, bits), \ |
313 | AD5064_CHANNEL(4, bits), \ | 312 | AD5064_CHANNEL(4, 4, bits), \ |
314 | AD5064_CHANNEL(5, bits), \ | 313 | AD5064_CHANNEL(5, 5, bits), \ |
315 | AD5064_CHANNEL(6, bits), \ | 314 | AD5064_CHANNEL(6, 6, bits), \ |
316 | AD5064_CHANNEL(7, bits), \ | 315 | AD5064_CHANNEL(7, 7, bits), \ |
316 | } | ||
317 | |||
318 | #define DECLARE_AD5065_CHANNELS(name, bits) \ | ||
319 | const struct iio_chan_spec name[] = { \ | ||
320 | AD5064_CHANNEL(0, 0, bits), \ | ||
321 | AD5064_CHANNEL(1, 3, bits), \ | ||
317 | } | 322 | } |
318 | 323 | ||
319 | static DECLARE_AD5064_CHANNELS(ad5024_channels, 12); | 324 | static DECLARE_AD5064_CHANNELS(ad5024_channels, 12); |
320 | static DECLARE_AD5064_CHANNELS(ad5044_channels, 14); | 325 | static DECLARE_AD5064_CHANNELS(ad5044_channels, 14); |
321 | static DECLARE_AD5064_CHANNELS(ad5064_channels, 16); | 326 | static DECLARE_AD5064_CHANNELS(ad5064_channels, 16); |
322 | 327 | ||
328 | static DECLARE_AD5065_CHANNELS(ad5025_channels, 12); | ||
329 | static DECLARE_AD5065_CHANNELS(ad5045_channels, 14); | ||
330 | static DECLARE_AD5065_CHANNELS(ad5065_channels, 16); | ||
331 | |||
323 | static const struct ad5064_chip_info ad5064_chip_info_tbl[] = { | 332 | static const struct ad5064_chip_info ad5064_chip_info_tbl[] = { |
324 | [ID_AD5024] = { | 333 | [ID_AD5024] = { |
325 | .shared_vref = false, | 334 | .shared_vref = false, |
@@ -328,7 +337,7 @@ static const struct ad5064_chip_info ad5064_chip_info_tbl[] = { | |||
328 | }, | 337 | }, |
329 | [ID_AD5025] = { | 338 | [ID_AD5025] = { |
330 | .shared_vref = false, | 339 | .shared_vref = false, |
331 | .channels = ad5024_channels, | 340 | .channels = ad5025_channels, |
332 | .num_channels = 2, | 341 | .num_channels = 2, |
333 | }, | 342 | }, |
334 | [ID_AD5044] = { | 343 | [ID_AD5044] = { |
@@ -338,7 +347,7 @@ static const struct ad5064_chip_info ad5064_chip_info_tbl[] = { | |||
338 | }, | 347 | }, |
339 | [ID_AD5045] = { | 348 | [ID_AD5045] = { |
340 | .shared_vref = false, | 349 | .shared_vref = false, |
341 | .channels = ad5044_channels, | 350 | .channels = ad5045_channels, |
342 | .num_channels = 2, | 351 | .num_channels = 2, |
343 | }, | 352 | }, |
344 | [ID_AD5064] = { | 353 | [ID_AD5064] = { |
@@ -353,7 +362,7 @@ static const struct ad5064_chip_info ad5064_chip_info_tbl[] = { | |||
353 | }, | 362 | }, |
354 | [ID_AD5065] = { | 363 | [ID_AD5065] = { |
355 | .shared_vref = false, | 364 | .shared_vref = false, |
356 | .channels = ad5064_channels, | 365 | .channels = ad5065_channels, |
357 | .num_channels = 2, | 366 | .num_channels = 2, |
358 | }, | 367 | }, |
359 | [ID_AD5628_1] = { | 368 | [ID_AD5628_1] = { |
@@ -429,6 +438,7 @@ static int ad5064_probe(struct device *dev, enum ad5064_type type, | |||
429 | { | 438 | { |
430 | struct iio_dev *indio_dev; | 439 | struct iio_dev *indio_dev; |
431 | struct ad5064_state *st; | 440 | struct ad5064_state *st; |
441 | unsigned int midscale; | ||
432 | unsigned int i; | 442 | unsigned int i; |
433 | int ret; | 443 | int ret; |
434 | 444 | ||
@@ -465,11 +475,6 @@ static int ad5064_probe(struct device *dev, enum ad5064_type type, | |||
465 | goto error_free_reg; | 475 | goto error_free_reg; |
466 | } | 476 | } |
467 | 477 | ||
468 | for (i = 0; i < st->chip_info->num_channels; ++i) { | ||
469 | st->pwr_down_mode[i] = AD5064_LDAC_PWRDN_1K; | ||
470 | st->dac_cache[i] = 0x8000; | ||
471 | } | ||
472 | |||
473 | indio_dev->dev.parent = dev; | 478 | indio_dev->dev.parent = dev; |
474 | indio_dev->name = name; | 479 | indio_dev->name = name; |
475 | indio_dev->info = &ad5064_info; | 480 | indio_dev->info = &ad5064_info; |
@@ -477,6 +482,13 @@ static int ad5064_probe(struct device *dev, enum ad5064_type type, | |||
477 | indio_dev->channels = st->chip_info->channels; | 482 | indio_dev->channels = st->chip_info->channels; |
478 | indio_dev->num_channels = st->chip_info->num_channels; | 483 | indio_dev->num_channels = st->chip_info->num_channels; |
479 | 484 | ||
485 | midscale = (1 << indio_dev->channels[0].scan_type.realbits) / 2; | ||
486 | |||
487 | for (i = 0; i < st->chip_info->num_channels; ++i) { | ||
488 | st->pwr_down_mode[i] = AD5064_LDAC_PWRDN_1K; | ||
489 | st->dac_cache[i] = midscale; | ||
490 | } | ||
491 | |||
480 | ret = iio_device_register(indio_dev); | 492 | ret = iio_device_register(indio_dev); |
481 | if (ret) | 493 | if (ret) |
482 | goto error_disable_reg; | 494 | goto error_disable_reg; |