.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Analog devices AD5380, AD5381, AD5382, AD5383, AD5390, AD5391, AD5392 |
---|
3 | 4 | * multi-channel Digital to Analog Converters driver |
---|
4 | 5 | * |
---|
5 | 6 | * Copyright 2011 Analog Devices Inc. |
---|
6 | | - * |
---|
7 | | - * Licensed under the GPL-2. |
---|
8 | 7 | */ |
---|
9 | 8 | |
---|
10 | 9 | #include <linux/device.h> |
---|
.. | .. |
---|
52 | 51 | * @vref_reg: vref supply regulator |
---|
53 | 52 | * @vref: actual reference voltage used in uA |
---|
54 | 53 | * @pwr_down: whether the chip is currently in power down mode |
---|
| 54 | + * @lock: lock to protect the data buffer during regmap ops |
---|
55 | 55 | */ |
---|
56 | 56 | |
---|
57 | 57 | struct ad5380_state { |
---|
.. | .. |
---|
60 | 60 | struct regulator *vref_reg; |
---|
61 | 61 | int vref; |
---|
62 | 62 | bool pwr_down; |
---|
| 63 | + struct mutex lock; |
---|
63 | 64 | }; |
---|
64 | 65 | |
---|
65 | 66 | enum ad5380_type { |
---|
.. | .. |
---|
99 | 100 | if (ret) |
---|
100 | 101 | return ret; |
---|
101 | 102 | |
---|
102 | | - mutex_lock(&indio_dev->mlock); |
---|
| 103 | + mutex_lock(&st->lock); |
---|
103 | 104 | |
---|
104 | 105 | if (pwr_down) |
---|
105 | 106 | ret = regmap_write(st->regmap, AD5380_REG_SF_PWR_DOWN, 0); |
---|
.. | .. |
---|
108 | 109 | |
---|
109 | 110 | st->pwr_down = pwr_down; |
---|
110 | 111 | |
---|
111 | | - mutex_unlock(&indio_dev->mlock); |
---|
| 112 | + mutex_unlock(&st->lock); |
---|
112 | 113 | |
---|
113 | 114 | return ret ? ret : len; |
---|
114 | 115 | } |
---|
.. | .. |
---|
239 | 240 | .write_raw = ad5380_write_raw, |
---|
240 | 241 | }; |
---|
241 | 242 | |
---|
242 | | -static struct iio_chan_spec_ext_info ad5380_ext_info[] = { |
---|
| 243 | +static const struct iio_chan_spec_ext_info ad5380_ext_info[] = { |
---|
243 | 244 | { |
---|
244 | 245 | .name = "powerdown", |
---|
245 | 246 | .read = ad5380_read_dac_powerdown, |
---|
.. | .. |
---|
385 | 386 | st->chip_info = &ad5380_chip_info_tbl[type]; |
---|
386 | 387 | st->regmap = regmap; |
---|
387 | 388 | |
---|
388 | | - indio_dev->dev.parent = dev; |
---|
389 | 389 | indio_dev->name = name; |
---|
390 | 390 | indio_dev->info = &ad5380_info; |
---|
391 | 391 | indio_dev->modes = INDIO_DIRECT_MODE; |
---|
392 | 392 | indio_dev->num_channels = st->chip_info->num_channels; |
---|
393 | 393 | |
---|
| 394 | + mutex_init(&st->lock); |
---|
| 395 | + |
---|
394 | 396 | ret = ad5380_alloc_channels(indio_dev); |
---|
395 | 397 | if (ret) { |
---|
396 | 398 | dev_err(dev, "Failed to allocate channel spec: %d\n", ret); |
---|