2 * Common library for ADIS16XXX devices
4 * Copyright 2012 Analog Devices Inc.
5 * Author: Lars-Peter Clausen <lars@metafoo.de>
7 * Licensed under the GPL-2 or later.
10 #ifndef __IIO_ADIS_H__
11 #define __IIO_ADIS_H__
13 #include <linux/spi/spi.h>
14 #include <linux/interrupt.h>
15 #include <linux/iio/types.h>
17 #define ADIS_WRITE_REG(reg) ((0x80 | (reg)))
18 #define ADIS_READ_REG(reg) ((reg) & 0x7f)
20 #define ADIS_PAGE_SIZE 0x80
21 #define ADIS_REG_PAGE_ID 0x00
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 * @glob_cmd_reg: Register address of the GLOB_CMD register
30 * @msc_ctrl_reg: Register address of the MSC_CTRL register
31 * @diag_stat_reg: Register address of the DIAG_STAT register
32 * @status_error_msgs: Array of error messgaes
36 unsigned int read_delay
;
37 unsigned int write_delay
;
39 unsigned int glob_cmd_reg
;
40 unsigned int msc_ctrl_reg
;
41 unsigned int diag_stat_reg
;
43 unsigned int self_test_mask
;
44 unsigned int startup_delay
;
46 const char * const *status_error_msgs
;
47 unsigned int status_error_mask
;
49 int (*enable_irq
)(struct adis
*adis
, bool enable
);
55 struct spi_device
*spi
;
56 struct iio_trigger
*trig
;
58 const struct adis_data
*data
;
60 struct mutex txrx_lock
;
61 struct spi_message msg
;
62 struct spi_transfer
*xfer
;
63 unsigned int current_page
;
66 uint8_t tx
[10] ____cacheline_aligned
;
70 int adis_init(struct adis
*adis
, struct iio_dev
*indio_dev
,
71 struct spi_device
*spi
, const struct adis_data
*data
);
72 int adis_reset(struct adis
*adis
);
74 int adis_write_reg(struct adis
*adis
, unsigned int reg
,
75 unsigned int val
, unsigned int size
);
76 int adis_read_reg(struct adis
*adis
, unsigned int reg
,
77 unsigned int *val
, unsigned int size
);
80 * adis_write_reg_8() - Write single byte to a register
81 * @adis: The adis device
82 * @reg: The address of the register to be written
83 * @value: The value to write
85 static inline int adis_write_reg_8(struct adis
*adis
, unsigned int reg
,
88 return adis_write_reg(adis
, reg
, val
, 1);
92 * adis_write_reg_16() - Write 2 bytes to a pair of registers
93 * @adis: The adis device
94 * @reg: The address of the lower of the two registers
95 * @value: Value to be written
97 static inline int adis_write_reg_16(struct adis
*adis
, unsigned int reg
,
100 return adis_write_reg(adis
, reg
, val
, 2);
104 * adis_write_reg_32() - write 4 bytes to four registers
105 * @adis: The adis device
106 * @reg: The address of the lower of the four register
107 * @value: Value to be written
109 static inline int adis_write_reg_32(struct adis
*adis
, unsigned int reg
,
112 return adis_write_reg(adis
, reg
, val
, 4);
116 * adis_read_reg_16() - read 2 bytes from a 16-bit register
117 * @adis: The adis device
118 * @reg: The address of the lower of the two registers
119 * @val: The value read back from the device
121 static inline int adis_read_reg_16(struct adis
*adis
, unsigned int reg
,
127 ret
= adis_read_reg(adis
, reg
, &tmp
, 2);
134 * adis_read_reg_32() - read 4 bytes from a 32-bit register
135 * @adis: The adis device
136 * @reg: The address of the lower of the two registers
137 * @val: The value read back from the device
139 static inline int adis_read_reg_32(struct adis
*adis
, unsigned int reg
,
145 ret
= adis_read_reg(adis
, reg
, &tmp
, 4);
151 int adis_enable_irq(struct adis
*adis
, bool enable
);
152 int adis_check_status(struct adis
*adis
);
154 int adis_initial_startup(struct adis
*adis
);
156 int adis_single_conversion(struct iio_dev
*indio_dev
,
157 const struct iio_chan_spec
*chan
, unsigned int error_mask
,
160 #define ADIS_VOLTAGE_CHAN(addr, si, chan, name, bits) { \
161 .type = IIO_VOLTAGE, \
164 .extend_name = name, \
165 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
166 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
168 .scan_index = (si), \
171 .realbits = (bits), \
173 .endianness = IIO_BE, \
177 #define ADIS_SUPPLY_CHAN(addr, si, bits) \
178 ADIS_VOLTAGE_CHAN(addr, si, 0, "supply", bits)
180 #define ADIS_AUX_ADC_CHAN(addr, si, bits) \
181 ADIS_VOLTAGE_CHAN(addr, si, 1, NULL, bits)
183 #define ADIS_TEMP_CHAN(addr, si, bits) { \
187 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
188 IIO_CHAN_INFO_SCALE_SEPARATE_BIT | \
189 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, \
191 .scan_index = (si), \
194 .realbits = (bits), \
196 .endianness = IIO_BE, \
200 #define ADIS_MOD_CHAN(_type, mod, addr, si, info, bits) { \
203 .channel2 = IIO_MOD_ ## mod, \
204 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
205 IIO_CHAN_INFO_SCALE_SHARED_BIT | \
208 .scan_index = (si), \
211 .realbits = (bits), \
213 .endianness = IIO_BE, \
217 #define ADIS_ACCEL_CHAN(mod, addr, si, info, bits) \
218 ADIS_MOD_CHAN(IIO_ACCEL, mod, addr, si, info, bits)
220 #define ADIS_GYRO_CHAN(mod, addr, si, info, bits) \
221 ADIS_MOD_CHAN(IIO_ANGL_VEL, mod, addr, si, info, bits)
223 #define ADIS_INCLI_CHAN(mod, addr, si, info, bits) \
224 ADIS_MOD_CHAN(IIO_INCLI, mod, addr, si, info, bits)
226 #define ADIS_ROT_CHAN(mod, addr, si, info, bits) \
227 ADIS_MOD_CHAN(IIO_ROT, mod, addr, si, info, bits)
229 #ifdef CONFIG_IIO_ADIS_LIB_BUFFER
231 int adis_setup_buffer_and_trigger(struct adis
*adis
,
232 struct iio_dev
*indio_dev
, irqreturn_t (*trigger_handler
)(int, void *));
233 void adis_cleanup_buffer_and_trigger(struct adis
*adis
,
234 struct iio_dev
*indio_dev
);
236 int adis_probe_trigger(struct adis
*adis
, struct iio_dev
*indio_dev
);
237 void adis_remove_trigger(struct adis
*adis
);
239 int adis_update_scan_mode(struct iio_dev
*indio_dev
,
240 const unsigned long *scan_mask
);
242 #else /* CONFIG_IIO_BUFFER */
244 static inline int adis_setup_buffer_and_trigger(struct adis
*adis
,
245 struct iio_dev
*indio_dev
, irqreturn_t (*trigger_handler
)(int, void *))
250 static inline void adis_cleanup_buffer_and_trigger(struct adis
*adis
,
251 struct iio_dev
*indio_dev
)
255 static inline int adis_probe_trigger(struct adis
*adis
,
256 struct iio_dev
*indio_dev
)
261 static inline void adis_remove_trigger(struct adis
*adis
)
265 #define adis_update_scan_mode NULL
267 #endif /* CONFIG_IIO_BUFFER */
269 #ifdef CONFIG_DEBUG_FS
271 int adis_debugfs_reg_access(struct iio_dev
*indio_dev
,
272 unsigned int reg
, unsigned int writeval
, unsigned int *readval
);
276 #define adis_debugfs_reg_access NULL
This page took 0.039106 seconds and 5 git commands to generate.