Commit | Line | Data |
---|---|---|
1e3864e6 BS |
1 | #ifndef SPI_ADIS16300_H_ |
2 | #define SPI_ADIS16300_H_ | |
3 | ||
4 | #define ADIS16300_STARTUP_DELAY 220 /* ms */ | |
5 | ||
6 | #define ADIS16300_READ_REG(a) a | |
7 | #define ADIS16300_WRITE_REG(a) ((a) | 0x80) | |
8 | ||
9 | #define ADIS16300_FLASH_CNT 0x00 /* Flash memory write count */ | |
10 | #define ADIS16300_SUPPLY_OUT 0x02 /* Power supply measurement */ | |
11 | #define ADIS16300_XGYRO_OUT 0x04 /* X-axis gyroscope output */ | |
12 | #define ADIS16300_XACCL_OUT 0x0A /* X-axis accelerometer output */ | |
13 | #define ADIS16300_YACCL_OUT 0x0C /* Y-axis accelerometer output */ | |
14 | #define ADIS16300_ZACCL_OUT 0x0E /* Z-axis accelerometer output */ | |
15 | #define ADIS16300_TEMP_OUT 0x10 /* Temperature output */ | |
16 | #define ADIS16300_XINCLI_OUT 0x12 /* X-axis inclinometer output measurement */ | |
17 | #define ADIS16300_YINCLI_OUT 0x14 /* Y-axis inclinometer output measurement */ | |
18 | #define ADIS16300_AUX_ADC 0x16 /* Auxiliary ADC measurement */ | |
19 | ||
20 | /* Calibration parameters */ | |
21 | #define ADIS16300_XGYRO_OFF 0x1A /* X-axis gyroscope bias offset factor */ | |
22 | #define ADIS16300_XACCL_OFF 0x20 /* X-axis acceleration bias offset factor */ | |
23 | #define ADIS16300_YACCL_OFF 0x22 /* Y-axis acceleration bias offset factor */ | |
24 | #define ADIS16300_ZACCL_OFF 0x24 /* Z-axis acceleration bias offset factor */ | |
25 | ||
26 | #define ADIS16300_GPIO_CTRL 0x32 /* Auxiliary digital input/output control */ | |
27 | #define ADIS16300_MSC_CTRL 0x34 /* Miscellaneous control */ | |
28 | #define ADIS16300_SMPL_PRD 0x36 /* Internal sample period (rate) control */ | |
29 | #define ADIS16300_SENS_AVG 0x38 /* Dynamic range and digital filter control */ | |
30 | #define ADIS16300_SLP_CNT 0x3A /* Sleep mode control */ | |
31 | #define ADIS16300_DIAG_STAT 0x3C /* System status */ | |
32 | ||
33 | /* Alarm functions */ | |
34 | #define ADIS16300_GLOB_CMD 0x3E /* System command */ | |
35 | #define ADIS16300_ALM_MAG1 0x26 /* Alarm 1 amplitude threshold */ | |
36 | #define ADIS16300_ALM_MAG2 0x28 /* Alarm 2 amplitude threshold */ | |
37 | #define ADIS16300_ALM_SMPL1 0x2A /* Alarm 1 sample size */ | |
38 | #define ADIS16300_ALM_SMPL2 0x2C /* Alarm 2 sample size */ | |
39 | #define ADIS16300_ALM_CTRL 0x2E /* Alarm control */ | |
40 | #define ADIS16300_AUX_DAC 0x30 /* Auxiliary DAC data */ | |
41 | ||
42 | #define ADIS16300_ERROR_ACTIVE (1<<14) | |
43 | #define ADIS16300_NEW_DATA (1<<15) | |
44 | ||
45 | /* MSC_CTRL */ | |
46 | #define ADIS16300_MSC_CTRL_MEM_TEST (1<<11) | |
47 | #define ADIS16300_MSC_CTRL_INT_SELF_TEST (1<<10) | |
48 | #define ADIS16300_MSC_CTRL_NEG_SELF_TEST (1<<9) | |
49 | #define ADIS16300_MSC_CTRL_POS_SELF_TEST (1<<8) | |
50 | #define ADIS16300_MSC_CTRL_GYRO_BIAS (1<<7) | |
51 | #define ADIS16300_MSC_CTRL_ACCL_ALIGN (1<<6) | |
52 | #define ADIS16300_MSC_CTRL_DATA_RDY_EN (1<<2) | |
53 | #define ADIS16300_MSC_CTRL_DATA_RDY_POL_HIGH (1<<1) | |
54 | #define ADIS16300_MSC_CTRL_DATA_RDY_DIO2 (1<<0) | |
55 | ||
56 | /* SMPL_PRD */ | |
57 | #define ADIS16300_SMPL_PRD_TIME_BASE (1<<7) | |
58 | #define ADIS16300_SMPL_PRD_DIV_MASK 0x7F | |
59 | ||
60 | /* DIAG_STAT */ | |
61 | #define ADIS16300_DIAG_STAT_ZACCL_FAIL (1<<15) | |
62 | #define ADIS16300_DIAG_STAT_YACCL_FAIL (1<<14) | |
63 | #define ADIS16300_DIAG_STAT_XACCL_FAIL (1<<13) | |
64 | #define ADIS16300_DIAG_STAT_XGYRO_FAIL (1<<10) | |
65 | #define ADIS16300_DIAG_STAT_ALARM2 (1<<9) | |
66 | #define ADIS16300_DIAG_STAT_ALARM1 (1<<8) | |
67 | #define ADIS16300_DIAG_STAT_FLASH_CHK (1<<6) | |
68 | #define ADIS16300_DIAG_STAT_SELF_TEST (1<<5) | |
69 | #define ADIS16300_DIAG_STAT_OVERFLOW (1<<4) | |
70 | #define ADIS16300_DIAG_STAT_SPI_FAIL (1<<3) | |
71 | #define ADIS16300_DIAG_STAT_FLASH_UPT (1<<2) | |
72 | #define ADIS16300_DIAG_STAT_POWER_HIGH (1<<1) | |
73 | #define ADIS16300_DIAG_STAT_POWER_LOW (1<<0) | |
74 | ||
75 | /* GLOB_CMD */ | |
76 | #define ADIS16300_GLOB_CMD_SW_RESET (1<<7) | |
77 | #define ADIS16300_GLOB_CMD_P_AUTO_NULL (1<<4) | |
78 | #define ADIS16300_GLOB_CMD_FLASH_UPD (1<<3) | |
79 | #define ADIS16300_GLOB_CMD_DAC_LATCH (1<<2) | |
80 | #define ADIS16300_GLOB_CMD_FAC_CALIB (1<<1) | |
81 | #define ADIS16300_GLOB_CMD_AUTO_NULL (1<<0) | |
82 | ||
83 | /* SLP_CNT */ | |
84 | #define ADIS16300_SLP_CNT_POWER_OFF (1<<8) | |
85 | ||
86 | #define ADIS16300_MAX_TX 18 | |
87 | #define ADIS16300_MAX_RX 18 | |
88 | ||
89 | #define ADIS16300_SPI_SLOW (u32)(300 * 1000) | |
90 | #define ADIS16300_SPI_BURST (u32)(1000 * 1000) | |
91 | #define ADIS16300_SPI_FAST (u32)(2000 * 1000) | |
92 | ||
93 | /** | |
94 | * struct adis16300_state - device instance specific data | |
95 | * @us: actual spi_device | |
96 | * @work_trigger_to_ring: bh for triggered event handling | |
97 | * @work_cont_thresh: CLEAN | |
98 | * @inter: used to check if new interrupt has been triggered | |
99 | * @last_timestamp: passing timestamp from th to bh of interrupt handler | |
100 | * @indio_dev: industrial I/O device structure | |
101 | * @trig: data ready trigger registered with iio | |
102 | * @tx: transmit buffer | |
103 | * @rx: recieve buffer | |
104 | * @buf_lock: mutex to protect tx and rx | |
105 | **/ | |
106 | struct adis16300_state { | |
107 | struct spi_device *us; | |
108 | struct work_struct work_trigger_to_ring; | |
109 | struct iio_work_cont work_cont_thresh; | |
110 | s64 last_timestamp; | |
111 | struct iio_dev *indio_dev; | |
112 | struct iio_trigger *trig; | |
113 | u8 *tx; | |
114 | u8 *rx; | |
115 | struct mutex buf_lock; | |
116 | }; | |
117 | ||
1e3864e6 BS |
118 | int adis16300_set_irq(struct device *dev, bool enable); |
119 | ||
1e3864e6 BS |
120 | #ifdef CONFIG_IIO_RING_BUFFER |
121 | /* At the moment triggers are only used for ring buffer | |
122 | * filling. This may change! | |
123 | */ | |
124 | ||
125 | enum adis16300_scan { | |
126 | ADIS16300_SCAN_SUPPLY, | |
127 | ADIS16300_SCAN_GYRO_X, | |
128 | ADIS16300_SCAN_ACC_X, | |
129 | ADIS16300_SCAN_ACC_Y, | |
130 | ADIS16300_SCAN_ACC_Z, | |
131 | ADIS16300_SCAN_TEMP, | |
132 | ADIS16300_SCAN_ADC_0, | |
133 | ADIS16300_SCAN_INCLI_X, | |
134 | ADIS16300_SCAN_INCLI_Y, | |
135 | }; | |
136 | ||
137 | void adis16300_remove_trigger(struct iio_dev *indio_dev); | |
138 | int adis16300_probe_trigger(struct iio_dev *indio_dev); | |
139 | ||
140 | ssize_t adis16300_read_data_from_ring(struct device *dev, | |
141 | struct device_attribute *attr, | |
142 | char *buf); | |
143 | ||
144 | ||
145 | int adis16300_configure_ring(struct iio_dev *indio_dev); | |
146 | void adis16300_unconfigure_ring(struct iio_dev *indio_dev); | |
147 | ||
148 | int adis16300_initialize_ring(struct iio_ring_buffer *ring); | |
149 | void adis16300_uninitialize_ring(struct iio_ring_buffer *ring); | |
150 | #else /* CONFIG_IIO_RING_BUFFER */ | |
151 | ||
152 | static inline void adis16300_remove_trigger(struct iio_dev *indio_dev) | |
153 | { | |
154 | } | |
155 | ||
156 | static inline int adis16300_probe_trigger(struct iio_dev *indio_dev) | |
157 | { | |
158 | return 0; | |
159 | } | |
160 | ||
161 | static inline ssize_t | |
162 | adis16300_read_data_from_ring(struct device *dev, | |
163 | struct device_attribute *attr, | |
164 | char *buf) | |
165 | { | |
166 | return 0; | |
167 | } | |
168 | ||
169 | static int adis16300_configure_ring(struct iio_dev *indio_dev) | |
170 | { | |
171 | return 0; | |
172 | } | |
173 | ||
174 | static inline void adis16300_unconfigure_ring(struct iio_dev *indio_dev) | |
175 | { | |
176 | } | |
177 | ||
178 | static inline int adis16300_initialize_ring(struct iio_ring_buffer *ring) | |
179 | { | |
180 | return 0; | |
181 | } | |
182 | ||
183 | static inline void adis16300_uninitialize_ring(struct iio_ring_buffer *ring) | |
184 | { | |
185 | } | |
186 | ||
187 | #endif /* CONFIG_IIO_RING_BUFFER */ | |
188 | #endif /* SPI_ADIS16300_H_ */ |