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 * @inter: used to check if new interrupt has been triggered 98 * @last_timestamp: passing timestamp from th to bh of interrupt handler 99 * @indio_dev: industrial I/O device structure 100 * @trig: data ready trigger registered with iio 101 * @tx: transmit buffer 102 * @rx: receive buffer 103 * @buf_lock: mutex to protect tx and rx 104 **/ 105 struct adis16300_state { 106 struct spi_device *us; 107 struct work_struct work_trigger_to_ring; 108 s64 last_timestamp; 109 struct iio_dev *indio_dev; 110 struct iio_trigger *trig; 111 u8 *tx; 112 u8 *rx; 113 struct mutex buf_lock; 114 }; 115 116 int adis16300_set_irq(struct device *dev, bool enable); 117 118 #ifdef CONFIG_IIO_RING_BUFFER 119 /* At the moment triggers are only used for ring buffer 120 * filling. This may change! 121 */ 122 123 #define ADIS16300_SCAN_SUPPLY 0 124 #define ADIS16300_SCAN_GYRO_X 1 125 #define ADIS16300_SCAN_ACC_X 2 126 #define ADIS16300_SCAN_ACC_Y 3 127 #define ADIS16300_SCAN_ACC_Z 4 128 #define ADIS16300_SCAN_TEMP 5 129 #define ADIS16300_SCAN_ADC_0 6 130 #define ADIS16300_SCAN_INCLI_X 7 131 #define ADIS16300_SCAN_INCLI_Y 8 132 133 void adis16300_remove_trigger(struct iio_dev *indio_dev); 134 int adis16300_probe_trigger(struct iio_dev *indio_dev); 135 136 ssize_t adis16300_read_data_from_ring(struct device *dev, 137 struct device_attribute *attr, 138 char *buf); 139 140 141 int adis16300_configure_ring(struct iio_dev *indio_dev); 142 void adis16300_unconfigure_ring(struct iio_dev *indio_dev); 143 144 int adis16300_initialize_ring(struct iio_ring_buffer *ring); 145 void adis16300_uninitialize_ring(struct iio_ring_buffer *ring); 146 #else /* CONFIG_IIO_RING_BUFFER */ 147 adis16300_remove_trigger(struct iio_dev * indio_dev)148static inline void adis16300_remove_trigger(struct iio_dev *indio_dev) 149 { 150 } 151 adis16300_probe_trigger(struct iio_dev * indio_dev)152static inline int adis16300_probe_trigger(struct iio_dev *indio_dev) 153 { 154 return 0; 155 } 156 157 static inline ssize_t adis16300_read_data_from_ring(struct device * dev,struct device_attribute * attr,char * buf)158adis16300_read_data_from_ring(struct device *dev, 159 struct device_attribute *attr, 160 char *buf) 161 { 162 return 0; 163 } 164 adis16300_configure_ring(struct iio_dev * indio_dev)165static int adis16300_configure_ring(struct iio_dev *indio_dev) 166 { 167 return 0; 168 } 169 adis16300_unconfigure_ring(struct iio_dev * indio_dev)170static inline void adis16300_unconfigure_ring(struct iio_dev *indio_dev) 171 { 172 } 173 adis16300_initialize_ring(struct iio_ring_buffer * ring)174static inline int adis16300_initialize_ring(struct iio_ring_buffer *ring) 175 { 176 return 0; 177 } 178 adis16300_uninitialize_ring(struct iio_ring_buffer * ring)179static inline void adis16300_uninitialize_ring(struct iio_ring_buffer *ring) 180 { 181 } 182 183 #endif /* CONFIG_IIO_RING_BUFFER */ 184 #endif /* SPI_ADIS16300_H_ */ 185