1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 29dbf091dSManuel Stahl /* 39dbf091dSManuel Stahl * itg3200.h -- support InvenSense ITG3200 49dbf091dSManuel Stahl * Digital 3-Axis Gyroscope driver 59dbf091dSManuel Stahl * 69dbf091dSManuel Stahl * Copyright (c) 2011 Christian Strobel <christian.strobel@iis.fraunhofer.de> 79dbf091dSManuel Stahl * Copyright (c) 2011 Manuel Stahl <manuel.stahl@iis.fraunhofer.de> 89dbf091dSManuel Stahl * Copyright (c) 2012 Thorsten Nowak <thorsten.nowak@iis.fraunhofer.de> 99dbf091dSManuel Stahl */ 109dbf091dSManuel Stahl 119dbf091dSManuel Stahl #ifndef I2C_ITG3200_H_ 129dbf091dSManuel Stahl #define I2C_ITG3200_H_ 139dbf091dSManuel Stahl 149dbf091dSManuel Stahl #include <linux/iio/iio.h> 159dbf091dSManuel Stahl 169dbf091dSManuel Stahl /* Register with I2C address (34h) */ 179dbf091dSManuel Stahl #define ITG3200_REG_ADDRESS 0x00 189dbf091dSManuel Stahl 199dbf091dSManuel Stahl /* Sample rate divider 209dbf091dSManuel Stahl * Range: 0 to 255 219dbf091dSManuel Stahl * Default value: 0x00 */ 229dbf091dSManuel Stahl #define ITG3200_REG_SAMPLE_RATE_DIV 0x15 239dbf091dSManuel Stahl 249dbf091dSManuel Stahl /* Digital low pass filter settings */ 259dbf091dSManuel Stahl #define ITG3200_REG_DLPF 0x16 269dbf091dSManuel Stahl /* DLPF full scale range */ 279dbf091dSManuel Stahl #define ITG3200_DLPF_FS_SEL_2000 0x18 289dbf091dSManuel Stahl /* Bandwidth (Hz) and internal sample rate 299dbf091dSManuel Stahl * (kHz) of DLPF */ 309dbf091dSManuel Stahl #define ITG3200_DLPF_256_8 0x00 319dbf091dSManuel Stahl #define ITG3200_DLPF_188_1 0x01 329dbf091dSManuel Stahl #define ITG3200_DLPF_98_1 0x02 339dbf091dSManuel Stahl #define ITG3200_DLPF_42_1 0x03 349dbf091dSManuel Stahl #define ITG3200_DLPF_20_1 0x04 359dbf091dSManuel Stahl #define ITG3200_DLPF_10_1 0x05 369dbf091dSManuel Stahl #define ITG3200_DLPF_5_1 0x06 379dbf091dSManuel Stahl 389dbf091dSManuel Stahl #define ITG3200_DLPF_CFG_MASK 0x07 399dbf091dSManuel Stahl 409dbf091dSManuel Stahl /* Configuration for interrupt operations */ 419dbf091dSManuel Stahl #define ITG3200_REG_IRQ_CONFIG 0x17 429dbf091dSManuel Stahl /* Logic level */ 439dbf091dSManuel Stahl #define ITG3200_IRQ_ACTIVE_LOW 0x80 449dbf091dSManuel Stahl #define ITG3200_IRQ_ACTIVE_HIGH 0x00 459dbf091dSManuel Stahl /* Drive type */ 469dbf091dSManuel Stahl #define ITG3200_IRQ_OPEN_DRAIN 0x40 479dbf091dSManuel Stahl #define ITG3200_IRQ_PUSH_PULL 0x00 489dbf091dSManuel Stahl /* Latch mode */ 499dbf091dSManuel Stahl #define ITG3200_IRQ_LATCH_UNTIL_CLEARED 0x20 509dbf091dSManuel Stahl #define ITG3200_IRQ_LATCH_50US_PULSE 0x00 519dbf091dSManuel Stahl /* Latch clear method */ 529dbf091dSManuel Stahl #define ITG3200_IRQ_LATCH_CLEAR_ANY 0x10 539dbf091dSManuel Stahl #define ITG3200_IRQ_LATCH_CLEAR_STATUS 0x00 549dbf091dSManuel Stahl /* Enable interrupt when device is ready */ 559dbf091dSManuel Stahl #define ITG3200_IRQ_DEVICE_RDY_ENABLE 0x04 569dbf091dSManuel Stahl /* Enable interrupt when data is available */ 579dbf091dSManuel Stahl #define ITG3200_IRQ_DATA_RDY_ENABLE 0x01 589dbf091dSManuel Stahl 599dbf091dSManuel Stahl /* Determine the status of ITG-3200 interrupts */ 609dbf091dSManuel Stahl #define ITG3200_REG_IRQ_STATUS 0x1A 619dbf091dSManuel Stahl /* Status of 'device is ready'-interrupt */ 629dbf091dSManuel Stahl #define ITG3200_IRQ_DEVICE_RDY_STATUS 0x04 639dbf091dSManuel Stahl /* Status of 'data is available'-interrupt */ 649dbf091dSManuel Stahl #define ITG3200_IRQ_DATA_RDY_STATUS 0x01 659dbf091dSManuel Stahl 669dbf091dSManuel Stahl /* Sensor registers */ 679dbf091dSManuel Stahl #define ITG3200_REG_TEMP_OUT_H 0x1B 689dbf091dSManuel Stahl #define ITG3200_REG_TEMP_OUT_L 0x1C 699dbf091dSManuel Stahl #define ITG3200_REG_GYRO_XOUT_H 0x1D 709dbf091dSManuel Stahl #define ITG3200_REG_GYRO_XOUT_L 0x1E 719dbf091dSManuel Stahl #define ITG3200_REG_GYRO_YOUT_H 0x1F 729dbf091dSManuel Stahl #define ITG3200_REG_GYRO_YOUT_L 0x20 739dbf091dSManuel Stahl #define ITG3200_REG_GYRO_ZOUT_H 0x21 749dbf091dSManuel Stahl #define ITG3200_REG_GYRO_ZOUT_L 0x22 759dbf091dSManuel Stahl 769dbf091dSManuel Stahl /* Power management */ 779dbf091dSManuel Stahl #define ITG3200_REG_POWER_MANAGEMENT 0x3E 789dbf091dSManuel Stahl /* Reset device and internal registers to the 799dbf091dSManuel Stahl * power-up-default settings */ 809dbf091dSManuel Stahl #define ITG3200_RESET 0x80 819dbf091dSManuel Stahl /* Enable low power sleep mode */ 829dbf091dSManuel Stahl #define ITG3200_SLEEP 0x40 839dbf091dSManuel Stahl /* Put according gyroscope in standby mode */ 849dbf091dSManuel Stahl #define ITG3200_STANDBY_GYRO_X 0x20 859dbf091dSManuel Stahl #define ITG3200_STANDBY_GYRO_Y 0x10 869dbf091dSManuel Stahl #define ITG3200_STANDBY_GYRO_Z 0x08 879dbf091dSManuel Stahl /* Determine the device clock source */ 889dbf091dSManuel Stahl #define ITG3200_CLK_INTERNAL 0x00 899dbf091dSManuel Stahl #define ITG3200_CLK_GYRO_X 0x01 909dbf091dSManuel Stahl #define ITG3200_CLK_GYRO_Y 0x02 919dbf091dSManuel Stahl #define ITG3200_CLK_GYRO_Z 0x03 929dbf091dSManuel Stahl #define ITG3200_CLK_EXT_32K 0x04 939dbf091dSManuel Stahl #define ITG3200_CLK_EXT_19M 0x05 949dbf091dSManuel Stahl 959dbf091dSManuel Stahl 969dbf091dSManuel Stahl /** 979dbf091dSManuel Stahl * struct itg3200 - device instance specific data 989dbf091dSManuel Stahl * @i2c: actual i2c_client 999dbf091dSManuel Stahl * @trig: data ready trigger from itg3200 pin 1009dbf091dSManuel Stahl **/ 1019dbf091dSManuel Stahl struct itg3200 { 1029dbf091dSManuel Stahl struct i2c_client *i2c; 1039dbf091dSManuel Stahl struct iio_trigger *trig; 10470b5fdbbSH. Nikolaus Schaller struct iio_mount_matrix orientation; 105*3cc36cabSNuno Sá /* lock to protect against multiple access to the device */ 106*3cc36cabSNuno Sá struct mutex lock; 1079dbf091dSManuel Stahl }; 1089dbf091dSManuel Stahl 1099dbf091dSManuel Stahl enum ITG3200_SCAN_INDEX { 1109dbf091dSManuel Stahl ITG3200_SCAN_TEMP, 1119dbf091dSManuel Stahl ITG3200_SCAN_GYRO_X, 1129dbf091dSManuel Stahl ITG3200_SCAN_GYRO_Y, 1139dbf091dSManuel Stahl ITG3200_SCAN_GYRO_Z, 1149dbf091dSManuel Stahl ITG3200_SCAN_ELEMENTS, 1159dbf091dSManuel Stahl }; 1169dbf091dSManuel Stahl 1179dbf091dSManuel Stahl int itg3200_write_reg_8(struct iio_dev *indio_dev, 1189dbf091dSManuel Stahl u8 reg_address, u8 val); 1199dbf091dSManuel Stahl 1209dbf091dSManuel Stahl int itg3200_read_reg_8(struct iio_dev *indio_dev, 1219dbf091dSManuel Stahl u8 reg_address, u8 *val); 1229dbf091dSManuel Stahl 1239dbf091dSManuel Stahl 1249dbf091dSManuel Stahl #ifdef CONFIG_IIO_BUFFER 1259dbf091dSManuel Stahl 1269dbf091dSManuel Stahl void itg3200_remove_trigger(struct iio_dev *indio_dev); 1279dbf091dSManuel Stahl int itg3200_probe_trigger(struct iio_dev *indio_dev); 1289dbf091dSManuel Stahl 1299dbf091dSManuel Stahl int itg3200_buffer_configure(struct iio_dev *indio_dev); 1309dbf091dSManuel Stahl void itg3200_buffer_unconfigure(struct iio_dev *indio_dev); 1319dbf091dSManuel Stahl 1329dbf091dSManuel Stahl #else /* CONFIG_IIO_BUFFER */ 1339dbf091dSManuel Stahl itg3200_remove_trigger(struct iio_dev * indio_dev)1349dbf091dSManuel Stahlstatic inline void itg3200_remove_trigger(struct iio_dev *indio_dev) 1359dbf091dSManuel Stahl { 1369dbf091dSManuel Stahl } 1379dbf091dSManuel Stahl itg3200_probe_trigger(struct iio_dev * indio_dev)1389dbf091dSManuel Stahlstatic inline int itg3200_probe_trigger(struct iio_dev *indio_dev) 1399dbf091dSManuel Stahl { 1409dbf091dSManuel Stahl return 0; 1419dbf091dSManuel Stahl } 1429dbf091dSManuel Stahl itg3200_buffer_configure(struct iio_dev * indio_dev)1439dbf091dSManuel Stahlstatic inline int itg3200_buffer_configure(struct iio_dev *indio_dev) 1449dbf091dSManuel Stahl { 1459dbf091dSManuel Stahl return 0; 1469dbf091dSManuel Stahl } 1479dbf091dSManuel Stahl itg3200_buffer_unconfigure(struct iio_dev * indio_dev)1489dbf091dSManuel Stahlstatic inline void itg3200_buffer_unconfigure(struct iio_dev *indio_dev) 1499dbf091dSManuel Stahl { 1509dbf091dSManuel Stahl } 1519dbf091dSManuel Stahl 152e6251fc2SPaul Bolle #endif /* CONFIG_IIO_BUFFER */ 1539dbf091dSManuel Stahl 1549dbf091dSManuel Stahl #endif /* ITG3200_H_ */ 155