2 * AD5024, AD5025, AD5044, AD5045, AD5064, AD5064-1, AD5065, AD5625, AD5625R,
3 * AD5627, AD5627R, AD5628, AD5629R, AD5645R, AD5647R, AD5648, AD5665, AD5665R,
4 * AD5666, AD5667, AD5667R, AD5668, AD5669R, LTC2606, LTC2607, LTC2609, LTC2616,
5 * LTC2617, LTC2619, LTC2626, LTC2627, LTC2629 Digital to analog converters
8 * Copyright 2011 Analog Devices Inc.
10 * Licensed under the GPL-2.
13 #include <linux/device.h>
14 #include <linux/err.h>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/spi/spi.h>
18 #include <linux/i2c.h>
19 #include <linux/slab.h>
20 #include <linux/sysfs.h>
21 #include <linux/regulator/consumer.h>
22 #include <asm/unaligned.h>
24 #include <linux/iio/iio.h>
25 #include <linux/iio/sysfs.h>
27 #define AD5064_MAX_DAC_CHANNELS 8
28 #define AD5064_MAX_VREFS 4
30 #define AD5064_ADDR(x) ((x) << 20)
31 #define AD5064_CMD(x) ((x) << 24)
33 #define AD5064_ADDR_ALL_DAC 0xF
35 #define AD5064_CMD_WRITE_INPUT_N 0x0
36 #define AD5064_CMD_UPDATE_DAC_N 0x1
37 #define AD5064_CMD_WRITE_INPUT_N_UPDATE_ALL 0x2
38 #define AD5064_CMD_WRITE_INPUT_N_UPDATE_N 0x3
39 #define AD5064_CMD_POWERDOWN_DAC 0x4
40 #define AD5064_CMD_CLEAR 0x5
41 #define AD5064_CMD_LDAC_MASK 0x6
42 #define AD5064_CMD_RESET 0x7
43 #define AD5064_CMD_CONFIG 0x8
45 #define AD5064_CMD_RESET_V2 0x5
46 #define AD5064_CMD_CONFIG_V2 0x7
48 #define AD5064_CONFIG_DAISY_CHAIN_ENABLE BIT(1)
49 #define AD5064_CONFIG_INT_VREF_ENABLE BIT(0)
51 #define AD5064_LDAC_PWRDN_NONE 0x0
52 #define AD5064_LDAC_PWRDN_1K 0x1
53 #define AD5064_LDAC_PWRDN_100K 0x2
54 #define AD5064_LDAC_PWRDN_3STATE 0x3
57 * enum ad5064_regmap_type - Register layout variant
58 * @AD5064_REGMAP_ADI: Old Analog Devices register map layout
59 * @AD5064_REGMAP_ADI2: New Analog Devices register map layout
60 * @AD5064_REGMAP_LTC: LTC register map layout
62 enum ad5064_regmap_type {
69 * struct ad5064_chip_info - chip specific information
70 * @shared_vref: whether the vref supply is shared between channels
71 * @internal_vref: internal reference voltage. 0 if the chip has no
73 * @channel: channel specification
74 * @num_channels: number of channels
75 * @regmap_type: register map layout variant
78 struct ad5064_chip_info {
80 unsigned long internal_vref;
81 const struct iio_chan_spec *channels;
82 unsigned int num_channels;
83 enum ad5064_regmap_type regmap_type;
88 typedef int (*ad5064_write_func)(struct ad5064_state *st, unsigned int cmd,
89 unsigned int addr, unsigned int val);
92 * struct ad5064_state - driver instance specific data
93 * @dev: the device for this driver instance
94 * @chip_info: chip model specific constants, available modes etc
95 * @vref_reg: vref supply regulators
96 * @pwr_down: whether channel is powered down
97 * @pwr_down_mode: channel's current power down mode
98 * @dac_cache: current DAC raw value (chip does not support readback)
99 * @use_internal_vref: set to true if the internal reference voltage should be
101 * @write: register write callback
102 * @data: i2c/spi transfer buffers
105 struct ad5064_state {
107 const struct ad5064_chip_info *chip_info;
108 struct regulator_bulk_data vref_reg[AD5064_MAX_VREFS];
109 bool pwr_down[AD5064_MAX_DAC_CHANNELS];
110 u8 pwr_down_mode[AD5064_MAX_DAC_CHANNELS];
111 unsigned int dac_cache[AD5064_MAX_DAC_CHANNELS];
112 bool use_internal_vref;
114 ad5064_write_func write;
117 * DMA (thus cache coherency maintenance) requires the
118 * transfer buffers to live in their own cache lines.
123 } data ____cacheline_aligned;
173 static int ad5064_write(struct ad5064_state *st, unsigned int cmd,
174 unsigned int addr, unsigned int val, unsigned int shift)
178 return st->write(st, cmd, addr, val);
181 static int ad5064_sync_powerdown_mode(struct ad5064_state *st,
182 const struct iio_chan_spec *chan)
184 unsigned int val, address;
188 if (st->chip_info->regmap_type == AD5064_REGMAP_LTC) {
190 address = chan->address;
192 if (st->chip_info->regmap_type == AD5064_REGMAP_ADI2)
197 val = (0x1 << chan->address);
200 if (st->pwr_down[chan->channel])
201 val |= st->pwr_down_mode[chan->channel] << shift;
204 ret = ad5064_write(st, AD5064_CMD_POWERDOWN_DAC, address, val, 0);
209 static const char * const ad5064_powerdown_modes[] = {
215 static const char * const ltc2617_powerdown_modes[] = {
219 static int ad5064_get_powerdown_mode(struct iio_dev *indio_dev,
220 const struct iio_chan_spec *chan)
222 struct ad5064_state *st = iio_priv(indio_dev);
224 return st->pwr_down_mode[chan->channel] - 1;
227 static int ad5064_set_powerdown_mode(struct iio_dev *indio_dev,
228 const struct iio_chan_spec *chan, unsigned int mode)
230 struct ad5064_state *st = iio_priv(indio_dev);
233 mutex_lock(&indio_dev->mlock);
234 st->pwr_down_mode[chan->channel] = mode + 1;
236 ret = ad5064_sync_powerdown_mode(st, chan);
237 mutex_unlock(&indio_dev->mlock);
242 static const struct iio_enum ad5064_powerdown_mode_enum = {
243 .items = ad5064_powerdown_modes,
244 .num_items = ARRAY_SIZE(ad5064_powerdown_modes),
245 .get = ad5064_get_powerdown_mode,
246 .set = ad5064_set_powerdown_mode,
249 static const struct iio_enum ltc2617_powerdown_mode_enum = {
250 .items = ltc2617_powerdown_modes,
251 .num_items = ARRAY_SIZE(ltc2617_powerdown_modes),
252 .get = ad5064_get_powerdown_mode,
253 .set = ad5064_set_powerdown_mode,
256 static ssize_t ad5064_read_dac_powerdown(struct iio_dev *indio_dev,
257 uintptr_t private, const struct iio_chan_spec *chan, char *buf)
259 struct ad5064_state *st = iio_priv(indio_dev);
261 return sprintf(buf, "%d\n", st->pwr_down[chan->channel]);
264 static ssize_t ad5064_write_dac_powerdown(struct iio_dev *indio_dev,
265 uintptr_t private, const struct iio_chan_spec *chan, const char *buf,
268 struct ad5064_state *st = iio_priv(indio_dev);
272 ret = strtobool(buf, &pwr_down);
276 mutex_lock(&indio_dev->mlock);
277 st->pwr_down[chan->channel] = pwr_down;
279 ret = ad5064_sync_powerdown_mode(st, chan);
280 mutex_unlock(&indio_dev->mlock);
281 return ret ? ret : len;
284 static int ad5064_get_vref(struct ad5064_state *st,
285 struct iio_chan_spec const *chan)
289 if (st->use_internal_vref)
290 return st->chip_info->internal_vref;
292 i = st->chip_info->shared_vref ? 0 : chan->channel;
293 return regulator_get_voltage(st->vref_reg[i].consumer);
296 static int ad5064_read_raw(struct iio_dev *indio_dev,
297 struct iio_chan_spec const *chan,
302 struct ad5064_state *st = iio_priv(indio_dev);
306 case IIO_CHAN_INFO_RAW:
307 *val = st->dac_cache[chan->channel];
309 case IIO_CHAN_INFO_SCALE:
310 scale_uv = ad5064_get_vref(st, chan);
314 *val = scale_uv / 1000;
315 *val2 = chan->scan_type.realbits;
316 return IIO_VAL_FRACTIONAL_LOG2;
323 static int ad5064_write_raw(struct iio_dev *indio_dev,
324 struct iio_chan_spec const *chan, int val, int val2, long mask)
326 struct ad5064_state *st = iio_priv(indio_dev);
330 case IIO_CHAN_INFO_RAW:
331 if (val >= (1 << chan->scan_type.realbits) || val < 0)
334 mutex_lock(&indio_dev->mlock);
335 ret = ad5064_write(st, AD5064_CMD_WRITE_INPUT_N_UPDATE_N,
336 chan->address, val, chan->scan_type.shift);
338 st->dac_cache[chan->channel] = val;
339 mutex_unlock(&indio_dev->mlock);
348 static const struct iio_info ad5064_info = {
349 .read_raw = ad5064_read_raw,
350 .write_raw = ad5064_write_raw,
351 .driver_module = THIS_MODULE,
354 static const struct iio_chan_spec_ext_info ad5064_ext_info[] = {
357 .read = ad5064_read_dac_powerdown,
358 .write = ad5064_write_dac_powerdown,
359 .shared = IIO_SEPARATE,
361 IIO_ENUM("powerdown_mode", IIO_SEPARATE, &ad5064_powerdown_mode_enum),
362 IIO_ENUM_AVAILABLE("powerdown_mode", &ad5064_powerdown_mode_enum),
366 static const struct iio_chan_spec_ext_info ltc2617_ext_info[] = {
369 .read = ad5064_read_dac_powerdown,
370 .write = ad5064_write_dac_powerdown,
371 .shared = IIO_SEPARATE,
373 IIO_ENUM("powerdown_mode", IIO_SEPARATE, <c2617_powerdown_mode_enum),
374 IIO_ENUM_AVAILABLE("powerdown_mode", <c2617_powerdown_mode_enum),
378 #define AD5064_CHANNEL(chan, addr, bits, _shift, _ext_info) { \
379 .type = IIO_VOLTAGE, \
383 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
384 BIT(IIO_CHAN_INFO_SCALE), \
388 .realbits = (bits), \
392 .ext_info = (_ext_info), \
395 #define DECLARE_AD5064_CHANNELS(name, bits, shift, ext_info) \
396 const struct iio_chan_spec name[] = { \
397 AD5064_CHANNEL(0, 0, bits, shift, ext_info), \
398 AD5064_CHANNEL(1, 1, bits, shift, ext_info), \
399 AD5064_CHANNEL(2, 2, bits, shift, ext_info), \
400 AD5064_CHANNEL(3, 3, bits, shift, ext_info), \
401 AD5064_CHANNEL(4, 4, bits, shift, ext_info), \
402 AD5064_CHANNEL(5, 5, bits, shift, ext_info), \
403 AD5064_CHANNEL(6, 6, bits, shift, ext_info), \
404 AD5064_CHANNEL(7, 7, bits, shift, ext_info), \
407 #define DECLARE_AD5065_CHANNELS(name, bits, shift, ext_info) \
408 const struct iio_chan_spec name[] = { \
409 AD5064_CHANNEL(0, 0, bits, shift, ext_info), \
410 AD5064_CHANNEL(1, 3, bits, shift, ext_info), \
413 static DECLARE_AD5064_CHANNELS(ad5024_channels, 12, 8, ad5064_ext_info);
414 static DECLARE_AD5064_CHANNELS(ad5044_channels, 14, 6, ad5064_ext_info);
415 static DECLARE_AD5064_CHANNELS(ad5064_channels, 16, 4, ad5064_ext_info);
417 static DECLARE_AD5065_CHANNELS(ad5025_channels, 12, 8, ad5064_ext_info);
418 static DECLARE_AD5065_CHANNELS(ad5045_channels, 14, 6, ad5064_ext_info);
419 static DECLARE_AD5065_CHANNELS(ad5065_channels, 16, 4, ad5064_ext_info);
421 static DECLARE_AD5064_CHANNELS(ad5629_channels, 12, 4, ad5064_ext_info);
422 static DECLARE_AD5064_CHANNELS(ad5645_channels, 14, 2, ad5064_ext_info);
423 static DECLARE_AD5064_CHANNELS(ad5669_channels, 16, 0, ad5064_ext_info);
425 static DECLARE_AD5064_CHANNELS(ltc2607_channels, 16, 0, ltc2617_ext_info);
426 static DECLARE_AD5064_CHANNELS(ltc2617_channels, 14, 2, ltc2617_ext_info);
427 static DECLARE_AD5064_CHANNELS(ltc2627_channels, 12, 4, ltc2617_ext_info);
429 static const struct ad5064_chip_info ad5064_chip_info_tbl[] = {
431 .shared_vref = false,
432 .channels = ad5024_channels,
434 .regmap_type = AD5064_REGMAP_ADI,
437 .shared_vref = false,
438 .channels = ad5025_channels,
440 .regmap_type = AD5064_REGMAP_ADI,
443 .shared_vref = false,
444 .channels = ad5044_channels,
446 .regmap_type = AD5064_REGMAP_ADI,
449 .shared_vref = false,
450 .channels = ad5045_channels,
452 .regmap_type = AD5064_REGMAP_ADI,
455 .shared_vref = false,
456 .channels = ad5064_channels,
458 .regmap_type = AD5064_REGMAP_ADI,
462 .channels = ad5064_channels,
464 .regmap_type = AD5064_REGMAP_ADI,
467 .shared_vref = false,
468 .channels = ad5065_channels,
470 .regmap_type = AD5064_REGMAP_ADI,
474 .channels = ad5629_channels,
476 .regmap_type = AD5064_REGMAP_ADI2
478 [ID_AD5625R_1V25] = {
480 .internal_vref = 1250000,
481 .channels = ad5629_channels,
483 .regmap_type = AD5064_REGMAP_ADI2
487 .internal_vref = 2500000,
488 .channels = ad5629_channels,
490 .regmap_type = AD5064_REGMAP_ADI2
494 .channels = ad5629_channels,
496 .regmap_type = AD5064_REGMAP_ADI2
498 [ID_AD5627R_1V25] = {
500 .internal_vref = 1250000,
501 .channels = ad5629_channels,
503 .regmap_type = AD5064_REGMAP_ADI2
507 .internal_vref = 2500000,
508 .channels = ad5629_channels,
510 .regmap_type = AD5064_REGMAP_ADI2
514 .internal_vref = 2500000,
515 .channels = ad5024_channels,
517 .regmap_type = AD5064_REGMAP_ADI,
521 .internal_vref = 5000000,
522 .channels = ad5024_channels,
524 .regmap_type = AD5064_REGMAP_ADI,
528 .internal_vref = 2500000,
529 .channels = ad5629_channels,
531 .regmap_type = AD5064_REGMAP_ADI,
535 .internal_vref = 5000000,
536 .channels = ad5629_channels,
538 .regmap_type = AD5064_REGMAP_ADI,
540 [ID_AD5645R_1V25] = {
542 .internal_vref = 1250000,
543 .channels = ad5645_channels,
545 .regmap_type = AD5064_REGMAP_ADI2
549 .internal_vref = 2500000,
550 .channels = ad5645_channels,
552 .regmap_type = AD5064_REGMAP_ADI2
554 [ID_AD5647R_1V25] = {
556 .internal_vref = 1250000,
557 .channels = ad5645_channels,
559 .regmap_type = AD5064_REGMAP_ADI2
563 .internal_vref = 2500000,
564 .channels = ad5645_channels,
566 .regmap_type = AD5064_REGMAP_ADI2
570 .internal_vref = 2500000,
571 .channels = ad5044_channels,
573 .regmap_type = AD5064_REGMAP_ADI,
577 .internal_vref = 5000000,
578 .channels = ad5044_channels,
580 .regmap_type = AD5064_REGMAP_ADI,
584 .channels = ad5669_channels,
586 .regmap_type = AD5064_REGMAP_ADI2
588 [ID_AD5665R_1V25] = {
590 .internal_vref = 1250000,
591 .channels = ad5669_channels,
593 .regmap_type = AD5064_REGMAP_ADI2
597 .internal_vref = 2500000,
598 .channels = ad5669_channels,
600 .regmap_type = AD5064_REGMAP_ADI2
604 .internal_vref = 2500000,
605 .channels = ad5064_channels,
607 .regmap_type = AD5064_REGMAP_ADI,
611 .internal_vref = 5000000,
612 .channels = ad5064_channels,
614 .regmap_type = AD5064_REGMAP_ADI,
618 .channels = ad5669_channels,
620 .regmap_type = AD5064_REGMAP_ADI2
622 [ID_AD5667R_1V25] = {
624 .internal_vref = 1250000,
625 .channels = ad5669_channels,
627 .regmap_type = AD5064_REGMAP_ADI2
631 .internal_vref = 2500000,
632 .channels = ad5669_channels,
634 .regmap_type = AD5064_REGMAP_ADI2
638 .internal_vref = 2500000,
639 .channels = ad5064_channels,
641 .regmap_type = AD5064_REGMAP_ADI,
645 .internal_vref = 5000000,
646 .channels = ad5064_channels,
648 .regmap_type = AD5064_REGMAP_ADI,
652 .internal_vref = 2500000,
653 .channels = ad5669_channels,
655 .regmap_type = AD5064_REGMAP_ADI,
659 .internal_vref = 5000000,
660 .channels = ad5669_channels,
662 .regmap_type = AD5064_REGMAP_ADI,
667 .channels = ltc2607_channels,
669 .regmap_type = AD5064_REGMAP_LTC,
674 .channels = ltc2607_channels,
676 .regmap_type = AD5064_REGMAP_LTC,
679 .shared_vref = false,
681 .channels = ltc2607_channels,
683 .regmap_type = AD5064_REGMAP_LTC,
688 .channels = ltc2617_channels,
690 .regmap_type = AD5064_REGMAP_LTC,
695 .channels = ltc2617_channels,
697 .regmap_type = AD5064_REGMAP_LTC,
700 .shared_vref = false,
702 .channels = ltc2617_channels,
704 .regmap_type = AD5064_REGMAP_LTC,
709 .channels = ltc2627_channels,
711 .regmap_type = AD5064_REGMAP_LTC,
716 .channels = ltc2627_channels,
718 .regmap_type = AD5064_REGMAP_LTC,
721 .shared_vref = false,
723 .channels = ltc2627_channels,
725 .regmap_type = AD5064_REGMAP_LTC,
729 static inline unsigned int ad5064_num_vref(struct ad5064_state *st)
731 return st->chip_info->shared_vref ? 1 : st->chip_info->num_channels;
734 static const char * const ad5064_vref_names[] = {
741 static const char * const ad5064_vref_name(struct ad5064_state *st,
744 return st->chip_info->shared_vref ? "vref" : ad5064_vref_names[vref];
747 static int ad5064_set_config(struct ad5064_state *st, unsigned int val)
751 switch (st->chip_info->regmap_type) {
752 case AD5064_REGMAP_ADI2:
753 cmd = AD5064_CMD_CONFIG_V2;
756 cmd = AD5064_CMD_CONFIG;
760 return ad5064_write(st, cmd, 0, val, 0);
763 static int ad5064_request_vref(struct ad5064_state *st, struct device *dev)
768 for (i = 0; i < ad5064_num_vref(st); ++i)
769 st->vref_reg[i].supply = ad5064_vref_name(st, i);
771 if (!st->chip_info->internal_vref)
772 return devm_regulator_bulk_get(dev, ad5064_num_vref(st),
776 * This assumes that when the regulator has an internal VREF
777 * there is only one external VREF connection, which is
778 * currently the case for all supported devices.
780 st->vref_reg[0].consumer = devm_regulator_get_optional(dev, "vref");
781 if (!IS_ERR(st->vref_reg[0].consumer))
784 ret = PTR_ERR(st->vref_reg[0].consumer);
788 /* If no external regulator was supplied use the internal VREF */
789 st->use_internal_vref = true;
790 ret = ad5064_set_config(st, AD5064_CONFIG_INT_VREF_ENABLE);
792 dev_err(dev, "Failed to enable internal vref: %d\n", ret);
797 static int ad5064_probe(struct device *dev, enum ad5064_type type,
798 const char *name, ad5064_write_func write)
800 struct iio_dev *indio_dev;
801 struct ad5064_state *st;
802 unsigned int midscale;
806 indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
807 if (indio_dev == NULL)
810 st = iio_priv(indio_dev);
811 dev_set_drvdata(dev, indio_dev);
813 st->chip_info = &ad5064_chip_info_tbl[type];
817 ret = ad5064_request_vref(st, dev);
821 if (!st->use_internal_vref) {
822 ret = regulator_bulk_enable(ad5064_num_vref(st), st->vref_reg);
827 indio_dev->dev.parent = dev;
828 indio_dev->name = name;
829 indio_dev->info = &ad5064_info;
830 indio_dev->modes = INDIO_DIRECT_MODE;
831 indio_dev->channels = st->chip_info->channels;
832 indio_dev->num_channels = st->chip_info->num_channels;
834 midscale = (1 << indio_dev->channels[0].scan_type.realbits) / 2;
836 for (i = 0; i < st->chip_info->num_channels; ++i) {
837 st->pwr_down_mode[i] = AD5064_LDAC_PWRDN_1K;
838 st->dac_cache[i] = midscale;
841 ret = iio_device_register(indio_dev);
843 goto error_disable_reg;
848 if (!st->use_internal_vref)
849 regulator_bulk_disable(ad5064_num_vref(st), st->vref_reg);
854 static int ad5064_remove(struct device *dev)
856 struct iio_dev *indio_dev = dev_get_drvdata(dev);
857 struct ad5064_state *st = iio_priv(indio_dev);
859 iio_device_unregister(indio_dev);
861 if (!st->use_internal_vref)
862 regulator_bulk_disable(ad5064_num_vref(st), st->vref_reg);
867 #if IS_ENABLED(CONFIG_SPI_MASTER)
869 static int ad5064_spi_write(struct ad5064_state *st, unsigned int cmd,
870 unsigned int addr, unsigned int val)
872 struct spi_device *spi = to_spi_device(st->dev);
874 st->data.spi = cpu_to_be32(AD5064_CMD(cmd) | AD5064_ADDR(addr) | val);
875 return spi_write(spi, &st->data.spi, sizeof(st->data.spi));
878 static int ad5064_spi_probe(struct spi_device *spi)
880 const struct spi_device_id *id = spi_get_device_id(spi);
882 return ad5064_probe(&spi->dev, id->driver_data, id->name,
886 static int ad5064_spi_remove(struct spi_device *spi)
888 return ad5064_remove(&spi->dev);
891 static const struct spi_device_id ad5064_spi_ids[] = {
892 {"ad5024", ID_AD5024},
893 {"ad5025", ID_AD5025},
894 {"ad5044", ID_AD5044},
895 {"ad5045", ID_AD5045},
896 {"ad5064", ID_AD5064},
897 {"ad5064-1", ID_AD5064_1},
898 {"ad5065", ID_AD5065},
899 {"ad5628-1", ID_AD5628_1},
900 {"ad5628-2", ID_AD5628_2},
901 {"ad5648-1", ID_AD5648_1},
902 {"ad5648-2", ID_AD5648_2},
903 {"ad5666-1", ID_AD5666_1},
904 {"ad5666-2", ID_AD5666_2},
905 {"ad5668-1", ID_AD5668_1},
906 {"ad5668-2", ID_AD5668_2},
907 {"ad5668-3", ID_AD5668_2}, /* similar enough to ad5668-2 */
910 MODULE_DEVICE_TABLE(spi, ad5064_spi_ids);
912 static struct spi_driver ad5064_spi_driver = {
916 .probe = ad5064_spi_probe,
917 .remove = ad5064_spi_remove,
918 .id_table = ad5064_spi_ids,
921 static int __init ad5064_spi_register_driver(void)
923 return spi_register_driver(&ad5064_spi_driver);
926 static void ad5064_spi_unregister_driver(void)
928 spi_unregister_driver(&ad5064_spi_driver);
933 static inline int ad5064_spi_register_driver(void) { return 0; }
934 static inline void ad5064_spi_unregister_driver(void) { }
938 #if IS_ENABLED(CONFIG_I2C)
940 static int ad5064_i2c_write(struct ad5064_state *st, unsigned int cmd,
941 unsigned int addr, unsigned int val)
943 struct i2c_client *i2c = to_i2c_client(st->dev);
944 unsigned int cmd_shift;
947 switch (st->chip_info->regmap_type) {
948 case AD5064_REGMAP_ADI2:
956 st->data.i2c[0] = (cmd << cmd_shift) | addr;
957 put_unaligned_be16(val, &st->data.i2c[1]);
959 ret = i2c_master_send(i2c, st->data.i2c, 3);
966 static int ad5064_i2c_probe(struct i2c_client *i2c,
967 const struct i2c_device_id *id)
969 return ad5064_probe(&i2c->dev, id->driver_data, id->name,
973 static int ad5064_i2c_remove(struct i2c_client *i2c)
975 return ad5064_remove(&i2c->dev);
978 static const struct i2c_device_id ad5064_i2c_ids[] = {
979 {"ad5625", ID_AD5625 },
980 {"ad5625r-1v25", ID_AD5625R_1V25 },
981 {"ad5625r-2v5", ID_AD5625R_2V5 },
982 {"ad5627", ID_AD5627 },
983 {"ad5627r-1v25", ID_AD5627R_1V25 },
984 {"ad5627r-2v5", ID_AD5627R_2V5 },
985 {"ad5629-1", ID_AD5629_1},
986 {"ad5629-2", ID_AD5629_2},
987 {"ad5629-3", ID_AD5629_2}, /* similar enough to ad5629-2 */
988 {"ad5645r-1v25", ID_AD5645R_1V25 },
989 {"ad5645r-2v5", ID_AD5645R_2V5 },
990 {"ad5665", ID_AD5665 },
991 {"ad5665r-1v25", ID_AD5665R_1V25 },
992 {"ad5665r-2v5", ID_AD5665R_2V5 },
993 {"ad5667", ID_AD5667 },
994 {"ad5667r-1v25", ID_AD5667R_1V25 },
995 {"ad5667r-2v5", ID_AD5667R_2V5 },
996 {"ad5669-1", ID_AD5669_1},
997 {"ad5669-2", ID_AD5669_2},
998 {"ad5669-3", ID_AD5669_2}, /* similar enough to ad5669-2 */
999 {"ltc2606", ID_LTC2606},
1000 {"ltc2607", ID_LTC2607},
1001 {"ltc2609", ID_LTC2609},
1002 {"ltc2616", ID_LTC2616},
1003 {"ltc2617", ID_LTC2617},
1004 {"ltc2619", ID_LTC2619},
1005 {"ltc2626", ID_LTC2626},
1006 {"ltc2627", ID_LTC2627},
1007 {"ltc2629", ID_LTC2629},
1010 MODULE_DEVICE_TABLE(i2c, ad5064_i2c_ids);
1012 static struct i2c_driver ad5064_i2c_driver = {
1016 .probe = ad5064_i2c_probe,
1017 .remove = ad5064_i2c_remove,
1018 .id_table = ad5064_i2c_ids,
1021 static int __init ad5064_i2c_register_driver(void)
1023 return i2c_add_driver(&ad5064_i2c_driver);
1026 static void __exit ad5064_i2c_unregister_driver(void)
1028 i2c_del_driver(&ad5064_i2c_driver);
1033 static inline int ad5064_i2c_register_driver(void) { return 0; }
1034 static inline void ad5064_i2c_unregister_driver(void) { }
1038 static int __init ad5064_init(void)
1042 ret = ad5064_spi_register_driver();
1046 ret = ad5064_i2c_register_driver();
1048 ad5064_spi_unregister_driver();
1054 module_init(ad5064_init);
1056 static void __exit ad5064_exit(void)
1058 ad5064_i2c_unregister_driver();
1059 ad5064_spi_unregister_driver();
1061 module_exit(ad5064_exit);
1063 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
1064 MODULE_DESCRIPTION("Analog Devices AD5024 and similar multi-channel DACs");
1065 MODULE_LICENSE("GPL v2");