blob: 6c6879db60e4820b6cdcb0bee7857949addd0492 [file] [log] [blame]
Stefan Popa0357e482018-04-11 14:53:17 +03001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * This file is part of AD5686 DAC driver
4 *
5 * Copyright 2018 Analog Devices Inc.
6 */
7
8#ifndef __DRIVERS_IIO_DAC_AD5686_H__
9#define __DRIVERS_IIO_DAC_AD5686_H__
10
11#include <linux/types.h>
12#include <linux/cache.h>
13#include <linux/mutex.h>
14#include <linux/kernel.h>
15
16#define AD5686_ADDR(x) ((x) << 16)
17#define AD5686_CMD(x) ((x) << 20)
18
19#define AD5686_ADDR_DAC(chan) (0x1 << (chan))
20#define AD5686_ADDR_ALL_DAC 0xF
21
22#define AD5686_CMD_NOOP 0x0
23#define AD5686_CMD_WRITE_INPUT_N 0x1
24#define AD5686_CMD_UPDATE_DAC_N 0x2
25#define AD5686_CMD_WRITE_INPUT_N_UPDATE_N 0x3
26#define AD5686_CMD_POWERDOWN_DAC 0x4
27#define AD5686_CMD_LDAC_MASK 0x5
28#define AD5686_CMD_RESET 0x6
29#define AD5686_CMD_INTERNAL_REFER_SETUP 0x7
30#define AD5686_CMD_DAISY_CHAIN_ENABLE 0x8
31#define AD5686_CMD_READBACK_ENABLE 0x9
32
33#define AD5686_LDAC_PWRDN_NONE 0x0
34#define AD5686_LDAC_PWRDN_1K 0x1
35#define AD5686_LDAC_PWRDN_100K 0x2
36#define AD5686_LDAC_PWRDN_3STATE 0x3
37
Stefan Popabe1b24d2018-05-18 18:22:50 +030038#define AD5686_CMD_CONTROL_REG 0x4
39#define AD5693_REF_BIT_MSK BIT(12)
40
Stefan Popa0357e482018-04-11 14:53:17 +030041/**
42 * ad5686_supported_device_ids:
43 */
44enum ad5686_supported_device_ids {
Stefan Popa41773812018-04-11 14:53:39 +030045 ID_AD5671R,
Stefan Popa0357e482018-04-11 14:53:17 +030046 ID_AD5672R,
Stefan Popa41773812018-04-11 14:53:39 +030047 ID_AD5675R,
Stefan Popa0357e482018-04-11 14:53:17 +030048 ID_AD5676,
49 ID_AD5676R,
50 ID_AD5684,
51 ID_AD5684R,
52 ID_AD5685R,
53 ID_AD5686,
54 ID_AD5686R,
Stefan Popabe1b24d2018-05-18 18:22:50 +030055 ID_AD5691R,
56 ID_AD5692R,
57 ID_AD5693,
58 ID_AD5693R,
Stefan Popa41773812018-04-11 14:53:39 +030059 ID_AD5694,
60 ID_AD5694R,
61 ID_AD5695R,
62 ID_AD5696,
63 ID_AD5696R,
Stefan Popa0357e482018-04-11 14:53:17 +030064};
65
Stefan Popabe1b24d2018-05-18 18:22:50 +030066enum ad5686_regmap_type {
67 AD5686_REGMAP,
68 AD5693_REGMAP
69};
70
Stefan Popa0357e482018-04-11 14:53:17 +030071struct ad5686_state;
72
73typedef int (*ad5686_write_func)(struct ad5686_state *st,
74 u8 cmd, u8 addr, u16 val);
75
76typedef int (*ad5686_read_func)(struct ad5686_state *st, u8 addr);
77
78/**
79 * struct ad5686_chip_info - chip specific information
80 * @int_vref_mv: AD5620/40/60: the internal reference voltage
81 * @num_channels: number of channels
82 * @channel: channel specification
Stefan Popabe1b24d2018-05-18 18:22:50 +030083 * @regmap_type: register map layout variant
Stefan Popa0357e482018-04-11 14:53:17 +030084 */
85
86struct ad5686_chip_info {
87 u16 int_vref_mv;
88 unsigned int num_channels;
89 struct iio_chan_spec *channels;
Stefan Popabe1b24d2018-05-18 18:22:50 +030090 enum ad5686_regmap_type regmap_type;
Stefan Popa0357e482018-04-11 14:53:17 +030091};
92
93/**
94 * struct ad5446_state - driver instance specific data
95 * @spi: spi_device
96 * @chip_info: chip model specific constants, available modes etc
97 * @reg: supply regulator
98 * @vref_mv: actual reference voltage used
99 * @pwr_down_mask: power down mask
100 * @pwr_down_mode: current power down mode
Stefan Popabe1b24d2018-05-18 18:22:50 +0300101 * @use_internal_vref: set to true if the internal reference voltage is used
Stefan Popa0357e482018-04-11 14:53:17 +0300102 * @data: spi transfer buffers
103 */
104
105struct ad5686_state {
106 struct device *dev;
107 const struct ad5686_chip_info *chip_info;
108 struct regulator *reg;
109 unsigned short vref_mv;
110 unsigned int pwr_down_mask;
111 unsigned int pwr_down_mode;
112 ad5686_write_func write;
113 ad5686_read_func read;
Stefan Popabe1b24d2018-05-18 18:22:50 +0300114 bool use_internal_vref;
Stefan Popa0357e482018-04-11 14:53:17 +0300115
116 /*
117 * DMA (thus cache coherency maintenance) requires the
118 * transfer buffers to live in their own cache lines.
119 */
120
121 union {
122 __be32 d32;
123 __be16 d16;
124 u8 d8[4];
125 } data[3] ____cacheline_aligned;
126};
127
128
129int ad5686_probe(struct device *dev,
130 enum ad5686_supported_device_ids chip_type,
131 const char *name, ad5686_write_func write,
132 ad5686_read_func read);
133
134int ad5686_remove(struct device *dev);
135
136
137#endif /* __DRIVERS_IIO_DAC_AD5686_H__ */