David Hays | 776c521 | 2014-06-22 21:55:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | ********************* (C) COPYRIGHT 2012 STMicroelectronics ******************** |
| 3 | * |
| 4 | * File Name : lsm330.h |
| 5 | * Authors : MH - C&I BU - Application Team |
| 6 | * : Matteo Dameno (matteo.dameno@st.com) |
| 7 | * : Denis Ciocca (denis.ciocca@st.com) |
| 8 | * Version : V.1.2.3 |
| 9 | * Date : 2013/May/16 |
| 10 | * |
| 11 | ******************************************************************************** |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License version 2 as |
| 15 | * published by the Free Software Foundation. |
| 16 | * |
| 17 | * THE PRESENT SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES |
| 18 | * OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, FOR THE SOLE |
| 19 | * PURPOSE TO SUPPORT YOUR APPLICATION DEVELOPMENT. |
| 20 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
| 21 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
| 22 | * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
| 23 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
| 24 | * |
| 25 | ******************************************************************************** |
| 26 | |
| 27 | ******************************************************************************** |
| 28 | Version History. |
| 29 | V 1.0.0 First Release |
| 30 | V 1.0.2 I2C address bugfix |
| 31 | V 1.2.0 Registers names compliant to correct datasheet |
| 32 | V.1.2.1 Removed enable_interrupt_output sysfs file, manage int1 |
| 33 | and int2, implements int1 isr. |
| 34 | V.1.2.2 Added HR_Timer and custom sysfs path |
| 35 | V.1.2.3 Added rotation matrices |
| 36 | ******************************************************************************** |
| 37 | SYSFS interface |
| 38 | - range: set full scale |
| 39 | -> accelerometer: 2,4,6,8,16 [g] |
| 40 | -> gyroscope: 250,500,2000 [dps] |
| 41 | - poll_period_ms: set 1/ODR |
| 42 | -> accelerometer: LSM330_ACC_MIN_POLL_PERIOD_MS < t [ms] |
| 43 | -> gyroscope: LSM330_GYR_MIN_POLL_PERIOD_MS < t [ms] |
| 44 | - enable_device: enable/disable sensor [1/0] |
| 45 | |
| 46 | |
| 47 | INPUT subsystem: NOTE-> output data INCLUDE the sensitivity in accelerometer, |
| 48 | but NOT INCLUDE the sensitivity in gyroscope. |
| 49 | - accelerometer: abs_x, abs_y, abs_z [ug] |
| 50 | - gyroscope: abs_x, abs_y, abs_z [raw data] |
| 51 | *******************************************************************************/ |
| 52 | |
| 53 | #ifndef __LSM330_H__ |
| 54 | #define __LSM330_H__ |
| 55 | |
| 56 | |
| 57 | #define LSM330_ACC_DEV_NAME "lsm330_acc" |
| 58 | #define LSM330_GYR_DEV_NAME "lsm330_gyr" |
| 59 | |
| 60 | #define CUSTOM_SYSFS_PATH |
| 61 | #define CUSTOM_SYSFS_CLASS_NAME_GYR "ST_gyr" |
| 62 | #define CUSTOM_SYSFS_CLASS_NAME_ACC "ST_acc" |
| 63 | |
| 64 | #define LSM330_GYR_SAD0L (0x00) |
| 65 | #define LSM330_ACC_SAD0L (0x02) |
| 66 | #define LSM330_SAD0H (0x01) |
| 67 | #define LSM330_ACC_I2C_SADROOT (0x07) |
| 68 | #define LSM330_ACC_I2C_SAD_L ((LSM330_ACC_I2C_SADROOT<<2) | \ |
| 69 | LSM330_ACC_SAD0L) |
| 70 | #define LSM330_ACC_I2C_SAD_H ((LSM330_ACC_I2C_SADROOT<<2) | \ |
| 71 | LSM330_SAD0H) |
| 72 | |
| 73 | #define LSM330_GYR_I2C_SADROOT (0x35) |
| 74 | #define LSM330_GYR_I2C_SAD_L ((LSM330_GYR_I2C_SADROOT<<1)| \ |
| 75 | LSM330_GYR_SAD0L) |
| 76 | #define LSM330_GYR_I2C_SAD_H ((LSM330_GYR_I2C_SADROOT<<1)| \ |
| 77 | LSM330_SAD0H) |
| 78 | |
| 79 | #define LSM330_ACC_MIN_POLL_PERIOD_MS 1 |
| 80 | |
| 81 | #define LSM330_GYR_MIN_POLL_PERIOD_MS 2 |
| 82 | |
| 83 | |
| 84 | #ifdef __KERNEL__ |
| 85 | |
| 86 | #define LSM330_ACC_DEFAULT_INT1_GPIO (-EINVAL) |
| 87 | #define LSM330_ACC_DEFAULT_INT2_GPIO (-EINVAL) |
| 88 | |
| 89 | #define LSM330_GYR_DEFAULT_INT1_GPIO (-EINVAL) |
| 90 | #define LSM330_GYR_DEFAULT_INT2_GPIO (-EINVAL) |
| 91 | |
| 92 | |
| 93 | #define LSM330_ACC_G_2G (0x00) |
| 94 | #define LSM330_ACC_G_4G (0x08) |
| 95 | #define LSM330_ACC_G_6G (0x10) |
| 96 | #define LSM330_ACC_G_8G (0x18) |
| 97 | #define LSM330_ACC_G_16G (0x20) |
| 98 | |
| 99 | #define LSM330_GYR_FS_250DPS (0x00) |
| 100 | #define LSM330_GYR_FS_500DPS (0x10) |
| 101 | #define LSM330_GYR_FS_2000DPS (0x30) |
| 102 | |
| 103 | extern unsigned int gs_kvalue; |
| 104 | extern unsigned char gyro_gsensor_kvalue[37]; |
| 105 | |
| 106 | struct lsm330_acc_platform_data { |
| 107 | unsigned int poll_interval; |
| 108 | unsigned int min_interval; |
| 109 | u8 fs_range; |
| 110 | short rot_matrix_index; |
| 111 | int (*init)(void); |
| 112 | void (*exit)(void); |
| 113 | int (*power_on)(void); |
| 114 | int (*power_off)(void); |
| 115 | int chip_layout; |
| 116 | int gs_kvalue; |
| 117 | int gpio_int1; |
| 118 | int gpio_int2; |
| 119 | }; |
| 120 | |
| 121 | struct lsm330_gyr_platform_data { |
| 122 | int (*init)(void); |
| 123 | void (*exit)(void); |
| 124 | int (*power_on)(void); |
| 125 | int (*power_off)(void); |
| 126 | unsigned int poll_interval; |
| 127 | unsigned int min_interval; |
| 128 | u8 fs_range; |
| 129 | short rot_matrix_index; |
| 130 | |
| 131 | u8 watermark; |
| 132 | u8 fifomode; |
| 133 | |
| 134 | int gpio_int1; |
| 135 | int gpio_int2; |
| 136 | }; |
| 137 | #endif |
| 138 | |
| 139 | #endif |