Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio:dac:ad5686: Add AD5310R support

The AD5310R is a single channel DAC with 10-bit precision, which is
part of the same family as AD5311R, except that it uses the spi interface
instead of i2c. The device has a built-in 2.5V reference which is enabled
by default.

Another important difference is that the SPI write command operation is
16 bits long. The first four bits represent the command, while the
remaining 12 bits are for data. In the control reg, DB9 and DB10 are used
for power-down modes, while DB8 is the REF bit. In order to accommodate
this change, a new regmap type was defined and checked accordingly.

Because AD5310R does not have a readback register, the read_raw operation
will return "Operation is not supported".

Datasheet:
Link: http://www.analog.com/media/en/technical-documentation/data-sheets/AD5310R_5311R.pdf

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Stefan Popa and committed by
Jonathan Cameron
12d323cf 5c608d4d

+41 -3
+18 -3
drivers/iio/dac/ad5686-spi.c
··· 19 19 u8 tx_len, *buf; 20 20 21 21 switch (st->chip_info->regmap_type) { 22 + case AD5310_REGMAP: 23 + st->data[0].d16 = cpu_to_be16(AD5310_CMD(cmd) | 24 + val); 25 + buf = &st->data[0].d8[0]; 26 + tx_len = 2; 27 + break; 22 28 case AD5683_REGMAP: 23 29 st->data[0].d32 = cpu_to_be32(AD5686_CMD(cmd) | 24 30 AD5683_DATA(val)); ··· 62 56 u8 cmd = 0; 63 57 int ret; 64 58 65 - if (st->chip_info->regmap_type == AD5686_REGMAP) 66 - cmd = AD5686_CMD_READBACK_ENABLE; 67 - else if (st->chip_info->regmap_type == AD5683_REGMAP) 59 + switch (st->chip_info->regmap_type) { 60 + case AD5310_REGMAP: 61 + return -ENOTSUPP; 62 + case AD5683_REGMAP: 68 63 cmd = AD5686_CMD_READBACK_ENABLE_V2; 64 + break; 65 + case AD5686_REGMAP: 66 + cmd = AD5686_CMD_READBACK_ENABLE; 67 + break; 68 + default: 69 + return -EINVAL; 70 + } 69 71 70 72 st->data[0].d32 = cpu_to_be32(AD5686_CMD(cmd) | 71 73 AD5686_ADDR(addr)); ··· 100 86 } 101 87 102 88 static const struct spi_device_id ad5686_spi_id[] = { 89 + {"ad5310r", ID_AD5310R}, 103 90 {"ad5672r", ID_AD5672R}, 104 91 {"ad5676", ID_AD5676}, 105 92 {"ad5676r", ID_AD5676R},
+16
drivers/iio/dac/ad5686.c
··· 83 83 st->pwr_down_mask &= ~(0x3 << (chan->channel * 2)); 84 84 85 85 switch (st->chip_info->regmap_type) { 86 + case AD5310_REGMAP: 87 + shift = 9; 88 + ref_bit_msk = AD5310_REF_BIT_MSK; 89 + break; 86 90 case AD5683_REGMAP: 87 91 shift = 13; 88 92 ref_bit_msk = AD5683_REF_BIT_MSK; ··· 225 221 AD5868_CHANNEL(7, 7, bits, _shift), \ 226 222 } 227 223 224 + DECLARE_AD5693_CHANNELS(ad5310r_channels, 10, 2); 228 225 DECLARE_AD5693_CHANNELS(ad5311r_channels, 10, 6); 229 226 DECLARE_AD5676_CHANNELS(ad5672_channels, 12, 4); 230 227 DECLARE_AD5676_CHANNELS(ad5676_channels, 16, 0); ··· 237 232 DECLARE_AD5693_CHANNELS(ad5691r_channels, 12, 4); 238 233 239 234 static const struct ad5686_chip_info ad5686_chip_info_tbl[] = { 235 + [ID_AD5310R] = { 236 + .channels = ad5310r_channels, 237 + .int_vref_mv = 2500, 238 + .num_channels = 1, 239 + .regmap_type = AD5310_REGMAP, 240 + }, 240 241 [ID_AD5311R] = { 241 242 .channels = ad5311r_channels, 242 243 .int_vref_mv = 2500, ··· 430 419 indio_dev->num_channels = st->chip_info->num_channels; 431 420 432 421 switch (st->chip_info->regmap_type) { 422 + case AD5310_REGMAP: 423 + cmd = AD5686_CMD_CONTROL_REG; 424 + ref_bit_msk = AD5310_REF_BIT_MSK; 425 + st->use_internal_vref = !voltage_uv; 426 + break; 433 427 case AD5683_REGMAP: 434 428 cmd = AD5686_CMD_CONTROL_REG; 435 429 ref_bit_msk = AD5683_REF_BIT_MSK;
+7
drivers/iio/dac/ad5686.h
··· 13 13 #include <linux/mutex.h> 14 14 #include <linux/kernel.h> 15 15 16 + #define AD5310_CMD(x) ((x) << 12) 17 + 16 18 #define AD5683_DATA(x) ((x) << 4) 19 + 17 20 #define AD5686_ADDR(x) ((x) << 16) 18 21 #define AD5686_CMD(x) ((x) << 20) 19 22 ··· 41 38 42 39 #define AD5686_CMD_CONTROL_REG 0x4 43 40 #define AD5686_CMD_READBACK_ENABLE_V2 0x5 41 + 42 + #define AD5310_REF_BIT_MSK BIT(8) 44 43 #define AD5683_REF_BIT_MSK BIT(12) 45 44 #define AD5693_REF_BIT_MSK BIT(12) 46 45 ··· 50 45 * ad5686_supported_device_ids: 51 46 */ 52 47 enum ad5686_supported_device_ids { 48 + ID_AD5310R, 53 49 ID_AD5311R, 54 50 ID_AD5671R, 55 51 ID_AD5672R, ··· 78 72 }; 79 73 80 74 enum ad5686_regmap_type { 75 + AD5310_REGMAP, 81 76 AD5683_REGMAP, 82 77 AD5686_REGMAP, 83 78 AD5693_REGMAP