/drivers/staging/iio/accel/adis16240.h
C Header | 196 lines | 108 code | 24 blank | 64 comment | 0 complexity | d703f05ef3298d7686540d6b03fcbc33 MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
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 * @trig: data ready trigger registered with iio 130 * @tx: transmit buffer 131 * @rx: receive buffer 132 * @buf_lock: mutex to protect tx and rx 133 **/ 134struct adis16240_state { 135 struct spi_device *us; 136 struct iio_trigger *trig; 137 struct mutex buf_lock; 138 u8 tx[ADIS16240_MAX_TX] ____cacheline_aligned; 139 u8 rx[ADIS16240_MAX_RX]; 140}; 141 142int adis16240_set_irq(struct iio_dev *indio_dev, bool enable); 143 144/* At the moment triggers are only used for ring buffer 145 * filling. This may change! 146 */ 147 148#define ADIS16240_SCAN_SUPPLY 0 149#define ADIS16240_SCAN_ACC_X 1 150#define ADIS16240_SCAN_ACC_Y 2 151#define ADIS16240_SCAN_ACC_Z 3 152#define ADIS16240_SCAN_AUX_ADC 4 153#define ADIS16240_SCAN_TEMP 5 154 155#ifdef CONFIG_IIO_RING_BUFFER 156void adis16240_remove_trigger(struct iio_dev *indio_dev); 157int adis16240_probe_trigger(struct iio_dev *indio_dev); 158 159ssize_t adis16240_read_data_from_ring(struct device *dev, 160 struct device_attribute *attr, 161 char *buf); 162 163 164int adis16240_configure_ring(struct iio_dev *indio_dev); 165void adis16240_unconfigure_ring(struct iio_dev *indio_dev); 166 167#else /* CONFIG_IIO_RING_BUFFER */ 168 169static inline void adis16240_remove_trigger(struct iio_dev *indio_dev) 170{ 171} 172 173static inline int adis16240_probe_trigger(struct iio_dev *indio_dev) 174{ 175 return 0; 176} 177 178static inline ssize_t 179adis16240_read_data_from_ring(struct device *dev, 180 struct device_attribute *attr, 181 char *buf) 182{ 183 return 0; 184} 185 186static int adis16240_configure_ring(struct iio_dev *indio_dev) 187{ 188 return 0; 189} 190 191static inline void adis16240_unconfigure_ring(struct iio_dev *indio_dev) 192{ 193} 194 195#endif /* CONFIG_IIO_RING_BUFFER */ 196#endif /* SPI_ADIS16240_H_ */