]>
Commit | Line | Data |
---|---|---|
2c834b4d BS |
1 | #ifndef SPI_ADIS16240_H_ |
2 | #define SPI_ADIS16240_H_ | |
3 | ||
4 | #define ADIS16240_STARTUP_DELAY 220 /* ms */ | |
5 | ||
6 | #define ADIS16240_READ_REG(a) a | |
7 | #define ADIS16240_WRITE_REG(a) ((a) | 0x80) | |
8 | ||
9 | /* Flash memory write count */ | |
10 | #define ADIS16240_FLASH_CNT 0x00 | |
11 | /* Output, power supply */ | |
12 | #define ADIS16240_SUPPLY_OUT 0x02 | |
13 | /* Output, x-axis accelerometer */ | |
14 | #define ADIS16240_XACCL_OUT 0x04 | |
15 | /* Output, y-axis accelerometer */ | |
16 | #define ADIS16240_YACCL_OUT 0x06 | |
17 | /* Output, z-axis accelerometer */ | |
18 | #define ADIS16240_ZACCL_OUT 0x08 | |
19 | /* Output, auxiliary ADC input */ | |
20 | #define ADIS16240_AUX_ADC 0x0A | |
21 | /* Output, temperature */ | |
22 | #define ADIS16240_TEMP_OUT 0x0C | |
23 | /* Output, x-axis acceleration peak */ | |
24 | #define ADIS16240_XPEAK_OUT 0x0E | |
25 | /* Output, y-axis acceleration peak */ | |
26 | #define ADIS16240_YPEAK_OUT 0x10 | |
27 | /* Output, z-axis acceleration peak */ | |
28 | #define ADIS16240_ZPEAK_OUT 0x12 | |
29 | /* Output, sum-of-squares acceleration peak */ | |
30 | #define ADIS16240_XYZPEAK_OUT 0x14 | |
31 | /* Output, Capture Buffer 1, X and Y acceleration */ | |
32 | #define ADIS16240_CAPT_BUF1 0x16 | |
33 | /* Output, Capture Buffer 2, Z acceleration */ | |
34 | #define ADIS16240_CAPT_BUF2 0x18 | |
35 | /* Diagnostic, error flags */ | |
36 | #define ADIS16240_DIAG_STAT 0x1A | |
37 | /* Diagnostic, event counter */ | |
38 | #define ADIS16240_EVNT_CNTR 0x1C | |
39 | /* Diagnostic, check sum value from firmware test */ | |
40 | #define ADIS16240_CHK_SUM 0x1E | |
41 | /* Calibration, x-axis acceleration offset adjustment */ | |
42 | #define ADIS16240_XACCL_OFF 0x20 | |
43 | /* Calibration, y-axis acceleration offset adjustment */ | |
44 | #define ADIS16240_YACCL_OFF 0x22 | |
45 | /* Calibration, z-axis acceleration offset adjustment */ | |
46 | #define ADIS16240_ZACCL_OFF 0x24 | |
47 | /* Clock, hour and minute */ | |
48 | #define ADIS16240_CLK_TIME 0x2E | |
49 | /* Clock, month and day */ | |
50 | #define ADIS16240_CLK_DATE 0x30 | |
51 | /* Clock, year */ | |
52 | #define ADIS16240_CLK_YEAR 0x32 | |
53 | /* Wake-up setting, hour and minute */ | |
54 | #define ADIS16240_WAKE_TIME 0x34 | |
55 | /* Wake-up setting, month and day */ | |
56 | #define ADIS16240_WAKE_DATE 0x36 | |
57 | /* Alarm 1 amplitude threshold */ | |
58 | #define ADIS16240_ALM_MAG1 0x38 | |
59 | /* Alarm 2 amplitude threshold */ | |
60 | #define ADIS16240_ALM_MAG2 0x3A | |
61 | /* Alarm control */ | |
62 | #define ADIS16240_ALM_CTRL 0x3C | |
63 | /* Capture, external trigger control */ | |
64 | #define ADIS16240_XTRIG_CTRL 0x3E | |
65 | /* Capture, address pointer */ | |
66 | #define ADIS16240_CAPT_PNTR 0x40 | |
67 | /* Capture, configuration and control */ | |
68 | #define ADIS16240_CAPT_CTRL 0x42 | |
69 | /* General-purpose digital input/output control */ | |
70 | #define ADIS16240_GPIO_CTRL 0x44 | |
71 | /* Miscellaneous control */ | |
72 | #define ADIS16240_MSC_CTRL 0x46 | |
73 | /* Internal sample period (rate) control */ | |
74 | #define ADIS16240_SMPL_PRD 0x48 | |
75 | /* System command */ | |
76 | #define ADIS16240_GLOB_CMD 0x4A | |
77 | ||
78 | #define ADIS16240_OUTPUTS 6 | |
79 | ||
80 | /* MSC_CTRL */ | |
81 | /* Enables sum-of-squares output (XYZPEAK_OUT) */ | |
82 | #define ADIS16240_MSC_CTRL_XYZPEAK_OUT_EN (1 << 15) | |
83 | /* Enables peak tracking output (XPEAK_OUT, YPEAK_OUT, and ZPEAK_OUT) */ | |
84 | #define ADIS16240_MSC_CTRL_X_Y_ZPEAK_OUT_EN (1 << 14) | |
85 | /* Self-test enable: 1 = apply electrostatic force, 0 = disabled */ | |
86 | #define ADIS16240_MSC_CTRL_SELF_TEST_EN (1 << 8) | |
87 | /* Data-ready enable: 1 = enabled, 0 = disabled */ | |
88 | #define ADIS16240_MSC_CTRL_DATA_RDY_EN (1 << 2) | |
89 | /* Data-ready polarity: 1 = active high, 0 = active low */ | |
90 | #define ADIS16240_MSC_CTRL_ACTIVE_HIGH (1 << 1) | |
91 | /* Data-ready line selection: 1 = DIO2, 0 = DIO1 */ | |
92 | #define ADIS16240_MSC_CTRL_DATA_RDY_DIO2 (1 << 0) | |
93 | ||
94 | /* DIAG_STAT */ | |
95 | /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */ | |
96 | #define ADIS16240_DIAG_STAT_ALARM2 (1<<9) | |
97 | /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */ | |
98 | #define ADIS16240_DIAG_STAT_ALARM1 (1<<8) | |
99 | /* Capture buffer full: 1 = capture buffer is full */ | |
100 | #define ADIS16240_DIAG_STAT_CPT_BUF_FUL (1<<7) | |
101 | /* Flash test, checksum flag: 1 = mismatch, 0 = match */ | |
102 | #define ADIS16240_DIAG_STAT_CHKSUM (1<<6) | |
103 | /* Power-on, self-test flag: 1 = failure, 0 = pass */ | |
104 | #define ADIS16240_DIAG_STAT_PWRON_FAIL (1<<5) | |
105 | /* Power-on self-test: 1 = in-progress, 0 = complete */ | |
106 | #define ADIS16240_DIAG_STAT_PWRON_BUSY (1<<4) | |
107 | /* SPI communications failure */ | |
108 | #define ADIS16240_DIAG_STAT_SPI_FAIL (1<<3) | |
109 | /* Flash update failure */ | |
110 | #define ADIS16240_DIAG_STAT_FLASH_UPT (1<<2) | |
111 | /* Power supply above 3.625 V */ | |
112 | #define ADIS16240_DIAG_STAT_POWER_HIGH (1<<1) | |
113 | /* Power supply below 3.15 V */ | |
114 | #define ADIS16240_DIAG_STAT_POWER_LOW (1<<0) | |
115 | ||
116 | /* GLOB_CMD */ | |
117 | #define ADIS16240_GLOB_CMD_RESUME (1<<8) | |
118 | #define ADIS16240_GLOB_CMD_SW_RESET (1<<7) | |
119 | #define ADIS16240_GLOB_CMD_STANDBY (1<<2) | |
120 | ||
121 | #define ADIS16240_ERROR_ACTIVE (1<<14) | |
122 | ||
123 | #define ADIS16240_MAX_TX 24 | |
124 | #define ADIS16240_MAX_RX 24 | |
125 | ||
126 | /** | |
127 | * struct adis16240_state - device instance specific data | |
128 | * @us: actual spi_device | |
129 | * @work_trigger_to_ring: bh for triggered event handling | |
2c834b4d BS |
130 | * @inter: used to check if new interrupt has been triggered |
131 | * @last_timestamp: passing timestamp from th to bh of interrupt handler | |
132 | * @indio_dev: industrial I/O device structure | |
133 | * @trig: data ready trigger registered with iio | |
134 | * @tx: transmit buffer | |
25985edc | 135 | * @rx: receive buffer |
2c834b4d BS |
136 | * @buf_lock: mutex to protect tx and rx |
137 | **/ | |
138 | struct adis16240_state { | |
139 | struct spi_device *us; | |
140 | struct work_struct work_trigger_to_ring; | |
2c834b4d BS |
141 | s64 last_timestamp; |
142 | struct iio_dev *indio_dev; | |
143 | struct iio_trigger *trig; | |
144 | u8 *tx; | |
145 | u8 *rx; | |
146 | struct mutex buf_lock; | |
147 | }; | |
148 | ||
149 | int adis16240_set_irq(struct device *dev, bool enable); | |
150 | ||
151 | #ifdef CONFIG_IIO_RING_BUFFER | |
152 | /* At the moment triggers are only used for ring buffer | |
153 | * filling. This may change! | |
154 | */ | |
155 | ||
69584bd6 JC |
156 | #define ADIS16240_SCAN_SUPPLY 0 |
157 | #define ADIS16240_SCAN_ACC_X 1 | |
158 | #define ADIS16240_SCAN_ACC_Y 2 | |
159 | #define ADIS16240_SCAN_ACC_Z 3 | |
160 | #define ADIS16240_SCAN_AUX_ADC 4 | |
161 | #define ADIS16240_SCAN_TEMP 5 | |
2c834b4d BS |
162 | |
163 | void adis16240_remove_trigger(struct iio_dev *indio_dev); | |
164 | int adis16240_probe_trigger(struct iio_dev *indio_dev); | |
165 | ||
166 | ssize_t adis16240_read_data_from_ring(struct device *dev, | |
167 | struct device_attribute *attr, | |
168 | char *buf); | |
169 | ||
170 | ||
171 | int adis16240_configure_ring(struct iio_dev *indio_dev); | |
172 | void adis16240_unconfigure_ring(struct iio_dev *indio_dev); | |
173 | ||
2c834b4d BS |
174 | #else /* CONFIG_IIO_RING_BUFFER */ |
175 | ||
176 | static inline void adis16240_remove_trigger(struct iio_dev *indio_dev) | |
177 | { | |
178 | } | |
179 | ||
180 | static inline int adis16240_probe_trigger(struct iio_dev *indio_dev) | |
181 | { | |
182 | return 0; | |
183 | } | |
184 | ||
185 | static inline ssize_t | |
186 | adis16240_read_data_from_ring(struct device *dev, | |
187 | struct device_attribute *attr, | |
188 | char *buf) | |
189 | { | |
190 | return 0; | |
191 | } | |
192 | ||
193 | static int adis16240_configure_ring(struct iio_dev *indio_dev) | |
194 | { | |
195 | return 0; | |
196 | } | |
197 | ||
198 | static inline void adis16240_unconfigure_ring(struct iio_dev *indio_dev) | |
199 | { | |
200 | } | |
201 | ||
2c834b4d BS |
202 | #endif /* CONFIG_IIO_RING_BUFFER */ |
203 | #endif /* SPI_ADIS16240_H_ */ |