Skip to content

Commit 5dcbe97

Browse files
larsclausenjic23
authored andcommitted
iio: ad5064: Fix ad5629/ad5669 shift
The ad5629/ad5669 are the I2C variant of the ad5628/ad5668, which has a SPI interface. They are mostly identical with the exception that the shift factor is different. Currently the driver does not take care of this difference which leads to incorrect DAC output values. Fix this by introducing a custom channel spec for the ad5629/ad5669 with the correct shift factor. Fixes: commit 6a17a07 ("iio:dac:ad5064: Add support for the ad5629r and ad5669r") Signed-off-by: Lars-Peter Clausen <[email protected]> Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 03fe472 commit 5dcbe97

File tree

1 file changed

+57
-26
lines changed

1 file changed

+57
-26
lines changed

drivers/iio/dac/ad5064.c

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,16 @@ enum ad5064_type {
113113
ID_AD5065,
114114
ID_AD5628_1,
115115
ID_AD5628_2,
116+
ID_AD5629_1,
117+
ID_AD5629_2,
116118
ID_AD5648_1,
117119
ID_AD5648_2,
118120
ID_AD5666_1,
119121
ID_AD5666_2,
120122
ID_AD5668_1,
121123
ID_AD5668_2,
124+
ID_AD5669_1,
125+
ID_AD5669_2,
122126
};
123127

124128
static int ad5064_write(struct ad5064_state *st, unsigned int cmd,
@@ -291,7 +295,7 @@ static const struct iio_chan_spec_ext_info ad5064_ext_info[] = {
291295
{ },
292296
};
293297

294-
#define AD5064_CHANNEL(chan, addr, bits) { \
298+
#define AD5064_CHANNEL(chan, addr, bits, _shift) { \
295299
.type = IIO_VOLTAGE, \
296300
.indexed = 1, \
297301
.output = 1, \
@@ -303,36 +307,39 @@ static const struct iio_chan_spec_ext_info ad5064_ext_info[] = {
303307
.sign = 'u', \
304308
.realbits = (bits), \
305309
.storagebits = 16, \
306-
.shift = 20 - bits, \
310+
.shift = (_shift), \
307311
}, \
308312
.ext_info = ad5064_ext_info, \
309313
}
310314

311-
#define DECLARE_AD5064_CHANNELS(name, bits) \
315+
#define DECLARE_AD5064_CHANNELS(name, bits, shift) \
312316
const struct iio_chan_spec name[] = { \
313-
AD5064_CHANNEL(0, 0, bits), \
314-
AD5064_CHANNEL(1, 1, bits), \
315-
AD5064_CHANNEL(2, 2, bits), \
316-
AD5064_CHANNEL(3, 3, bits), \
317-
AD5064_CHANNEL(4, 4, bits), \
318-
AD5064_CHANNEL(5, 5, bits), \
319-
AD5064_CHANNEL(6, 6, bits), \
320-
AD5064_CHANNEL(7, 7, bits), \
317+
AD5064_CHANNEL(0, 0, bits, shift), \
318+
AD5064_CHANNEL(1, 1, bits, shift), \
319+
AD5064_CHANNEL(2, 2, bits, shift), \
320+
AD5064_CHANNEL(3, 3, bits, shift), \
321+
AD5064_CHANNEL(4, 4, bits, shift), \
322+
AD5064_CHANNEL(5, 5, bits, shift), \
323+
AD5064_CHANNEL(6, 6, bits, shift), \
324+
AD5064_CHANNEL(7, 7, bits, shift), \
321325
}
322326

323-
#define DECLARE_AD5065_CHANNELS(name, bits) \
327+
#define DECLARE_AD5065_CHANNELS(name, bits, shift) \
324328
const struct iio_chan_spec name[] = { \
325-
AD5064_CHANNEL(0, 0, bits), \
326-
AD5064_CHANNEL(1, 3, bits), \
329+
AD5064_CHANNEL(0, 0, bits, shift), \
330+
AD5064_CHANNEL(1, 3, bits, shift), \
327331
}
328332

329-
static DECLARE_AD5064_CHANNELS(ad5024_channels, 12);
330-
static DECLARE_AD5064_CHANNELS(ad5044_channels, 14);
331-
static DECLARE_AD5064_CHANNELS(ad5064_channels, 16);
333+
static DECLARE_AD5064_CHANNELS(ad5024_channels, 12, 8);
334+
static DECLARE_AD5064_CHANNELS(ad5044_channels, 14, 6);
335+
static DECLARE_AD5064_CHANNELS(ad5064_channels, 16, 4);
332336

333-
static DECLARE_AD5065_CHANNELS(ad5025_channels, 12);
334-
static DECLARE_AD5065_CHANNELS(ad5045_channels, 14);
335-
static DECLARE_AD5065_CHANNELS(ad5065_channels, 16);
337+
static DECLARE_AD5065_CHANNELS(ad5025_channels, 12, 8);
338+
static DECLARE_AD5065_CHANNELS(ad5045_channels, 14, 6);
339+
static DECLARE_AD5065_CHANNELS(ad5065_channels, 16, 4);
340+
341+
static DECLARE_AD5064_CHANNELS(ad5629_channels, 12, 4);
342+
static DECLARE_AD5064_CHANNELS(ad5669_channels, 16, 0);
336343

337344
static const struct ad5064_chip_info ad5064_chip_info_tbl[] = {
338345
[ID_AD5024] = {
@@ -382,6 +389,18 @@ static const struct ad5064_chip_info ad5064_chip_info_tbl[] = {
382389
.channels = ad5024_channels,
383390
.num_channels = 8,
384391
},
392+
[ID_AD5629_1] = {
393+
.shared_vref = true,
394+
.internal_vref = 2500000,
395+
.channels = ad5629_channels,
396+
.num_channels = 8,
397+
},
398+
[ID_AD5629_2] = {
399+
.shared_vref = true,
400+
.internal_vref = 5000000,
401+
.channels = ad5629_channels,
402+
.num_channels = 8,
403+
},
385404
[ID_AD5648_1] = {
386405
.shared_vref = true,
387406
.internal_vref = 2500000,
@@ -418,6 +437,18 @@ static const struct ad5064_chip_info ad5064_chip_info_tbl[] = {
418437
.channels = ad5064_channels,
419438
.num_channels = 8,
420439
},
440+
[ID_AD5669_1] = {
441+
.shared_vref = true,
442+
.internal_vref = 2500000,
443+
.channels = ad5669_channels,
444+
.num_channels = 8,
445+
},
446+
[ID_AD5669_2] = {
447+
.shared_vref = true,
448+
.internal_vref = 5000000,
449+
.channels = ad5669_channels,
450+
.num_channels = 8,
451+
},
421452
};
422453

423454
static inline unsigned int ad5064_num_vref(struct ad5064_state *st)
@@ -623,12 +654,12 @@ static int ad5064_i2c_remove(struct i2c_client *i2c)
623654
}
624655

625656
static const struct i2c_device_id ad5064_i2c_ids[] = {
626-
{"ad5629-1", ID_AD5628_1},
627-
{"ad5629-2", ID_AD5628_2},
628-
{"ad5629-3", ID_AD5628_2}, /* similar enough to ad5629-2 */
629-
{"ad5669-1", ID_AD5668_1},
630-
{"ad5669-2", ID_AD5668_2},
631-
{"ad5669-3", ID_AD5668_2}, /* similar enough to ad5669-2 */
657+
{"ad5629-1", ID_AD5629_1},
658+
{"ad5629-2", ID_AD5629_2},
659+
{"ad5629-3", ID_AD5629_2}, /* similar enough to ad5629-2 */
660+
{"ad5669-1", ID_AD5669_1},
661+
{"ad5669-2", ID_AD5669_2},
662+
{"ad5669-3", ID_AD5669_2}, /* similar enough to ad5669-2 */
632663
{}
633664
};
634665
MODULE_DEVICE_TABLE(i2c, ad5064_i2c_ids);

0 commit comments

Comments
 (0)