iio:imu:adis: Add paging support
[linux-2.6.git] / include / linux / iio / imu / adis.h
blobe82cd0827e91645a7ff5c79190b64e560a54ef6a
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 /**
24 * struct adis_data - ADIS chip variant specific data
25 * @read_delay: SPI delay for read operations in us
26 * @write_delay: SPI delay for write operations in us
27 * @glob_cmd_reg: Register address of the GLOB_CMD register
28 * @msc_ctrl_reg: Register address of the MSC_CTRL register
29 * @diag_stat_reg: Register address of the DIAG_STAT register
30 * @status_error_msgs: Array of error messgaes
31 * @status_error_mask:
33 struct adis_data {
34 unsigned int read_delay;
35 unsigned int write_delay;
37 unsigned int glob_cmd_reg;
38 unsigned int msc_ctrl_reg;
39 unsigned int diag_stat_reg;
41 unsigned int self_test_mask;
42 unsigned int startup_delay;
44 const char * const *status_error_msgs;
45 unsigned int status_error_mask;
47 bool has_paging;
50 struct adis {
51 struct spi_device *spi;
52 struct iio_trigger *trig;
54 const struct adis_data *data;
56 struct mutex txrx_lock;
57 struct spi_message msg;
58 struct spi_transfer *xfer;
59 unsigned int current_page;
60 void *buffer;
62 uint8_t tx[10] ____cacheline_aligned;
63 uint8_t rx[4];
66 int adis_init(struct adis *adis, struct iio_dev *indio_dev,
67 struct spi_device *spi, const struct adis_data *data);
68 int adis_reset(struct adis *adis);
70 int adis_write_reg(struct adis *adis, unsigned int reg,
71 unsigned int val, unsigned int size);
72 int adis_read_reg(struct adis *adis, unsigned int reg,
73 unsigned int *val, unsigned int size);
75 /**
76 * adis_write_reg_8() - Write single byte to a register
77 * @adis: The adis device
78 * @reg: The address of the register to be written
79 * @value: The value to write
81 static inline int adis_write_reg_8(struct adis *adis, unsigned int reg,
82 uint8_t val)
84 return adis_write_reg(adis, reg, val, 1);
87 /**
88 * adis_write_reg_16() - Write 2 bytes to a pair of registers
89 * @adis: The adis device
90 * @reg: The address of the lower of the two registers
91 * @value: Value to be written
93 static inline int adis_write_reg_16(struct adis *adis, unsigned int reg,
94 uint16_t val)
96 return adis_write_reg(adis, reg, val, 2);
99 /**
100 * adis_write_reg_32() - write 4 bytes to four registers
101 * @adis: The adis device
102 * @reg: The address of the lower of the four register
103 * @value: Value to be written
105 static inline int adis_write_reg_32(struct adis *adis, unsigned int reg,
106 uint32_t val)
108 return adis_write_reg(adis, reg, val, 4);
112 * adis_read_reg_16() - read 2 bytes from a 16-bit register
113 * @adis: The adis device
114 * @reg: The address of the lower of the two registers
115 * @val: The value read back from the device
117 static inline int adis_read_reg_16(struct adis *adis, unsigned int reg,
118 uint16_t *val)
120 unsigned int tmp;
121 int ret;
123 ret = adis_read_reg(adis, reg, &tmp, 2);
124 *val = tmp;
126 return ret;
130 * adis_read_reg_32() - read 4 bytes from a 32-bit register
131 * @adis: The adis device
132 * @reg: The address of the lower of the two registers
133 * @val: The value read back from the device
135 static inline int adis_read_reg_32(struct adis *adis, unsigned int reg,
136 uint32_t *val)
138 unsigned int tmp;
139 int ret;
141 ret = adis_read_reg(adis, reg, &tmp, 4);
142 *val = tmp;
144 return ret;
147 int adis_enable_irq(struct adis *adis, bool enable);
148 int adis_check_status(struct adis *adis);
150 int adis_initial_startup(struct adis *adis);
152 int adis_single_conversion(struct iio_dev *indio_dev,
153 const struct iio_chan_spec *chan, unsigned int error_mask,
154 int *val);
156 #define ADIS_VOLTAGE_CHAN(addr, si, chan, name, bits) { \
157 .type = IIO_VOLTAGE, \
158 .indexed = 1, \
159 .channel = (chan), \
160 .extend_name = name, \
161 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
162 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
163 .address = (addr), \
164 .scan_index = (si), \
165 .scan_type = { \
166 .sign = 'u', \
167 .realbits = (bits), \
168 .storagebits = 16, \
169 .endianness = IIO_BE, \
170 }, \
173 #define ADIS_SUPPLY_CHAN(addr, si, bits) \
174 ADIS_VOLTAGE_CHAN(addr, si, 0, "supply", bits)
176 #define ADIS_AUX_ADC_CHAN(addr, si, bits) \
177 ADIS_VOLTAGE_CHAN(addr, si, 1, NULL, bits)
179 #define ADIS_TEMP_CHAN(addr, si, bits) { \
180 .type = IIO_TEMP, \
181 .indexed = 1, \
182 .channel = 0, \
183 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
184 IIO_CHAN_INFO_SCALE_SEPARATE_BIT | \
185 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, \
186 .address = (addr), \
187 .scan_index = (si), \
188 .scan_type = { \
189 .sign = 'u', \
190 .realbits = (bits), \
191 .storagebits = 16, \
192 .endianness = IIO_BE, \
193 }, \
196 #define ADIS_MOD_CHAN(_type, mod, addr, si, info, bits) { \
197 .type = (_type), \
198 .modified = 1, \
199 .channel2 = IIO_MOD_ ## mod, \
200 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
201 IIO_CHAN_INFO_SCALE_SHARED_BIT | \
202 info, \
203 .address = (addr), \
204 .scan_index = (si), \
205 .scan_type = { \
206 .sign = 's', \
207 .realbits = (bits), \
208 .storagebits = 16, \
209 .endianness = IIO_BE, \
210 }, \
213 #define ADIS_ACCEL_CHAN(mod, addr, si, info, bits) \
214 ADIS_MOD_CHAN(IIO_ACCEL, mod, addr, si, info, bits)
216 #define ADIS_GYRO_CHAN(mod, addr, si, info, bits) \
217 ADIS_MOD_CHAN(IIO_ANGL_VEL, mod, addr, si, info, bits)
219 #define ADIS_INCLI_CHAN(mod, addr, si, info, bits) \
220 ADIS_MOD_CHAN(IIO_INCLI, mod, addr, si, info, bits)
222 #define ADIS_ROT_CHAN(mod, addr, si, info, bits) \
223 ADIS_MOD_CHAN(IIO_ROT, mod, addr, si, info, bits)
225 #ifdef CONFIG_IIO_ADIS_LIB_BUFFER
227 int adis_setup_buffer_and_trigger(struct adis *adis,
228 struct iio_dev *indio_dev, irqreturn_t (*trigger_handler)(int, void *));
229 void adis_cleanup_buffer_and_trigger(struct adis *adis,
230 struct iio_dev *indio_dev);
232 int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev);
233 void adis_remove_trigger(struct adis *adis);
235 int adis_update_scan_mode(struct iio_dev *indio_dev,
236 const unsigned long *scan_mask);
238 #else /* CONFIG_IIO_BUFFER */
240 static inline int adis_setup_buffer_and_trigger(struct adis *adis,
241 struct iio_dev *indio_dev, irqreturn_t (*trigger_handler)(int, void *))
243 return 0;
246 static inline void adis_cleanup_buffer_and_trigger(struct adis *adis,
247 struct iio_dev *indio_dev)
251 static inline int adis_probe_trigger(struct adis *adis,
252 struct iio_dev *indio_dev)
254 return 0;
257 static inline void adis_remove_trigger(struct adis *adis)
261 #define adis_update_scan_mode NULL
263 #endif /* CONFIG_IIO_BUFFER */
265 #ifdef CONFIG_DEBUG_FS
267 int adis_debugfs_reg_access(struct iio_dev *indio_dev,
268 unsigned int reg, unsigned int writeval, unsigned int *readval);
270 #else
272 #define adis_debugfs_reg_access NULL
274 #endif
276 #endif