itg3200.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. #ifndef I2C_ITG3200_H_
  14. #define I2C_ITG3200_H_
  15. #include <linux/iio/iio.h>
  16. /* Register with I2C address (34h) */
  17. #define ITG3200_REG_ADDRESS 0x00
  18. /* Sample rate divider
  19. * Range: 0 to 255
  20. * Default value: 0x00 */
  21. #define ITG3200_REG_SAMPLE_RATE_DIV 0x15
  22. /* Digital low pass filter settings */
  23. #define ITG3200_REG_DLPF 0x16
  24. /* DLPF full scale range */
  25. #define ITG3200_DLPF_FS_SEL_2000 0x18
  26. /* Bandwidth (Hz) and internal sample rate
  27. * (kHz) of DLPF */
  28. #define ITG3200_DLPF_256_8 0x00
  29. #define ITG3200_DLPF_188_1 0x01
  30. #define ITG3200_DLPF_98_1 0x02
  31. #define ITG3200_DLPF_42_1 0x03
  32. #define ITG3200_DLPF_20_1 0x04
  33. #define ITG3200_DLPF_10_1 0x05
  34. #define ITG3200_DLPF_5_1 0x06
  35. #define ITG3200_DLPF_CFG_MASK 0x07
  36. /* Configuration for interrupt operations */
  37. #define ITG3200_REG_IRQ_CONFIG 0x17
  38. /* Logic level */
  39. #define ITG3200_IRQ_ACTIVE_LOW 0x80
  40. #define ITG3200_IRQ_ACTIVE_HIGH 0x00
  41. /* Drive type */
  42. #define ITG3200_IRQ_OPEN_DRAIN 0x40
  43. #define ITG3200_IRQ_PUSH_PULL 0x00
  44. /* Latch mode */
  45. #define ITG3200_IRQ_LATCH_UNTIL_CLEARED 0x20
  46. #define ITG3200_IRQ_LATCH_50US_PULSE 0x00
  47. /* Latch clear method */
  48. #define ITG3200_IRQ_LATCH_CLEAR_ANY 0x10
  49. #define ITG3200_IRQ_LATCH_CLEAR_STATUS 0x00
  50. /* Enable interrupt when device is ready */
  51. #define ITG3200_IRQ_DEVICE_RDY_ENABLE 0x04
  52. /* Enable interrupt when data is available */
  53. #define ITG3200_IRQ_DATA_RDY_ENABLE 0x01
  54. /* Determine the status of ITG-3200 interrupts */
  55. #define ITG3200_REG_IRQ_STATUS 0x1A
  56. /* Status of 'device is ready'-interrupt */
  57. #define ITG3200_IRQ_DEVICE_RDY_STATUS 0x04
  58. /* Status of 'data is available'-interrupt */
  59. #define ITG3200_IRQ_DATA_RDY_STATUS 0x01
  60. /* Sensor registers */
  61. #define ITG3200_REG_TEMP_OUT_H 0x1B
  62. #define ITG3200_REG_TEMP_OUT_L 0x1C
  63. #define ITG3200_REG_GYRO_XOUT_H 0x1D
  64. #define ITG3200_REG_GYRO_XOUT_L 0x1E
  65. #define ITG3200_REG_GYRO_YOUT_H 0x1F
  66. #define ITG3200_REG_GYRO_YOUT_L 0x20
  67. #define ITG3200_REG_GYRO_ZOUT_H 0x21
  68. #define ITG3200_REG_GYRO_ZOUT_L 0x22
  69. /* Power management */
  70. #define ITG3200_REG_POWER_MANAGEMENT 0x3E
  71. /* Reset device and internal registers to the
  72. * power-up-default settings */
  73. #define ITG3200_RESET 0x80
  74. /* Enable low power sleep mode */
  75. #define ITG3200_SLEEP 0x40
  76. /* Put according gyroscope in standby mode */
  77. #define ITG3200_STANDBY_GYRO_X 0x20
  78. #define ITG3200_STANDBY_GYRO_Y 0x10
  79. #define ITG3200_STANDBY_GYRO_Z 0x08
  80. /* Determine the device clock source */
  81. #define ITG3200_CLK_INTERNAL 0x00
  82. #define ITG3200_CLK_GYRO_X 0x01
  83. #define ITG3200_CLK_GYRO_Y 0x02
  84. #define ITG3200_CLK_GYRO_Z 0x03
  85. #define ITG3200_CLK_EXT_32K 0x04
  86. #define ITG3200_CLK_EXT_19M 0x05
  87. /**
  88. * struct itg3200 - device instance specific data
  89. * @i2c: actual i2c_client
  90. * @trig: data ready trigger from itg3200 pin
  91. **/
  92. struct itg3200 {
  93. struct i2c_client *i2c;
  94. struct iio_trigger *trig;
  95. };
  96. enum ITG3200_SCAN_INDEX {
  97. ITG3200_SCAN_TEMP,
  98. ITG3200_SCAN_GYRO_X,
  99. ITG3200_SCAN_GYRO_Y,
  100. ITG3200_SCAN_GYRO_Z,
  101. ITG3200_SCAN_ELEMENTS,
  102. };
  103. int itg3200_write_reg_8(struct iio_dev *indio_dev,
  104. u8 reg_address, u8 val);
  105. int itg3200_read_reg_8(struct iio_dev *indio_dev,
  106. u8 reg_address, u8 *val);
  107. #ifdef CONFIG_IIO_BUFFER
  108. void itg3200_remove_trigger(struct iio_dev *indio_dev);
  109. int itg3200_probe_trigger(struct iio_dev *indio_dev);
  110. int itg3200_buffer_configure(struct iio_dev *indio_dev);
  111. void itg3200_buffer_unconfigure(struct iio_dev *indio_dev);
  112. #else /* CONFIG_IIO_BUFFER */
  113. static inline void itg3200_remove_trigger(struct iio_dev *indio_dev)
  114. {
  115. }
  116. static inline int itg3200_probe_trigger(struct iio_dev *indio_dev)
  117. {
  118. return 0;
  119. }
  120. static inline int itg3200_buffer_configure(struct iio_dev *indio_dev)
  121. {
  122. return 0;
  123. }
  124. static inline void itg3200_buffer_unconfigure(struct iio_dev *indio_dev)
  125. {
  126. }
  127. #endif /* CONFIG_IIO_BUFFER */
  128. #endif /* ITG3200_H_ */