unify {de,}mangle_poll(), get rid of kernel-side POLL...
[cris-mirror.git] / include / linux / iio / imu / adis.h
blob360da7d18a3d011e630bc0fff1790485150ca78b
1 /*
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.
8 */
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
23 struct adis;
25 /**
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
33 * @status_error_mask:
35 struct adis_data {
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 bool self_test_no_autoclear;
45 unsigned int startup_delay;
47 const char * const *status_error_msgs;
48 unsigned int status_error_mask;
50 int (*enable_irq)(struct adis *adis, bool enable);
52 bool has_paging;
55 struct adis {
56 struct spi_device *spi;
57 struct iio_trigger *trig;
59 const struct adis_data *data;
61 struct mutex txrx_lock;
62 struct spi_message msg;
63 struct spi_transfer *xfer;
64 unsigned int current_page;
65 void *buffer;
67 uint8_t tx[10] ____cacheline_aligned;
68 uint8_t rx[4];
71 int adis_init(struct adis *adis, struct iio_dev *indio_dev,
72 struct spi_device *spi, const struct adis_data *data);
73 int adis_reset(struct adis *adis);
75 int adis_write_reg(struct adis *adis, unsigned int reg,
76 unsigned int val, unsigned int size);
77 int adis_read_reg(struct adis *adis, unsigned int reg,
78 unsigned int *val, unsigned int size);
80 /**
81 * adis_write_reg_8() - Write single byte to a register
82 * @adis: The adis device
83 * @reg: The address of the register to be written
84 * @value: The value to write
86 static inline int adis_write_reg_8(struct adis *adis, unsigned int reg,
87 uint8_t val)
89 return adis_write_reg(adis, reg, val, 1);
92 /**
93 * adis_write_reg_16() - Write 2 bytes to a pair of registers
94 * @adis: The adis device
95 * @reg: The address of the lower of the two registers
96 * @value: Value to be written
98 static inline int adis_write_reg_16(struct adis *adis, unsigned int reg,
99 uint16_t val)
101 return adis_write_reg(adis, reg, val, 2);
105 * adis_write_reg_32() - write 4 bytes to four registers
106 * @adis: The adis device
107 * @reg: The address of the lower of the four register
108 * @value: Value to be written
110 static inline int adis_write_reg_32(struct adis *adis, unsigned int reg,
111 uint32_t val)
113 return adis_write_reg(adis, reg, val, 4);
117 * adis_read_reg_16() - read 2 bytes from a 16-bit register
118 * @adis: The adis device
119 * @reg: The address of the lower of the two registers
120 * @val: The value read back from the device
122 static inline int adis_read_reg_16(struct adis *adis, unsigned int reg,
123 uint16_t *val)
125 unsigned int tmp;
126 int ret;
128 ret = adis_read_reg(adis, reg, &tmp, 2);
129 *val = tmp;
131 return ret;
135 * adis_read_reg_32() - read 4 bytes from a 32-bit register
136 * @adis: The adis device
137 * @reg: The address of the lower of the two registers
138 * @val: The value read back from the device
140 static inline int adis_read_reg_32(struct adis *adis, unsigned int reg,
141 uint32_t *val)
143 unsigned int tmp;
144 int ret;
146 ret = adis_read_reg(adis, reg, &tmp, 4);
147 *val = tmp;
149 return ret;
152 int adis_enable_irq(struct adis *adis, bool enable);
153 int adis_check_status(struct adis *adis);
155 int adis_initial_startup(struct adis *adis);
157 int adis_single_conversion(struct iio_dev *indio_dev,
158 const struct iio_chan_spec *chan, unsigned int error_mask,
159 int *val);
161 #define ADIS_VOLTAGE_CHAN(addr, si, chan, name, info_all, bits) { \
162 .type = IIO_VOLTAGE, \
163 .indexed = 1, \
164 .channel = (chan), \
165 .extend_name = name, \
166 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
167 BIT(IIO_CHAN_INFO_SCALE), \
168 .info_mask_shared_by_all = info_all, \
169 .address = (addr), \
170 .scan_index = (si), \
171 .scan_type = { \
172 .sign = 'u', \
173 .realbits = (bits), \
174 .storagebits = 16, \
175 .endianness = IIO_BE, \
176 }, \
179 #define ADIS_SUPPLY_CHAN(addr, si, info_all, bits) \
180 ADIS_VOLTAGE_CHAN(addr, si, 0, "supply", info_all, bits)
182 #define ADIS_AUX_ADC_CHAN(addr, si, info_all, bits) \
183 ADIS_VOLTAGE_CHAN(addr, si, 1, NULL, info_all, bits)
185 #define ADIS_TEMP_CHAN(addr, si, info_all, bits) { \
186 .type = IIO_TEMP, \
187 .indexed = 1, \
188 .channel = 0, \
189 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
190 BIT(IIO_CHAN_INFO_SCALE) | \
191 BIT(IIO_CHAN_INFO_OFFSET), \
192 .info_mask_shared_by_all = info_all, \
193 .address = (addr), \
194 .scan_index = (si), \
195 .scan_type = { \
196 .sign = 'u', \
197 .realbits = (bits), \
198 .storagebits = 16, \
199 .endianness = IIO_BE, \
200 }, \
203 #define ADIS_MOD_CHAN(_type, mod, addr, si, info_sep, info_all, bits) { \
204 .type = (_type), \
205 .modified = 1, \
206 .channel2 = IIO_MOD_ ## mod, \
207 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
208 info_sep, \
209 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
210 .info_mask_shared_by_all = info_all, \
211 .address = (addr), \
212 .scan_index = (si), \
213 .scan_type = { \
214 .sign = 's', \
215 .realbits = (bits), \
216 .storagebits = 16, \
217 .endianness = IIO_BE, \
218 }, \
221 #define ADIS_ACCEL_CHAN(mod, addr, si, info_sep, info_all, bits) \
222 ADIS_MOD_CHAN(IIO_ACCEL, mod, addr, si, info_sep, info_all, bits)
224 #define ADIS_GYRO_CHAN(mod, addr, si, info_sep, info_all, bits) \
225 ADIS_MOD_CHAN(IIO_ANGL_VEL, mod, addr, si, info_sep, info_all, bits)
227 #define ADIS_INCLI_CHAN(mod, addr, si, info_sep, info_all, bits) \
228 ADIS_MOD_CHAN(IIO_INCLI, mod, addr, si, info_sep, info_all, bits)
230 #define ADIS_ROT_CHAN(mod, addr, si, info_sep, info_all, bits) \
231 ADIS_MOD_CHAN(IIO_ROT, mod, addr, si, info_sep, info_all, bits)
233 #ifdef CONFIG_IIO_ADIS_LIB_BUFFER
235 int adis_setup_buffer_and_trigger(struct adis *adis,
236 struct iio_dev *indio_dev, irqreturn_t (*trigger_handler)(int, void *));
237 void adis_cleanup_buffer_and_trigger(struct adis *adis,
238 struct iio_dev *indio_dev);
240 int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev);
241 void adis_remove_trigger(struct adis *adis);
243 int adis_update_scan_mode(struct iio_dev *indio_dev,
244 const unsigned long *scan_mask);
246 #else /* CONFIG_IIO_BUFFER */
248 static inline int adis_setup_buffer_and_trigger(struct adis *adis,
249 struct iio_dev *indio_dev, irqreturn_t (*trigger_handler)(int, void *))
251 return 0;
254 static inline void adis_cleanup_buffer_and_trigger(struct adis *adis,
255 struct iio_dev *indio_dev)
259 static inline int adis_probe_trigger(struct adis *adis,
260 struct iio_dev *indio_dev)
262 return 0;
265 static inline void adis_remove_trigger(struct adis *adis)
269 #define adis_update_scan_mode NULL
271 #endif /* CONFIG_IIO_BUFFER */
273 #ifdef CONFIG_DEBUG_FS
275 int adis_debugfs_reg_access(struct iio_dev *indio_dev,
276 unsigned int reg, unsigned int writeval, unsigned int *readval);
278 #else
280 #define adis_debugfs_reg_access NULL
282 #endif
284 #endif