2 * AD5755, AD5755-1, AD5757, AD5735, AD5737 Digital to analog converters driver
4 * Copyright 2012 Analog Devices Inc.
6 * Licensed under the GPL-2.
9 #include <linux/device.h>
10 #include <linux/err.h>
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/spi/spi.h>
14 #include <linux/slab.h>
15 #include <linux/sysfs.h>
16 #include <linux/delay.h>
18 #include <linux/iio/iio.h>
19 #include <linux/iio/sysfs.h>
20 #include <linux/platform_data/ad5755.h>
22 #define AD5755_NUM_CHANNELS 4
24 #define AD5755_ADDR(x) ((x) << 16)
26 #define AD5755_WRITE_REG_DATA(chan) (chan)
27 #define AD5755_WRITE_REG_GAIN(chan) (0x08 | (chan))
28 #define AD5755_WRITE_REG_OFFSET(chan) (0x10 | (chan))
29 #define AD5755_WRITE_REG_CTRL(chan) (0x1c | (chan))
31 #define AD5755_READ_REG_DATA(chan) (chan)
32 #define AD5755_READ_REG_CTRL(chan) (0x4 | (chan))
33 #define AD5755_READ_REG_GAIN(chan) (0x8 | (chan))
34 #define AD5755_READ_REG_OFFSET(chan) (0xc | (chan))
35 #define AD5755_READ_REG_CLEAR(chan) (0x10 | (chan))
36 #define AD5755_READ_REG_SLEW(chan) (0x14 | (chan))
37 #define AD5755_READ_REG_STATUS 0x18
38 #define AD5755_READ_REG_MAIN 0x19
39 #define AD5755_READ_REG_DC_DC 0x1a
41 #define AD5755_CTRL_REG_SLEW 0x0
42 #define AD5755_CTRL_REG_MAIN 0x1
43 #define AD5755_CTRL_REG_DAC 0x2
44 #define AD5755_CTRL_REG_DC_DC 0x3
45 #define AD5755_CTRL_REG_SW 0x4
47 #define AD5755_READ_FLAG 0x800000
49 #define AD5755_NOOP 0x1CE000
51 #define AD5755_DAC_INT_EN BIT(8)
52 #define AD5755_DAC_CLR_EN BIT(7)
53 #define AD5755_DAC_OUT_EN BIT(6)
54 #define AD5755_DAC_INT_CURRENT_SENSE_RESISTOR BIT(5)
55 #define AD5755_DAC_DC_DC_EN BIT(4)
56 #define AD5755_DAC_VOLTAGE_OVERRANGE_EN BIT(3)
58 #define AD5755_DC_DC_MAXV 0
59 #define AD5755_DC_DC_FREQ_SHIFT 2
60 #define AD5755_DC_DC_PHASE_SHIFT 4
61 #define AD5755_EXT_DC_DC_COMP_RES BIT(6)
63 #define AD5755_SLEW_STEP_SIZE_SHIFT 0
64 #define AD5755_SLEW_RATE_SHIFT 3
65 #define AD5755_SLEW_ENABLE BIT(12)
68 * struct ad5755_chip_info - chip specific information
69 * @channel_template: channel specification
70 * @calib_shift: shift for the calibration data registers
71 * @has_voltage_out: whether the chip has voltage outputs
73 struct ad5755_chip_info {
74 const struct iio_chan_spec channel_template;
75 unsigned int calib_shift;
80 * struct ad5755_state - driver instance specific data
81 * @spi: spi device the driver is attached to
82 * @chip_info: chip model specific constants, available modes etc
83 * @pwr_down: bitmask which contains hether a channel is powered down or not
84 * @ctrl: software shadow of the channel ctrl registers
85 * @channels: iio channel spec for the device
86 * @data: spi transfer buffers
89 struct spi_device *spi;
90 const struct ad5755_chip_info *chip_info;
91 unsigned int pwr_down;
92 unsigned int ctrl[AD5755_NUM_CHANNELS];
93 struct iio_chan_spec channels[AD5755_NUM_CHANNELS];
96 * DMA (thus cache coherency maintenance) requires the
97 * transfer buffers to live in their own cache lines.
103 } data[2] ____cacheline_aligned;
114 static const int ad5755_dcdc_freq_table[][2] = {
115 { 250000, AD5755_DC_DC_FREQ_250kHZ },
116 { 410000, AD5755_DC_DC_FREQ_410kHZ },
117 { 650000, AD5755_DC_DC_FREQ_650kHZ }
120 static const int ad5755_dcdc_maxv_table[][2] = {
121 { 23000000, AD5755_DC_DC_MAXV_23V },
122 { 24500000, AD5755_DC_DC_MAXV_24V5 },
123 { 27000000, AD5755_DC_DC_MAXV_27V },
124 { 29500000, AD5755_DC_DC_MAXV_29V5 },
127 static const int ad5755_slew_rate_table[][2] = {
128 { 64000, AD5755_SLEW_RATE_64k },
129 { 32000, AD5755_SLEW_RATE_32k },
130 { 16000, AD5755_SLEW_RATE_16k },
131 { 8000, AD5755_SLEW_RATE_8k },
132 { 4000, AD5755_SLEW_RATE_4k },
133 { 2000, AD5755_SLEW_RATE_2k },
134 { 1000, AD5755_SLEW_RATE_1k },
135 { 500, AD5755_SLEW_RATE_500 },
136 { 250, AD5755_SLEW_RATE_250 },
137 { 125, AD5755_SLEW_RATE_125 },
138 { 64, AD5755_SLEW_RATE_64 },
139 { 32, AD5755_SLEW_RATE_32 },
140 { 16, AD5755_SLEW_RATE_16 },
141 { 8, AD5755_SLEW_RATE_8 },
142 { 4, AD5755_SLEW_RATE_4 },
143 { 0, AD5755_SLEW_RATE_0_5 },
146 static const int ad5755_slew_step_table[][2] = {
147 { 256, AD5755_SLEW_STEP_SIZE_256 },
148 { 128, AD5755_SLEW_STEP_SIZE_128 },
149 { 64, AD5755_SLEW_STEP_SIZE_64 },
150 { 32, AD5755_SLEW_STEP_SIZE_32 },
151 { 16, AD5755_SLEW_STEP_SIZE_16 },
152 { 4, AD5755_SLEW_STEP_SIZE_4 },
153 { 2, AD5755_SLEW_STEP_SIZE_2 },
154 { 1, AD5755_SLEW_STEP_SIZE_1 },
158 static int ad5755_write_unlocked(struct iio_dev *indio_dev,
159 unsigned int reg, unsigned int val)
161 struct ad5755_state *st = iio_priv(indio_dev);
163 st->data[0].d32 = cpu_to_be32((reg << 16) | val);
165 return spi_write(st->spi, &st->data[0].d8[1], 3);
168 static int ad5755_write_ctrl_unlocked(struct iio_dev *indio_dev,
169 unsigned int channel, unsigned int reg, unsigned int val)
171 return ad5755_write_unlocked(indio_dev,
172 AD5755_WRITE_REG_CTRL(channel), (reg << 13) | val);
175 static int ad5755_write(struct iio_dev *indio_dev, unsigned int reg,
180 mutex_lock(&indio_dev->mlock);
181 ret = ad5755_write_unlocked(indio_dev, reg, val);
182 mutex_unlock(&indio_dev->mlock);
187 static int ad5755_write_ctrl(struct iio_dev *indio_dev, unsigned int channel,
188 unsigned int reg, unsigned int val)
192 mutex_lock(&indio_dev->mlock);
193 ret = ad5755_write_ctrl_unlocked(indio_dev, channel, reg, val);
194 mutex_unlock(&indio_dev->mlock);
199 static int ad5755_read(struct iio_dev *indio_dev, unsigned int addr)
201 struct ad5755_state *st = iio_priv(indio_dev);
203 struct spi_transfer t[] = {
205 .tx_buf = &st->data[0].d8[1],
209 .tx_buf = &st->data[1].d8[1],
210 .rx_buf = &st->data[1].d8[1],
215 mutex_lock(&indio_dev->mlock);
217 st->data[0].d32 = cpu_to_be32(AD5755_READ_FLAG | (addr << 16));
218 st->data[1].d32 = cpu_to_be32(AD5755_NOOP);
220 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
222 ret = be32_to_cpu(st->data[1].d32) & 0xffff;
224 mutex_unlock(&indio_dev->mlock);
229 static int ad5755_update_dac_ctrl(struct iio_dev *indio_dev,
230 unsigned int channel, unsigned int set, unsigned int clr)
232 struct ad5755_state *st = iio_priv(indio_dev);
235 st->ctrl[channel] |= set;
236 st->ctrl[channel] &= ~clr;
238 ret = ad5755_write_ctrl_unlocked(indio_dev, channel,
239 AD5755_CTRL_REG_DAC, st->ctrl[channel]);
244 static int ad5755_set_channel_pwr_down(struct iio_dev *indio_dev,
245 unsigned int channel, bool pwr_down)
247 struct ad5755_state *st = iio_priv(indio_dev);
248 unsigned int mask = BIT(channel);
250 mutex_lock(&indio_dev->mlock);
252 if ((bool)(st->pwr_down & mask) == pwr_down)
256 st->pwr_down &= ~mask;
257 ad5755_update_dac_ctrl(indio_dev, channel,
258 AD5755_DAC_INT_EN | AD5755_DAC_DC_DC_EN, 0);
260 ad5755_update_dac_ctrl(indio_dev, channel,
261 AD5755_DAC_OUT_EN, 0);
263 st->pwr_down |= mask;
264 ad5755_update_dac_ctrl(indio_dev, channel,
265 0, AD5755_DAC_INT_EN | AD5755_DAC_OUT_EN |
266 AD5755_DAC_DC_DC_EN);
270 mutex_unlock(&indio_dev->mlock);
275 static const int ad5755_min_max_table[][2] = {
276 [AD5755_MODE_VOLTAGE_0V_5V] = { 0, 5000 },
277 [AD5755_MODE_VOLTAGE_0V_10V] = { 0, 10000 },
278 [AD5755_MODE_VOLTAGE_PLUSMINUS_5V] = { -5000, 5000 },
279 [AD5755_MODE_VOLTAGE_PLUSMINUS_10V] = { -10000, 10000 },
280 [AD5755_MODE_CURRENT_4mA_20mA] = { 4, 20 },
281 [AD5755_MODE_CURRENT_0mA_20mA] = { 0, 20 },
282 [AD5755_MODE_CURRENT_0mA_24mA] = { 0, 24 },
285 static void ad5755_get_min_max(struct ad5755_state *st,
286 struct iio_chan_spec const *chan, int *min, int *max)
288 enum ad5755_mode mode = st->ctrl[chan->channel] & 7;
289 *min = ad5755_min_max_table[mode][0];
290 *max = ad5755_min_max_table[mode][1];
293 static inline int ad5755_get_offset(struct ad5755_state *st,
294 struct iio_chan_spec const *chan)
298 ad5755_get_min_max(st, chan, &min, &max);
299 return (min * (1 << chan->scan_type.realbits)) / (max - min);
302 static int ad5755_chan_reg_info(struct ad5755_state *st,
303 struct iio_chan_spec const *chan, long info, bool write,
304 unsigned int *reg, unsigned int *shift, unsigned int *offset)
307 case IIO_CHAN_INFO_RAW:
309 *reg = AD5755_WRITE_REG_DATA(chan->address);
311 *reg = AD5755_READ_REG_DATA(chan->address);
312 *shift = chan->scan_type.shift;
315 case IIO_CHAN_INFO_CALIBBIAS:
317 *reg = AD5755_WRITE_REG_OFFSET(chan->address);
319 *reg = AD5755_READ_REG_OFFSET(chan->address);
320 *shift = st->chip_info->calib_shift;
323 case IIO_CHAN_INFO_CALIBSCALE:
325 *reg = AD5755_WRITE_REG_GAIN(chan->address);
327 *reg = AD5755_READ_REG_GAIN(chan->address);
328 *shift = st->chip_info->calib_shift;
338 static int ad5755_read_raw(struct iio_dev *indio_dev,
339 const struct iio_chan_spec *chan, int *val, int *val2, long info)
341 struct ad5755_state *st = iio_priv(indio_dev);
342 unsigned int reg, shift, offset;
347 case IIO_CHAN_INFO_SCALE:
348 ad5755_get_min_max(st, chan, &min, &max);
350 *val2 = chan->scan_type.realbits;
351 return IIO_VAL_FRACTIONAL_LOG2;
352 case IIO_CHAN_INFO_OFFSET:
353 *val = ad5755_get_offset(st, chan);
356 ret = ad5755_chan_reg_info(st, chan, info, false,
357 ®, &shift, &offset);
361 ret = ad5755_read(indio_dev, reg);
365 *val = (ret - offset) >> shift;
373 static int ad5755_write_raw(struct iio_dev *indio_dev,
374 const struct iio_chan_spec *chan, int val, int val2, long info)
376 struct ad5755_state *st = iio_priv(indio_dev);
377 unsigned int shift, reg, offset;
380 ret = ad5755_chan_reg_info(st, chan, info, true,
381 ®, &shift, &offset);
388 if (val < 0 || val > 0xffff)
391 return ad5755_write(indio_dev, reg, val);
394 static ssize_t ad5755_read_powerdown(struct iio_dev *indio_dev, uintptr_t priv,
395 const struct iio_chan_spec *chan, char *buf)
397 struct ad5755_state *st = iio_priv(indio_dev);
399 return sprintf(buf, "%d\n",
400 (bool)(st->pwr_down & (1 << chan->channel)));
403 static ssize_t ad5755_write_powerdown(struct iio_dev *indio_dev, uintptr_t priv,
404 struct iio_chan_spec const *chan, const char *buf, size_t len)
409 ret = strtobool(buf, &pwr_down);
413 ret = ad5755_set_channel_pwr_down(indio_dev, chan->channel, pwr_down);
414 return ret ? ret : len;
417 static const struct iio_info ad5755_info = {
418 .read_raw = ad5755_read_raw,
419 .write_raw = ad5755_write_raw,
422 static const struct iio_chan_spec_ext_info ad5755_ext_info[] = {
425 .read = ad5755_read_powerdown,
426 .write = ad5755_write_powerdown,
427 .shared = IIO_SEPARATE,
432 #define AD5755_CHANNEL(_bits) { \
435 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
436 BIT(IIO_CHAN_INFO_SCALE) | \
437 BIT(IIO_CHAN_INFO_OFFSET) | \
438 BIT(IIO_CHAN_INFO_CALIBSCALE) | \
439 BIT(IIO_CHAN_INFO_CALIBBIAS), \
442 .realbits = (_bits), \
444 .shift = 16 - (_bits), \
446 .ext_info = ad5755_ext_info, \
449 static const struct ad5755_chip_info ad5755_chip_info_tbl[] = {
451 .channel_template = AD5755_CHANNEL(14),
452 .has_voltage_out = true,
456 .channel_template = AD5755_CHANNEL(14),
457 .has_voltage_out = false,
461 .channel_template = AD5755_CHANNEL(16),
462 .has_voltage_out = true,
466 .channel_template = AD5755_CHANNEL(16),
467 .has_voltage_out = false,
472 static bool ad5755_is_valid_mode(struct ad5755_state *st, enum ad5755_mode mode)
475 case AD5755_MODE_VOLTAGE_0V_5V:
476 case AD5755_MODE_VOLTAGE_0V_10V:
477 case AD5755_MODE_VOLTAGE_PLUSMINUS_5V:
478 case AD5755_MODE_VOLTAGE_PLUSMINUS_10V:
479 return st->chip_info->has_voltage_out;
480 case AD5755_MODE_CURRENT_4mA_20mA:
481 case AD5755_MODE_CURRENT_0mA_20mA:
482 case AD5755_MODE_CURRENT_0mA_24mA:
489 static int ad5755_setup_pdata(struct iio_dev *indio_dev,
490 const struct ad5755_platform_data *pdata)
492 struct ad5755_state *st = iio_priv(indio_dev);
497 if (pdata->dc_dc_phase > AD5755_DC_DC_PHASE_90_DEGREE ||
498 pdata->dc_dc_freq > AD5755_DC_DC_FREQ_650kHZ ||
499 pdata->dc_dc_maxv > AD5755_DC_DC_MAXV_29V5)
502 val = pdata->dc_dc_maxv << AD5755_DC_DC_MAXV;
503 val |= pdata->dc_dc_freq << AD5755_DC_DC_FREQ_SHIFT;
504 val |= pdata->dc_dc_phase << AD5755_DC_DC_PHASE_SHIFT;
505 if (pdata->ext_dc_dc_compenstation_resistor)
506 val |= AD5755_EXT_DC_DC_COMP_RES;
508 ret = ad5755_write_ctrl(indio_dev, 0, AD5755_CTRL_REG_DC_DC, val);
512 for (i = 0; i < ARRAY_SIZE(pdata->dac); ++i) {
513 val = pdata->dac[i].slew.step_size <<
514 AD5755_SLEW_STEP_SIZE_SHIFT;
515 val |= pdata->dac[i].slew.rate <<
516 AD5755_SLEW_RATE_SHIFT;
517 if (pdata->dac[i].slew.enable)
518 val |= AD5755_SLEW_ENABLE;
520 ret = ad5755_write_ctrl(indio_dev, i,
521 AD5755_CTRL_REG_SLEW, val);
526 for (i = 0; i < ARRAY_SIZE(pdata->dac); ++i) {
527 if (!ad5755_is_valid_mode(st, pdata->dac[i].mode))
531 if (!pdata->dac[i].ext_current_sense_resistor)
532 val |= AD5755_DAC_INT_CURRENT_SENSE_RESISTOR;
533 if (pdata->dac[i].enable_voltage_overrange)
534 val |= AD5755_DAC_VOLTAGE_OVERRANGE_EN;
535 val |= pdata->dac[i].mode;
537 ret = ad5755_update_dac_ctrl(indio_dev, i, val, 0);
545 static bool ad5755_is_voltage_mode(enum ad5755_mode mode)
548 case AD5755_MODE_VOLTAGE_0V_5V:
549 case AD5755_MODE_VOLTAGE_0V_10V:
550 case AD5755_MODE_VOLTAGE_PLUSMINUS_5V:
551 case AD5755_MODE_VOLTAGE_PLUSMINUS_10V:
558 static int ad5755_init_channels(struct iio_dev *indio_dev,
559 const struct ad5755_platform_data *pdata)
561 struct ad5755_state *st = iio_priv(indio_dev);
562 struct iio_chan_spec *channels = st->channels;
565 for (i = 0; i < AD5755_NUM_CHANNELS; ++i) {
566 channels[i] = st->chip_info->channel_template;
567 channels[i].channel = i;
568 channels[i].address = i;
569 if (pdata && ad5755_is_voltage_mode(pdata->dac[i].mode))
570 channels[i].type = IIO_VOLTAGE;
572 channels[i].type = IIO_CURRENT;
575 indio_dev->channels = channels;
580 #define AD5755_DEFAULT_DAC_PDATA { \
581 .mode = AD5755_MODE_CURRENT_4mA_20mA, \
582 .ext_current_sense_resistor = true, \
583 .enable_voltage_overrange = false, \
586 .rate = AD5755_SLEW_RATE_64k, \
587 .step_size = AD5755_SLEW_STEP_SIZE_1, \
591 static const struct ad5755_platform_data ad5755_default_pdata = {
592 .ext_dc_dc_compenstation_resistor = false,
593 .dc_dc_phase = AD5755_DC_DC_PHASE_ALL_SAME_EDGE,
594 .dc_dc_freq = AD5755_DC_DC_FREQ_410kHZ,
595 .dc_dc_maxv = AD5755_DC_DC_MAXV_23V,
597 [0] = AD5755_DEFAULT_DAC_PDATA,
598 [1] = AD5755_DEFAULT_DAC_PDATA,
599 [2] = AD5755_DEFAULT_DAC_PDATA,
600 [3] = AD5755_DEFAULT_DAC_PDATA,
605 static struct ad5755_platform_data *ad5755_parse_dt(struct device *dev)
607 struct device_node *np = dev->of_node;
608 struct device_node *pp;
609 struct ad5755_platform_data *pdata;
611 unsigned int tmparray[3];
614 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
618 pdata->ext_dc_dc_compenstation_resistor =
619 of_property_read_bool(np, "adi,ext-dc-dc-compenstation-resistor");
621 if (!of_property_read_u32(np, "adi,dc-dc-phase", &tmp))
622 pdata->dc_dc_phase = tmp;
624 pdata->dc_dc_phase = AD5755_DC_DC_PHASE_ALL_SAME_EDGE;
626 pdata->dc_dc_freq = AD5755_DC_DC_FREQ_410kHZ;
627 if (!of_property_read_u32(np, "adi,dc-dc-freq-hz", &tmp)) {
628 for (i = 0; i < ARRAY_SIZE(ad5755_dcdc_freq_table); i++) {
629 if (tmp == ad5755_dcdc_freq_table[i][0]) {
630 pdata->dc_dc_freq = ad5755_dcdc_freq_table[i][1];
635 if (i == ARRAY_SIZE(ad5755_dcdc_freq_table)) {
637 "adi,dc-dc-freq out of range selecting 410kHz");
641 pdata->dc_dc_maxv = AD5755_DC_DC_MAXV_23V;
642 if (!of_property_read_u32(np, "adi,dc-dc-max-microvolt", &tmp)) {
643 for (i = 0; i < ARRAY_SIZE(ad5755_dcdc_maxv_table); i++) {
644 if (tmp == ad5755_dcdc_maxv_table[i][0]) {
645 pdata->dc_dc_maxv = ad5755_dcdc_maxv_table[i][1];
649 if (i == ARRAY_SIZE(ad5755_dcdc_maxv_table)) {
651 "adi,dc-dc-maxv out of range selecting 23V");
656 for_each_child_of_node(np, pp) {
657 if (devnr >= AD5755_NUM_CHANNELS) {
659 "There is to many channels defined in DT\n");
663 if (!of_property_read_u32(pp, "adi,mode", &tmp))
664 pdata->dac[devnr].mode = tmp;
666 pdata->dac[devnr].mode = AD5755_MODE_CURRENT_4mA_20mA;
668 pdata->dac[devnr].ext_current_sense_resistor =
669 of_property_read_bool(pp, "adi,ext-current-sense-resistor");
671 pdata->dac[devnr].enable_voltage_overrange =
672 of_property_read_bool(pp, "adi,enable-voltage-overrange");
674 if (!of_property_read_u32_array(pp, "adi,slew", tmparray, 3)) {
675 pdata->dac[devnr].slew.enable = tmparray[0];
677 pdata->dac[devnr].slew.rate = AD5755_SLEW_RATE_64k;
678 for (i = 0; i < ARRAY_SIZE(ad5755_slew_rate_table); i++) {
679 if (tmparray[1] == ad5755_slew_rate_table[i][0]) {
680 pdata->dac[devnr].slew.rate =
681 ad5755_slew_rate_table[i][1];
685 if (i == ARRAY_SIZE(ad5755_slew_rate_table)) {
687 "channel %d slew rate out of range selecting 64kHz",
691 pdata->dac[devnr].slew.step_size = AD5755_SLEW_STEP_SIZE_1;
692 for (i = 0; i < ARRAY_SIZE(ad5755_slew_step_table); i++) {
693 if (tmparray[2] == ad5755_slew_step_table[i][0]) {
694 pdata->dac[devnr].slew.step_size =
695 ad5755_slew_step_table[i][1];
699 if (i == ARRAY_SIZE(ad5755_slew_step_table)) {
701 "channel %d slew step size out of range selecting 1 LSB",
705 pdata->dac[devnr].slew.enable = false;
706 pdata->dac[devnr].slew.rate = AD5755_SLEW_RATE_64k;
707 pdata->dac[devnr].slew.step_size =
708 AD5755_SLEW_STEP_SIZE_1;
716 devm_kfree(dev, pdata);
721 struct ad5755_platform_data *ad5755_parse_dt(struct device *dev)
727 static int ad5755_probe(struct spi_device *spi)
729 enum ad5755_type type = spi_get_device_id(spi)->driver_data;
730 const struct ad5755_platform_data *pdata = dev_get_platdata(&spi->dev);
731 struct iio_dev *indio_dev;
732 struct ad5755_state *st;
735 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
736 if (indio_dev == NULL) {
737 dev_err(&spi->dev, "Failed to allocate iio device\n");
741 st = iio_priv(indio_dev);
742 spi_set_drvdata(spi, indio_dev);
744 st->chip_info = &ad5755_chip_info_tbl[type];
748 indio_dev->dev.parent = &spi->dev;
749 indio_dev->name = spi_get_device_id(spi)->name;
750 indio_dev->info = &ad5755_info;
751 indio_dev->modes = INDIO_DIRECT_MODE;
752 indio_dev->num_channels = AD5755_NUM_CHANNELS;
754 if (spi->dev.of_node)
755 pdata = ad5755_parse_dt(&spi->dev);
757 pdata = spi->dev.platform_data;
760 dev_warn(&spi->dev, "no platform data? using default\n");
761 pdata = &ad5755_default_pdata;
764 ret = ad5755_init_channels(indio_dev, pdata);
768 ret = ad5755_setup_pdata(indio_dev, pdata);
772 return devm_iio_device_register(&spi->dev, indio_dev);
775 static const struct spi_device_id ad5755_id[] = {
776 { "ad5755", ID_AD5755 },
777 { "ad5755-1", ID_AD5755 },
778 { "ad5757", ID_AD5757 },
779 { "ad5735", ID_AD5735 },
780 { "ad5737", ID_AD5737 },
783 MODULE_DEVICE_TABLE(spi, ad5755_id);
785 static const struct of_device_id ad5755_of_match[] = {
786 { .compatible = "adi,ad5755" },
787 { .compatible = "adi,ad5755-1" },
788 { .compatible = "adi,ad5757" },
789 { .compatible = "adi,ad5735" },
790 { .compatible = "adi,ad5737" },
793 MODULE_DEVICE_TABLE(of, ad5755_of_match);
795 static struct spi_driver ad5755_driver = {
799 .probe = ad5755_probe,
800 .id_table = ad5755_id,
802 module_spi_driver(ad5755_driver);
805 MODULE_DESCRIPTION("Analog Devices AD5755/55-1/57/35/37 DAC");
806 MODULE_LICENSE("GPL v2");