1 /* SPDX-License-Identifier: GPL-2.0-only */ 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 2 /* 3 * itg3200.h -- support InvenSense ITG3200 3 * itg3200.h -- support InvenSense ITG3200 4 * Digital 3-Axis Gyroscope drive 4 * Digital 3-Axis Gyroscope driver 5 * 5 * 6 * Copyright (c) 2011 Christian Strobel <chris 6 * Copyright (c) 2011 Christian Strobel <christian.strobel@iis.fraunhofer.de> 7 * Copyright (c) 2011 Manuel Stahl <manuel.sta 7 * Copyright (c) 2011 Manuel Stahl <manuel.stahl@iis.fraunhofer.de> 8 * Copyright (c) 2012 Thorsten Nowak <thorsten 8 * Copyright (c) 2012 Thorsten Nowak <thorsten.nowak@iis.fraunhofer.de> 9 */ 9 */ 10 10 11 #ifndef I2C_ITG3200_H_ 11 #ifndef I2C_ITG3200_H_ 12 #define I2C_ITG3200_H_ 12 #define I2C_ITG3200_H_ 13 13 14 #include <linux/iio/iio.h> 14 #include <linux/iio/iio.h> 15 15 16 /* Register with I2C address (34h) */ 16 /* Register with I2C address (34h) */ 17 #define ITG3200_REG_ADDRESS 0x00 17 #define ITG3200_REG_ADDRESS 0x00 18 18 19 /* Sample rate divider 19 /* Sample rate divider 20 * Range: 0 to 255 20 * Range: 0 to 255 21 * Default value: 0x00 */ 21 * Default value: 0x00 */ 22 #define ITG3200_REG_SAMPLE_RATE_DIV 0x15 22 #define ITG3200_REG_SAMPLE_RATE_DIV 0x15 23 23 24 /* Digital low pass filter settings */ 24 /* Digital low pass filter settings */ 25 #define ITG3200_REG_DLPF 0x16 25 #define ITG3200_REG_DLPF 0x16 26 /* DLPF full scale range */ 26 /* DLPF full scale range */ 27 #define ITG3200_DLPF_FS_SEL_2000 0x18 27 #define ITG3200_DLPF_FS_SEL_2000 0x18 28 /* Bandwidth (Hz) and internal sample rate 28 /* Bandwidth (Hz) and internal sample rate 29 * (kHz) of DLPF */ 29 * (kHz) of DLPF */ 30 #define ITG3200_DLPF_256_8 0x00 30 #define ITG3200_DLPF_256_8 0x00 31 #define ITG3200_DLPF_188_1 0x01 31 #define ITG3200_DLPF_188_1 0x01 32 #define ITG3200_DLPF_98_1 0x02 32 #define ITG3200_DLPF_98_1 0x02 33 #define ITG3200_DLPF_42_1 0x03 33 #define ITG3200_DLPF_42_1 0x03 34 #define ITG3200_DLPF_20_1 0x04 34 #define ITG3200_DLPF_20_1 0x04 35 #define ITG3200_DLPF_10_1 0x05 35 #define ITG3200_DLPF_10_1 0x05 36 #define ITG3200_DLPF_5_1 0x06 36 #define ITG3200_DLPF_5_1 0x06 37 37 38 #define ITG3200_DLPF_CFG_MASK 0x07 38 #define ITG3200_DLPF_CFG_MASK 0x07 39 39 40 /* Configuration for interrupt operations */ 40 /* Configuration for interrupt operations */ 41 #define ITG3200_REG_IRQ_CONFIG 0x17 41 #define ITG3200_REG_IRQ_CONFIG 0x17 42 /* Logic level */ 42 /* Logic level */ 43 #define ITG3200_IRQ_ACTIVE_LOW 0x80 43 #define ITG3200_IRQ_ACTIVE_LOW 0x80 44 #define ITG3200_IRQ_ACTIVE_HIGH 0x00 44 #define ITG3200_IRQ_ACTIVE_HIGH 0x00 45 /* Drive type */ 45 /* Drive type */ 46 #define ITG3200_IRQ_OPEN_DRAIN 0x40 46 #define ITG3200_IRQ_OPEN_DRAIN 0x40 47 #define ITG3200_IRQ_PUSH_PULL 0x00 47 #define ITG3200_IRQ_PUSH_PULL 0x00 48 /* Latch mode */ 48 /* Latch mode */ 49 #define ITG3200_IRQ_LATCH_UNTIL_CLEARED 0x20 49 #define ITG3200_IRQ_LATCH_UNTIL_CLEARED 0x20 50 #define ITG3200_IRQ_LATCH_50US_PULSE 0x00 50 #define ITG3200_IRQ_LATCH_50US_PULSE 0x00 51 /* Latch clear method */ 51 /* Latch clear method */ 52 #define ITG3200_IRQ_LATCH_CLEAR_ANY 0x10 52 #define ITG3200_IRQ_LATCH_CLEAR_ANY 0x10 53 #define ITG3200_IRQ_LATCH_CLEAR_STATUS 0x00 53 #define ITG3200_IRQ_LATCH_CLEAR_STATUS 0x00 54 /* Enable interrupt when device is ready */ 54 /* Enable interrupt when device is ready */ 55 #define ITG3200_IRQ_DEVICE_RDY_ENABLE 0x04 55 #define ITG3200_IRQ_DEVICE_RDY_ENABLE 0x04 56 /* Enable interrupt when data is available */ 56 /* Enable interrupt when data is available */ 57 #define ITG3200_IRQ_DATA_RDY_ENABLE 0x01 57 #define ITG3200_IRQ_DATA_RDY_ENABLE 0x01 58 58 59 /* Determine the status of ITG-3200 interrupts 59 /* Determine the status of ITG-3200 interrupts */ 60 #define ITG3200_REG_IRQ_STATUS 0x1A 60 #define ITG3200_REG_IRQ_STATUS 0x1A 61 /* Status of 'device is ready'-interrupt */ 61 /* Status of 'device is ready'-interrupt */ 62 #define ITG3200_IRQ_DEVICE_RDY_STATUS 0x04 62 #define ITG3200_IRQ_DEVICE_RDY_STATUS 0x04 63 /* Status of 'data is available'-interrupt */ 63 /* Status of 'data is available'-interrupt */ 64 #define ITG3200_IRQ_DATA_RDY_STATUS 0x01 64 #define ITG3200_IRQ_DATA_RDY_STATUS 0x01 65 65 66 /* Sensor registers */ 66 /* Sensor registers */ 67 #define ITG3200_REG_TEMP_OUT_H 0x1B 67 #define ITG3200_REG_TEMP_OUT_H 0x1B 68 #define ITG3200_REG_TEMP_OUT_L 0x1C 68 #define ITG3200_REG_TEMP_OUT_L 0x1C 69 #define ITG3200_REG_GYRO_XOUT_H 0x1D 69 #define ITG3200_REG_GYRO_XOUT_H 0x1D 70 #define ITG3200_REG_GYRO_XOUT_L 0x1E 70 #define ITG3200_REG_GYRO_XOUT_L 0x1E 71 #define ITG3200_REG_GYRO_YOUT_H 0x1F 71 #define ITG3200_REG_GYRO_YOUT_H 0x1F 72 #define ITG3200_REG_GYRO_YOUT_L 0x20 72 #define ITG3200_REG_GYRO_YOUT_L 0x20 73 #define ITG3200_REG_GYRO_ZOUT_H 0x21 73 #define ITG3200_REG_GYRO_ZOUT_H 0x21 74 #define ITG3200_REG_GYRO_ZOUT_L 0x22 74 #define ITG3200_REG_GYRO_ZOUT_L 0x22 75 75 76 /* Power management */ 76 /* Power management */ 77 #define ITG3200_REG_POWER_MANAGEMENT 0x3E 77 #define ITG3200_REG_POWER_MANAGEMENT 0x3E 78 /* Reset device and internal registers to the 78 /* Reset device and internal registers to the 79 * power-up-default settings */ 79 * power-up-default settings */ 80 #define ITG3200_RESET 0x80 80 #define ITG3200_RESET 0x80 81 /* Enable low power sleep mode */ 81 /* Enable low power sleep mode */ 82 #define ITG3200_SLEEP 0x40 82 #define ITG3200_SLEEP 0x40 83 /* Put according gyroscope in standby mode */ 83 /* Put according gyroscope in standby mode */ 84 #define ITG3200_STANDBY_GYRO_X 0x20 84 #define ITG3200_STANDBY_GYRO_X 0x20 85 #define ITG3200_STANDBY_GYRO_Y 0x10 85 #define ITG3200_STANDBY_GYRO_Y 0x10 86 #define ITG3200_STANDBY_GYRO_Z 0x08 86 #define ITG3200_STANDBY_GYRO_Z 0x08 87 /* Determine the device clock source */ 87 /* Determine the device clock source */ 88 #define ITG3200_CLK_INTERNAL 0x00 88 #define ITG3200_CLK_INTERNAL 0x00 89 #define ITG3200_CLK_GYRO_X 0x01 89 #define ITG3200_CLK_GYRO_X 0x01 90 #define ITG3200_CLK_GYRO_Y 0x02 90 #define ITG3200_CLK_GYRO_Y 0x02 91 #define ITG3200_CLK_GYRO_Z 0x03 91 #define ITG3200_CLK_GYRO_Z 0x03 92 #define ITG3200_CLK_EXT_32K 0x04 92 #define ITG3200_CLK_EXT_32K 0x04 93 #define ITG3200_CLK_EXT_19M 0x05 93 #define ITG3200_CLK_EXT_19M 0x05 94 94 95 95 96 /** 96 /** 97 * struct itg3200 - device instance specific d 97 * struct itg3200 - device instance specific data 98 * @i2c: actual i2c_client 98 * @i2c: actual i2c_client 99 * @trig: data ready trigger from itg3200 pi 99 * @trig: data ready trigger from itg3200 pin 100 **/ 100 **/ 101 struct itg3200 { 101 struct itg3200 { 102 struct i2c_client *i2c; 102 struct i2c_client *i2c; 103 struct iio_trigger *trig; 103 struct iio_trigger *trig; 104 struct iio_mount_matrix orientation; 104 struct iio_mount_matrix orientation; 105 /* lock to protect against multiple ac << 106 struct mutex lock; << 107 }; 105 }; 108 106 109 enum ITG3200_SCAN_INDEX { 107 enum ITG3200_SCAN_INDEX { 110 ITG3200_SCAN_TEMP, 108 ITG3200_SCAN_TEMP, 111 ITG3200_SCAN_GYRO_X, 109 ITG3200_SCAN_GYRO_X, 112 ITG3200_SCAN_GYRO_Y, 110 ITG3200_SCAN_GYRO_Y, 113 ITG3200_SCAN_GYRO_Z, 111 ITG3200_SCAN_GYRO_Z, 114 ITG3200_SCAN_ELEMENTS, 112 ITG3200_SCAN_ELEMENTS, 115 }; 113 }; 116 114 117 int itg3200_write_reg_8(struct iio_dev *indio_ 115 int itg3200_write_reg_8(struct iio_dev *indio_dev, 118 u8 reg_address, u8 val); 116 u8 reg_address, u8 val); 119 117 120 int itg3200_read_reg_8(struct iio_dev *indio_d 118 int itg3200_read_reg_8(struct iio_dev *indio_dev, 121 u8 reg_address, u8 *val); 119 u8 reg_address, u8 *val); 122 120 123 121 124 #ifdef CONFIG_IIO_BUFFER 122 #ifdef CONFIG_IIO_BUFFER 125 123 126 void itg3200_remove_trigger(struct iio_dev *in 124 void itg3200_remove_trigger(struct iio_dev *indio_dev); 127 int itg3200_probe_trigger(struct iio_dev *indi 125 int itg3200_probe_trigger(struct iio_dev *indio_dev); 128 126 129 int itg3200_buffer_configure(struct iio_dev *i 127 int itg3200_buffer_configure(struct iio_dev *indio_dev); 130 void itg3200_buffer_unconfigure(struct iio_dev 128 void itg3200_buffer_unconfigure(struct iio_dev *indio_dev); 131 129 132 #else /* CONFIG_IIO_BUFFER */ 130 #else /* CONFIG_IIO_BUFFER */ 133 131 134 static inline void itg3200_remove_trigger(stru 132 static inline void itg3200_remove_trigger(struct iio_dev *indio_dev) 135 { 133 { 136 } 134 } 137 135 138 static inline int itg3200_probe_trigger(struct 136 static inline int itg3200_probe_trigger(struct iio_dev *indio_dev) 139 { 137 { 140 return 0; 138 return 0; 141 } 139 } 142 140 143 static inline int itg3200_buffer_configure(str 141 static inline int itg3200_buffer_configure(struct iio_dev *indio_dev) 144 { 142 { 145 return 0; 143 return 0; 146 } 144 } 147 145 148 static inline void itg3200_buffer_unconfigure( 146 static inline void itg3200_buffer_unconfigure(struct iio_dev *indio_dev) 149 { 147 { 150 } 148 } 151 149 152 #endif /* CONFIG_IIO_BUFFER */ 150 #endif /* CONFIG_IIO_BUFFER */ 153 151 154 #endif /* ITG3200_H_ */ 152 #endif /* ITG3200_H_ */ 155 153
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.