11 #include <linux/device.h>
12 #include <linux/module.h>
13 #include <linux/kernel.h>
15 #include <linux/slab.h>
22 #define AD5686_DAC_CHANNELS 4
24 #define AD5686_ADDR(x) ((x) << 16)
25 #define AD5686_CMD(x) ((x) << 20)
27 #define AD5686_ADDR_DAC(chan) (0x1 << (chan))
28 #define AD5686_ADDR_ALL_DAC 0xF
30 #define AD5686_CMD_NOOP 0x0
31 #define AD5686_CMD_WRITE_INPUT_N 0x1
32 #define AD5686_CMD_UPDATE_DAC_N 0x2
33 #define AD5686_CMD_WRITE_INPUT_N_UPDATE_N 0x3
34 #define AD5686_CMD_POWERDOWN_DAC 0x4
35 #define AD5686_CMD_LDAC_MASK 0x5
36 #define AD5686_CMD_RESET 0x6
37 #define AD5686_CMD_INTERNAL_REFER_SETUP 0x7
38 #define AD5686_CMD_DAISY_CHAIN_ENABLE 0x8
39 #define AD5686_CMD_READBACK_ENABLE 0x9
41 #define AD5686_LDAC_PWRDN_NONE 0x0
42 #define AD5686_LDAC_PWRDN_1K 0x1
43 #define AD5686_LDAC_PWRDN_100K 0x2
44 #define AD5686_LDAC_PWRDN_3STATE 0x3
104 return spi_write(st->
spi, &st->data[0].
d8[1], 3);
111 .tx_buf = &st->data[0].
d8[1],
115 .tx_buf = &st->data[1].
d8[1],
116 .rx_buf = &st->data[2].
d8[1],
123 spi_message_init(&
m);
124 spi_message_add_tail(&t[0], &
m);
125 spi_message_add_tail(&t[1], &
m);
138 static const char *
const ad5686_powerdown_modes[] = {
144 static int ad5686_get_powerdown_mode(
struct iio_dev *indio_dev,
152 static int ad5686_set_powerdown_mode(
struct iio_dev *indio_dev,
163 static const struct iio_enum ad5686_powerdown_mode_enum = {
164 .items = ad5686_powerdown_modes,
165 .num_items =
ARRAY_SIZE(ad5686_powerdown_modes),
166 .get = ad5686_get_powerdown_mode,
167 .set = ad5686_set_powerdown_mode,
170 static ssize_t ad5686_read_dac_powerdown(
struct iio_dev *indio_dev,
176 (0x3 << (chan->
channel * 2))));
179 static ssize_t ad5686_write_dac_powerdown(
struct iio_dev *indio_dev,
199 return ret ? ret : len;
202 static int ad5686_read_raw(
struct iio_dev *indio_dev,
209 unsigned long scale_uv;
215 ret = ad5686_spi_read(st, chan->
address);
223 scale_uv = (st->
vref_mv * 100000)
225 *val = scale_uv / 100000;
226 *val2 = (scale_uv % 100000) * 10;
233 static int ad5686_write_raw(
struct iio_dev *indio_dev,
244 if (val > (1 << chan->
scan_type.realbits) || val < 0)
248 ret = ad5686_spi_write(st,
262 static const struct iio_info ad5686_info = {
263 .read_raw = ad5686_read_raw,
264 .write_raw = ad5686_write_raw,
271 .read = ad5686_read_dac_powerdown,
272 .write = ad5686_write_dac_powerdown,
274 IIO_ENUM(
"powerdown_mode",
false, &ad5686_powerdown_mode_enum),
279 #define AD5868_CHANNEL(chan, bits, shift) { \
280 .type = IIO_VOLTAGE, \
284 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
285 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
286 .address = AD5686_ADDR_DAC(chan), \
287 .scan_type = IIO_ST('u', bits, 16, shift), \
288 .ext_info = ad5686_ext_info, \
320 int ret, regdone = 0, voltage_uv = 0;
323 if (indio_dev ==
NULL)
326 st = iio_priv(indio_dev);
327 spi_set_drvdata(spi, indio_dev);
330 if (!IS_ERR(st->
reg)) {
342 st->
vref_mv = voltage_uv / 1000;
351 indio_dev->
dev.parent = &spi->
dev;
353 indio_dev->
info = &ad5686_info;
362 goto error_disable_reg;
366 goto error_disable_reg;
371 if (!IS_ERR(st->
reg))
374 if (!IS_ERR(st->
reg))
384 struct iio_dev *indio_dev = spi_get_drvdata(spi);
388 if (!IS_ERR(st->
reg)) {
410 .probe = ad5686_probe,
412 .id_table = ad5686_id,