staging: iio: adis16240 driver
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / iio / accel / adis16240.h
blobdcff43c75235a10343b10206162b095272791a6b
1 #ifndef SPI_ADIS16240_H_
2 #define SPI_ADIS16240_H_
4 #define ADIS16240_STARTUP_DELAY 220 /* ms */
6 #define ADIS16240_READ_REG(a) a
7 #define ADIS16240_WRITE_REG(a) ((a) | 0x80)
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
78 #define ADIS16240_OUTPUTS 6
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)
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)
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)
121 #define ADIS16240_ERROR_ACTIVE (1<<14)
123 #define ADIS16240_MAX_TX 24
124 #define ADIS16240_MAX_RX 24
127 * struct adis16240_state - device instance specific data
128 * @us: actual spi_device
129 * @work_trigger_to_ring: bh for triggered event handling
130 * @work_cont_thresh: CLEAN
131 * @inter: used to check if new interrupt has been triggered
132 * @last_timestamp: passing timestamp from th to bh of interrupt handler
133 * @indio_dev: industrial I/O device structure
134 * @trig: data ready trigger registered with iio
135 * @tx: transmit buffer
136 * @rx: recieve buffer
137 * @buf_lock: mutex to protect tx and rx
139 struct adis16240_state {
140 struct spi_device *us;
141 struct work_struct work_trigger_to_ring;
142 struct iio_work_cont work_cont_thresh;
143 s64 last_timestamp;
144 struct iio_dev *indio_dev;
145 struct iio_trigger *trig;
146 u8 *tx;
147 u8 *rx;
148 struct mutex buf_lock;
151 int adis16240_set_irq(struct device *dev, bool enable);
153 #ifdef CONFIG_IIO_RING_BUFFER
154 /* At the moment triggers are only used for ring buffer
155 * filling. This may change!
158 enum adis16240_scan {
159 ADIS16240_SCAN_SUPPLY,
160 ADIS16240_SCAN_ACC_X,
161 ADIS16240_SCAN_ACC_Y,
162 ADIS16240_SCAN_ACC_Z,
163 ADIS16240_SCAN_AUX_ADC,
164 ADIS16240_SCAN_TEMP,
167 void adis16240_remove_trigger(struct iio_dev *indio_dev);
168 int adis16240_probe_trigger(struct iio_dev *indio_dev);
170 ssize_t adis16240_read_data_from_ring(struct device *dev,
171 struct device_attribute *attr,
172 char *buf);
175 int adis16240_configure_ring(struct iio_dev *indio_dev);
176 void adis16240_unconfigure_ring(struct iio_dev *indio_dev);
178 int adis16240_initialize_ring(struct iio_ring_buffer *ring);
179 void adis16240_uninitialize_ring(struct iio_ring_buffer *ring);
180 #else /* CONFIG_IIO_RING_BUFFER */
182 static inline void adis16240_remove_trigger(struct iio_dev *indio_dev)
186 static inline int adis16240_probe_trigger(struct iio_dev *indio_dev)
188 return 0;
191 static inline ssize_t
192 adis16240_read_data_from_ring(struct device *dev,
193 struct device_attribute *attr,
194 char *buf)
196 return 0;
199 static int adis16240_configure_ring(struct iio_dev *indio_dev)
201 return 0;
204 static inline void adis16240_unconfigure_ring(struct iio_dev *indio_dev)
208 static inline int adis16240_initialize_ring(struct iio_ring_buffer *ring)
210 return 0;
213 static inline void adis16240_uninitialize_ring(struct iio_ring_buffer *ring)
217 #endif /* CONFIG_IIO_RING_BUFFER */
218 #endif /* SPI_ADIS16240_H_ */