11 #include <linux/device.h>
12 #include <linux/kernel.h>
14 #include <linux/slab.h>
17 #include <linux/module.h>
38 data = (0 << 22) | (cmd << 19) | (addr << 16) | (val << (16 - len));
43 return spi_write(spi, msg, 3);
46 static int ad5624r_read_raw(
struct iio_dev *indio_dev,
53 unsigned long scale_uv;
58 *val = scale_uv / 1000;
59 *val2 = (scale_uv % 1000) * 1000;
66 static int ad5624r_write_raw(
struct iio_dev *indio_dev,
77 if (val >= (1 << chan->
scan_type.realbits) || val < 0)
80 return ad5624r_spi_write(st->
us,
91 static const char *
const ad5624r_powerdown_modes[] = {
97 static int ad5624r_get_powerdown_mode(
struct iio_dev *indio_dev,
105 static int ad5624r_set_powerdown_mode(
struct iio_dev *indio_dev,
115 static const struct iio_enum ad5624r_powerdown_mode_enum = {
116 .items = ad5624r_powerdown_modes,
117 .num_items =
ARRAY_SIZE(ad5624r_powerdown_modes),
118 .get = ad5624r_get_powerdown_mode,
119 .set = ad5624r_set_powerdown_mode,
122 static ssize_t ad5624r_read_dac_powerdown(
struct iio_dev *indio_dev,
131 static ssize_t ad5624r_write_dac_powerdown(
struct iio_dev *indio_dev,
152 return ret ? ret : len;
155 static const struct iio_info ad5624r_info = {
156 .write_raw = ad5624r_write_raw,
157 .read_raw = ad5624r_read_raw,
164 .read = ad5624r_read_dac_powerdown,
165 .write = ad5624r_write_dac_powerdown,
167 IIO_ENUM(
"powerdown_mode",
true, &ad5624r_powerdown_mode_enum),
172 #define AD5624R_CHANNEL(_chan, _bits) { \
173 .type = IIO_VOLTAGE, \
176 .channel = (_chan), \
177 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
178 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
179 .address = (_chan), \
180 .scan_type = IIO_ST('u', (_bits), 16, 16 - (_bits)), \
181 .ext_info = ad5624r_ext_info, \
184 #define DECLARE_AD5624R_CHANNELS(_name, _bits) \
185 const struct iio_chan_spec _name##_channels[] = { \
186 AD5624R_CHANNEL(0, _bits), \
187 AD5624R_CHANNEL(1, _bits), \
188 AD5624R_CHANNEL(2, _bits), \
189 AD5624R_CHANNEL(3, _bits), \
198 .channels = ad5624r_channels,
202 .channels = ad5624r_channels,
206 .channels = ad5644r_channels,
210 .channels = ad5644r_channels,
214 .channels = ad5664r_channels,
218 .channels = ad5664r_channels,
227 int ret, voltage_uv = 0;
230 if (indio_dev ==
NULL) {
234 st = iio_priv(indio_dev);
236 if (!IS_ERR(st->
reg)) {
244 spi_set_drvdata(spi, indio_dev);
249 st->
vref_mv = voltage_uv / 1000;
255 indio_dev->
dev.parent = &spi->
dev;
257 indio_dev->
info = &ad5624r_info;
265 goto error_disable_reg;
269 goto error_disable_reg;
274 if (!IS_ERR(st->
reg))
277 if (!IS_ERR(st->
reg))
287 struct iio_dev *indio_dev = spi_get_drvdata(spi);
291 if (!IS_ERR(st->
reg)) {
316 .probe = ad5624r_probe,
318 .id_table = ad5624r_id,