#include <linux/interrupt.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/spi/spi.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
#include <linux/regulator/consumer.h>
#include <linux/module.h>
#include <linux/bitops.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/iio/dac/ad5791.h>
#define AD5791_DAC_MASK …
#define AD5791_CMD_READ …
#define AD5791_CMD_WRITE …
#define AD5791_ADDR(addr) …
#define AD5791_ADDR_NOOP …
#define AD5791_ADDR_DAC0 …
#define AD5791_ADDR_CTRL …
#define AD5791_ADDR_CLRCODE …
#define AD5791_ADDR_SW_CTRL …
#define AD5791_CTRL_RBUF …
#define AD5791_CTRL_OPGND …
#define AD5791_CTRL_DACTRI …
#define AD5791_CTRL_BIN2SC …
#define AD5791_CTRL_SDODIS …
#define AD5761_CTRL_LINCOMP(x) …
#define AD5791_LINCOMP_0_10 …
#define AD5791_LINCOMP_10_12 …
#define AD5791_LINCOMP_12_16 …
#define AD5791_LINCOMP_16_19 …
#define AD5791_LINCOMP_19_20 …
#define AD5780_LINCOMP_0_10 …
#define AD5780_LINCOMP_10_20 …
#define AD5791_SWCTRL_LDAC …
#define AD5791_SWCTRL_CLR …
#define AD5791_SWCTRL_RESET …
#define AD5791_DAC_PWRDN_6K …
#define AD5791_DAC_PWRDN_3STATE …
struct ad5791_chip_info { … };
struct ad5791_state { … };
enum ad5791_supported_device_ids { … };
static int ad5791_spi_write(struct ad5791_state *st, u8 addr, u32 val)
{ … }
static int ad5791_spi_read(struct ad5791_state *st, u8 addr, u32 *val)
{ … }
static const char * const ad5791_powerdown_modes[] = …;
static int ad5791_get_powerdown_mode(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan)
{ … }
static int ad5791_set_powerdown_mode(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan, unsigned int mode)
{ … }
static const struct iio_enum ad5791_powerdown_mode_enum = …;
static ssize_t ad5791_read_dac_powerdown(struct iio_dev *indio_dev,
uintptr_t private, const struct iio_chan_spec *chan, char *buf)
{ … }
static ssize_t ad5791_write_dac_powerdown(struct iio_dev *indio_dev,
uintptr_t private, const struct iio_chan_spec *chan, const char *buf,
size_t len)
{ … }
static int ad5791_get_lin_comp(unsigned int span)
{ … }
static int ad5780_get_lin_comp(unsigned int span)
{ … }
static const struct ad5791_chip_info ad5791_chip_info_tbl[] = …;
static int ad5791_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val,
int *val2,
long m)
{
struct ad5791_state *st = iio_priv(indio_dev);
u64 val64;
int ret;
switch (m) {
case IIO_CHAN_INFO_RAW:
ret = ad5791_spi_read(st, chan->address, val);
if (ret)
return ret;
*val &= AD5791_DAC_MASK;
*val >>= chan->scan_type.shift;
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
*val = st->vref_mv;
*val2 = (1 << chan->scan_type.realbits) - 1;
return IIO_VAL_FRACTIONAL;
case IIO_CHAN_INFO_OFFSET:
val64 = (((u64)st->vref_neg_mv) << chan->scan_type.realbits);
do_div(val64, st->vref_mv);
*val = -val64;
return IIO_VAL_INT;
default:
return -EINVAL;
}
};
static const struct iio_chan_spec_ext_info ad5791_ext_info[] = …;
#define AD5791_CHAN(bits, _shift) …
static const struct iio_chan_spec ad5791_channels[] = …;
static int ad5791_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val,
int val2,
long mask)
{ … }
static const struct iio_info ad5791_info = …;
static int ad5791_probe(struct spi_device *spi)
{ … }
static void ad5791_remove(struct spi_device *spi)
{ … }
static const struct spi_device_id ad5791_id[] = …;
MODULE_DEVICE_TABLE(spi, ad5791_id);
static struct spi_driver ad5791_driver = …;
module_spi_driver(…) …;
MODULE_AUTHOR(…) …;
MODULE_DESCRIPTION(…) …;
MODULE_LICENSE(…) …;