aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/dac/ad5791.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/iio/dac/ad5791.c')
-rw-r--r--drivers/iio/dac/ad5791.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/drivers/iio/dac/ad5791.c b/drivers/iio/dac/ad5791.c
index ae49afe2b380..5ba785f18589 100644
--- a/drivers/iio/dac/ad5791.c
+++ b/drivers/iio/dac/ad5791.c
@@ -16,17 +16,16 @@
16#include <linux/sysfs.h> 16#include <linux/sysfs.h>
17#include <linux/regulator/consumer.h> 17#include <linux/regulator/consumer.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/bitops.h>
19 20
20#include <linux/iio/iio.h> 21#include <linux/iio/iio.h>
21#include <linux/iio/sysfs.h> 22#include <linux/iio/sysfs.h>
22#include <linux/iio/dac/ad5791.h> 23#include <linux/iio/dac/ad5791.h>
23 24
24#define AD5791_RES_MASK(x) ((1 << (x)) - 1) 25#define AD5791_DAC_MASK GENMASK(19, 0)
25#define AD5791_DAC_MASK AD5791_RES_MASK(20)
26#define AD5791_DAC_MSB (1 << 19)
27 26
28#define AD5791_CMD_READ (1 << 23) 27#define AD5791_CMD_READ BIT(23)
29#define AD5791_CMD_WRITE (0 << 23) 28#define AD5791_CMD_WRITE 0
30#define AD5791_ADDR(addr) ((addr) << 20) 29#define AD5791_ADDR(addr) ((addr) << 20)
31 30
32/* Registers */ 31/* Registers */
@@ -37,11 +36,11 @@
37#define AD5791_ADDR_SW_CTRL 4 36#define AD5791_ADDR_SW_CTRL 4
38 37
39/* Control Register */ 38/* Control Register */
40#define AD5791_CTRL_RBUF (1 << 1) 39#define AD5791_CTRL_RBUF BIT(1)
41#define AD5791_CTRL_OPGND (1 << 2) 40#define AD5791_CTRL_OPGND BIT(2)
42#define AD5791_CTRL_DACTRI (1 << 3) 41#define AD5791_CTRL_DACTRI BIT(3)
43#define AD5791_CTRL_BIN2SC (1 << 4) 42#define AD5791_CTRL_BIN2SC BIT(4)
44#define AD5791_CTRL_SDODIS (1 << 5) 43#define AD5791_CTRL_SDODIS BIT(5)
45#define AD5761_CTRL_LINCOMP(x) ((x) << 6) 44#define AD5761_CTRL_LINCOMP(x) ((x) << 6)
46 45
47#define AD5791_LINCOMP_0_10 0 46#define AD5791_LINCOMP_0_10 0
@@ -54,9 +53,9 @@
54#define AD5780_LINCOMP_10_20 12 53#define AD5780_LINCOMP_10_20 12
55 54
56/* Software Control Register */ 55/* Software Control Register */
57#define AD5791_SWCTRL_LDAC (1 << 0) 56#define AD5791_SWCTRL_LDAC BIT(0)
58#define AD5791_SWCTRL_CLR (1 << 1) 57#define AD5791_SWCTRL_CLR BIT(1)
59#define AD5791_SWCTRL_RESET (1 << 2) 58#define AD5791_SWCTRL_RESET BIT(2)
60 59
61#define AD5791_DAC_PWRDN_6K 0 60#define AD5791_DAC_PWRDN_6K 0
62#define AD5791_DAC_PWRDN_3STATE 1 61#define AD5791_DAC_PWRDN_3STATE 1
@@ -72,7 +71,7 @@ struct ad5791_chip_info {
72 71
73/** 72/**
74 * struct ad5791_state - driver instance specific data 73 * struct ad5791_state - driver instance specific data
75 * @us: spi_device 74 * @spi: spi_device
76 * @reg_vdd: positive supply regulator 75 * @reg_vdd: positive supply regulator
77 * @reg_vss: negative supply regulator 76 * @reg_vss: negative supply regulator
78 * @chip_info: chip model specific constants 77 * @chip_info: chip model specific constants
@@ -328,7 +327,7 @@ static int ad5791_write_raw(struct iio_dev *indio_dev,
328 327
329 switch (mask) { 328 switch (mask) {
330 case IIO_CHAN_INFO_RAW: 329 case IIO_CHAN_INFO_RAW:
331 val &= AD5791_RES_MASK(chan->scan_type.realbits); 330 val &= GENMASK(chan->scan_type.realbits - 1, 0);
332 val <<= chan->scan_type.shift; 331 val <<= chan->scan_type.shift;
333 332
334 return ad5791_spi_write(st, chan->address, val); 333 return ad5791_spi_write(st, chan->address, val);