adis.h (1bdd3e05a0a3b4a97ea88bc46fef8fb265c8b94c) adis.h (380b107bbf9449ddea0637cefe65a6cbf7b6ca84)
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Common library for ADIS16XXX devices
4 *
5 * Copyright 2012 Analog Devices Inc.
6 * Author: Lars-Peter Clausen <lars@metafoo.de>
7 */
8

--- 9 unchanged lines hidden (view full) ---

18
19#define ADIS_PAGE_SIZE 0x80
20#define ADIS_REG_PAGE_ID 0x00
21
22struct adis;
23struct adis_burst;
24
25/**
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Common library for ADIS16XXX devices
4 *
5 * Copyright 2012 Analog Devices Inc.
6 * Author: Lars-Peter Clausen <lars@metafoo.de>
7 */
8

--- 9 unchanged lines hidden (view full) ---

18
19#define ADIS_PAGE_SIZE 0x80
20#define ADIS_REG_PAGE_ID 0x00
21
22struct adis;
23struct adis_burst;
24
25/**
26 * struct adis_timeouts - ADIS chip variant timeouts
27 * @reset_ms - Wait time after rst pin goes inactive
28 * @sw_reset_ms - Wait time after sw reset command
29 * @self_test_ms - Wait time after self test command
30 */
31struct adis_timeout {
32 u16 reset_ms;
33 u16 sw_reset_ms;
34 u16 self_test_ms;
35};
36/**
26 * struct adis_data - ADIS chip variant specific data
27 * @read_delay: SPI delay for read operations in us
28 * @write_delay: SPI delay for write operations in us
29 * @cs_change_delay: SPI delay between CS changes in us
30 * @glob_cmd_reg: Register address of the GLOB_CMD register
31 * @msc_ctrl_reg: Register address of the MSC_CTRL register
32 * @diag_stat_reg: Register address of the DIAG_STAT register
33 * @status_error_msgs: Array of error messgaes
34 * @status_error_mask:
37 * struct adis_data - ADIS chip variant specific data
38 * @read_delay: SPI delay for read operations in us
39 * @write_delay: SPI delay for write operations in us
40 * @cs_change_delay: SPI delay between CS changes in us
41 * @glob_cmd_reg: Register address of the GLOB_CMD register
42 * @msc_ctrl_reg: Register address of the MSC_CTRL register
43 * @diag_stat_reg: Register address of the DIAG_STAT register
44 * @status_error_msgs: Array of error messgaes
45 * @status_error_mask:
46 * @timeouts: Chip specific delays
35 */
36struct adis_data {
37 unsigned int read_delay;
38 unsigned int write_delay;
39 unsigned int cs_change_delay;
40
41 unsigned int glob_cmd_reg;
42 unsigned int msc_ctrl_reg;
43 unsigned int diag_stat_reg;
44
45 unsigned int self_test_mask;
46 bool self_test_no_autoclear;
47 unsigned int startup_delay;
47 */
48struct adis_data {
49 unsigned int read_delay;
50 unsigned int write_delay;
51 unsigned int cs_change_delay;
52
53 unsigned int glob_cmd_reg;
54 unsigned int msc_ctrl_reg;
55 unsigned int diag_stat_reg;
56
57 unsigned int self_test_mask;
58 bool self_test_no_autoclear;
59 unsigned int startup_delay;
60 const struct adis_timeout *timeouts;
48
49 const char * const *status_error_msgs;
50 unsigned int status_error_mask;
51
52 int (*enable_irq)(struct adis *adis, bool enable);
53
54 bool has_paging;
55};
56
57struct adis {
58 struct spi_device *spi;
59 struct iio_trigger *trig;
60
61 const struct adis_data *data;
62 struct adis_burst *burst;
63
61
62 const char * const *status_error_msgs;
63 unsigned int status_error_mask;
64
65 int (*enable_irq)(struct adis *adis, bool enable);
66
67 bool has_paging;
68};
69
70struct adis {
71 struct spi_device *spi;
72 struct iio_trigger *trig;
73
74 const struct adis_data *data;
75 struct adis_burst *burst;
76
64 struct mutex txrx_lock;
77 struct mutex state_lock;
65 struct spi_message msg;
66 struct spi_transfer *xfer;
67 unsigned int current_page;
68 void *buffer;
69
70 uint8_t tx[10] ____cacheline_aligned;
71 uint8_t rx[4];
72};
73
74int adis_init(struct adis *adis, struct iio_dev *indio_dev,
75 struct spi_device *spi, const struct adis_data *data);
78 struct spi_message msg;
79 struct spi_transfer *xfer;
80 unsigned int current_page;
81 void *buffer;
82
83 uint8_t tx[10] ____cacheline_aligned;
84 uint8_t rx[4];
85};
86
87int adis_init(struct adis *adis, struct iio_dev *indio_dev,
88 struct spi_device *spi, const struct adis_data *data);
76int adis_reset(struct adis *adis);
89int __adis_reset(struct adis *adis);
77
90
78int adis_write_reg(struct adis *adis, unsigned int reg,
91/**
92 * adis_reset() - Reset the device
93 * @adis: The adis device
94 *
95 * Returns 0 on success, a negative error code otherwise
96 */
97static inline int adis_reset(struct adis *adis)
98{
99 int ret;
100
101 mutex_lock(&adis->state_lock);
102 ret = __adis_reset(adis);
103 mutex_unlock(&adis->state_lock);
104
105 return ret;
106}
107
108int __adis_write_reg(struct adis *adis, unsigned int reg,
79 unsigned int val, unsigned int size);
109 unsigned int val, unsigned int size);
80int adis_read_reg(struct adis *adis, unsigned int reg,
110int __adis_read_reg(struct adis *adis, unsigned int reg,
81 unsigned int *val, unsigned int size);
82
83/**
111 unsigned int *val, unsigned int size);
112
113/**
114 * __adis_write_reg_8() - Write single byte to a register (unlocked)
115 * @adis: The adis device
116 * @reg: The address of the register to be written
117 * @value: The value to write
118 */
119static inline int __adis_write_reg_8(struct adis *adis, unsigned int reg,
120 uint8_t val)
121{
122 return __adis_write_reg(adis, reg, val, 1);
123}
124
125/**
126 * __adis_write_reg_16() - Write 2 bytes to a pair of registers (unlocked)
127 * @adis: The adis device
128 * @reg: The address of the lower of the two registers
129 * @value: Value to be written
130 */
131static inline int __adis_write_reg_16(struct adis *adis, unsigned int reg,
132 uint16_t val)
133{
134 return __adis_write_reg(adis, reg, val, 2);
135}
136
137/**
138 * __adis_write_reg_32() - write 4 bytes to four registers (unlocked)
139 * @adis: The adis device
140 * @reg: The address of the lower of the four register
141 * @value: Value to be written
142 */
143static inline int __adis_write_reg_32(struct adis *adis, unsigned int reg,
144 uint32_t val)
145{
146 return __adis_write_reg(adis, reg, val, 4);
147}
148
149/**
150 * __adis_read_reg_16() - read 2 bytes from a 16-bit register (unlocked)
151 * @adis: The adis device
152 * @reg: The address of the lower of the two registers
153 * @val: The value read back from the device
154 */
155static inline int __adis_read_reg_16(struct adis *adis, unsigned int reg,
156 uint16_t *val)
157{
158 unsigned int tmp;
159 int ret;
160
161 ret = __adis_read_reg(adis, reg, &tmp, 2);
162 if (ret == 0)
163 *val = tmp;
164
165 return ret;
166}
167
168/**
169 * __adis_read_reg_32() - read 4 bytes from a 32-bit register (unlocked)
170 * @adis: The adis device
171 * @reg: The address of the lower of the two registers
172 * @val: The value read back from the device
173 */
174static inline int __adis_read_reg_32(struct adis *adis, unsigned int reg,
175 uint32_t *val)
176{
177 unsigned int tmp;
178 int ret;
179
180 ret = __adis_read_reg(adis, reg, &tmp, 4);
181 if (ret == 0)
182 *val = tmp;
183
184 return ret;
185}
186
187/**
188 * adis_write_reg() - write N bytes to register
189 * @adis: The adis device
190 * @reg: The address of the lower of the two registers
191 * @value: The value to write to device (up to 4 bytes)
192 * @size: The size of the @value (in bytes)
193 */
194static inline int adis_write_reg(struct adis *adis, unsigned int reg,
195 unsigned int val, unsigned int size)
196{
197 int ret;
198
199 mutex_lock(&adis->state_lock);
200 ret = __adis_write_reg(adis, reg, val, size);
201 mutex_unlock(&adis->state_lock);
202
203 return ret;
204}
205
206/**
207 * adis_read_reg() - read N bytes from register
208 * @adis: The adis device
209 * @reg: The address of the lower of the two registers
210 * @val: The value read back from the device
211 * @size: The size of the @val buffer
212 */
213static int adis_read_reg(struct adis *adis, unsigned int reg,
214 unsigned int *val, unsigned int size)
215{
216 int ret;
217
218 mutex_lock(&adis->state_lock);
219 ret = __adis_read_reg(adis, reg, val, size);
220 mutex_unlock(&adis->state_lock);
221
222 return ret;
223}
224
225/**
84 * adis_write_reg_8() - Write single byte to a register
85 * @adis: The adis device
86 * @reg: The address of the register to be written
87 * @value: The value to write
88 */
89static inline int adis_write_reg_8(struct adis *adis, unsigned int reg,
90 uint8_t val)
91{

--- 58 unchanged lines hidden (view full) ---

150 ret = adis_read_reg(adis, reg, &tmp, 4);
151 if (ret == 0)
152 *val = tmp;
153
154 return ret;
155}
156
157int adis_enable_irq(struct adis *adis, bool enable);
226 * adis_write_reg_8() - Write single byte to a register
227 * @adis: The adis device
228 * @reg: The address of the register to be written
229 * @value: The value to write
230 */
231static inline int adis_write_reg_8(struct adis *adis, unsigned int reg,
232 uint8_t val)
233{

--- 58 unchanged lines hidden (view full) ---

292 ret = adis_read_reg(adis, reg, &tmp, 4);
293 if (ret == 0)
294 *val = tmp;
295
296 return ret;
297}
298
299int adis_enable_irq(struct adis *adis, bool enable);
158int adis_check_status(struct adis *adis);
300int __adis_check_status(struct adis *adis);
159
301
302static inline int adis_check_status(struct adis *adis)
303{
304 int ret;
305
306 mutex_lock(&adis->state_lock);
307 ret = __adis_check_status(adis);
308 mutex_unlock(&adis->state_lock);
309
310 return ret;
311}
312
160int adis_initial_startup(struct adis *adis);
161
162int adis_single_conversion(struct iio_dev *indio_dev,
163 const struct iio_chan_spec *chan, unsigned int error_mask,
164 int *val);
165
166#define ADIS_VOLTAGE_CHAN(addr, si, chan, name, info_all, bits) { \
167 .type = IIO_VOLTAGE, \

--- 134 unchanged lines hidden ---
313int adis_initial_startup(struct adis *adis);
314
315int adis_single_conversion(struct iio_dev *indio_dev,
316 const struct iio_chan_spec *chan, unsigned int error_mask,
317 int *val);
318
319#define ADIS_VOLTAGE_CHAN(addr, si, chan, name, info_all, bits) { \
320 .type = IIO_VOLTAGE, \

--- 134 unchanged lines hidden ---