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