Flemmard | 6b1be1e | 2014-02-21 19:34:00 +0100 | [diff] [blame] | 1 | /******************** (C) COPYRIGHT 2010 STMicroelectronics ******************** |
| 2 | * |
| 3 | * File Name : lsm303dlh.h |
| 4 | * Authors : MSH - Motion Mems BU - Application Team |
| 5 | * : Carmine Iascone (carmine.iascone@st.com) |
| 6 | * : Matteo Dameno (matteo.dameno@st.com) |
| 7 | * Version : V 1.6.0 |
| 8 | * Date : 2011/02/28 |
| 9 | * Description : LSM303DLH 6D module sensor API |
| 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 | #ifndef __LSM303DLH_H__ |
| 28 | #define __LSM303DLH_H__ |
| 29 | |
| 30 | #define SAD0L 0x00 |
| 31 | #define SAD0H 0x01 |
| 32 | #define LSM303DLH_ACC_I2C_SADROOT 0x0C |
| 33 | #define LSM303DLH_ACC_I2C_SAD_L ((LSM303DLH_ACC_I2C_SADROOT<<1)|SAD0L) |
| 34 | #define LSM303DLH_ACC_I2C_SAD_H ((LSM303DLH_ACC_I2C_SADROOT<<1)|SAD0H) |
| 35 | #define LSM303DLH_ACC_DEV_NAME "lsm303dlh_acc_sysfs" |
| 36 | |
| 37 | |
| 38 | #define LSM303DLH_MAG_I2C_SAD 0x1E |
| 39 | #define LSM303DLH_MAG_DEV_NAME "lsm303dlh_mag_sysfs" |
| 40 | |
| 41 | |
trostanski | 576fee1 | 2013-12-13 09:50:30 +0100 | [diff] [blame] | 42 | #define LSM303DLH_ACC_MIN_POLL_PERIOD_MS 1 |
| 43 | #define LSM303DLH_MAG_MIN_POLL_PERIOD_MS 5 |
| 44 | |
| 45 | #define LSM303DLH_ACC_DEFAULT_INT1_GPIO (-EINVAL) |
| 46 | #define LSM303DLH_ACC_DEFAULT_INT2_GPIO (-EINVAL) |
| 47 | |
Flemmard | 6b1be1e | 2014-02-21 19:34:00 +0100 | [diff] [blame] | 48 | |
| 49 | /************************************************/ |
| 50 | /* Accelerometer section defines */ |
| 51 | /************************************************/ |
| 52 | |
| 53 | /* Accelerometer Sensor Full Scale */ |
| 54 | #define LSM303DLH_ACC_FS_MASK 0x30 |
| 55 | #define LSM303DLH_ACC_G_2G 0x00 |
| 56 | #define LSM303DLH_ACC_G_4G 0x10 |
| 57 | #define LSM303DLH_ACC_G_8G 0x30 |
| 58 | |
| 59 | /* Accelerometer Sensor Operating Mode */ |
| 60 | #define LSM303DLH_ACC_ENABLE 0x01 |
| 61 | #define LSM303DLH_ACC_DISABLE 0x00 |
| 62 | #define LSM303DLH_ACC_PM_NORMAL 0x20 |
| 63 | #define LSM303DLH_ACC_PM_OFF LSM303DLH_ACC_DISABLE |
| 64 | |
| 65 | |
trostanski | 576fee1 | 2013-12-13 09:50:30 +0100 | [diff] [blame] | 66 | /* RESUME STATE INDICES */ |
| 67 | #define RES_CTRL_REG1 0 |
| 68 | #define RES_CTRL_REG2 1 |
| 69 | #define RES_CTRL_REG3 2 |
| 70 | #define RES_CTRL_REG4 3 |
| 71 | #define RES_CTRL_REG5 4 |
| 72 | #define RES_REFERENCE 5 |
Flemmard | 6b1be1e | 2014-02-21 19:34:00 +0100 | [diff] [blame] | 73 | |
trostanski | 576fee1 | 2013-12-13 09:50:30 +0100 | [diff] [blame] | 74 | #define RES_INT_CFG1 6 |
| 75 | #define RES_INT_THS1 7 |
| 76 | #define RES_INT_DUR1 8 |
| 77 | #define RES_INT_CFG2 9 |
| 78 | #define RES_INT_THS2 10 |
| 79 | #define RES_INT_DUR2 11 |
| 80 | |
| 81 | #define RESUME_ENTRIES 12 |
| 82 | /* end RESUME STATE INDICES */ |
Flemmard | 6b1be1e | 2014-02-21 19:34:00 +0100 | [diff] [blame] | 83 | |
| 84 | /************************************************/ |
| 85 | /* Magnetometer section defines */ |
| 86 | /************************************************/ |
| 87 | |
| 88 | /* Magnetometer Sensor Full Scale */ |
| 89 | #define LSM303DLH_MAG_H_1_3G 0x20 |
| 90 | #define LSM303DLH_MAG_H_1_9G 0x40 |
| 91 | #define LSM303DLH_MAG_H_2_5G 0x60 |
| 92 | #define LSM303DLH_MAG_H_4_0G 0x80 |
| 93 | #define LSM303DLH_MAG_H_4_7G 0xA0 |
| 94 | #define LSM303DLH_MAG_H_5_6G 0xC0 |
| 95 | #define LSM303DLH_MAG_H_8_1G 0xE0 |
| 96 | |
| 97 | /* Magnetic Sensor Operating Mode */ |
| 98 | #define LSM303DLH_MAG_NORMAL_MODE 0x00 |
| 99 | #define LSM303DLH_MAG_POS_BIAS 0x01 |
| 100 | #define LSM303DLH_MAG_NEG_BIAS 0x02 |
| 101 | #define LSM303DLH_MAG_CC_MODE 0x00 |
| 102 | #define LSM303DLH_MAG_SC_MODE 0x01 |
| 103 | #define LSM303DLH_MAG_SLEEP_MODE 0x03 |
| 104 | |
| 105 | |
| 106 | #ifdef __KERNEL__ |
| 107 | struct lsm303dlh_acc_platform_data { |
| 108 | |
| 109 | int poll_interval; |
| 110 | int min_interval; |
| 111 | |
| 112 | u8 g_range; |
| 113 | |
| 114 | u8 axis_map_x; |
| 115 | u8 axis_map_y; |
| 116 | u8 axis_map_z; |
| 117 | |
| 118 | u8 negate_x; |
| 119 | u8 negate_y; |
| 120 | u8 negate_z; |
| 121 | |
| 122 | int (*init)(void); |
| 123 | void (*exit)(void); |
| 124 | int (*power_on)(void); |
| 125 | int (*power_off)(void); |
| 126 | |
| 127 | /* set gpio_int[1,2] either to the choosen gpio pin number or to -EINVAL |
| 128 | * if leaved unconnected |
| 129 | */ |
| 130 | int gpio_int1; |
| 131 | int gpio_int2; |
| 132 | }; |
| 133 | |
trostanski | 576fee1 | 2013-12-13 09:50:30 +0100 | [diff] [blame] | 134 | struct lsm303dlh_acc_data { |
| 135 | struct i2c_client *client; |
| 136 | struct lsm303dlh_acc_platform_data *pdata; |
| 137 | |
| 138 | struct mutex lock; |
| 139 | struct delayed_work input_work; |
| 140 | |
| 141 | struct input_dev *input_dev; |
| 142 | |
| 143 | int hw_initialized; |
| 144 | /* hw_working=-1 means not tested yet */ |
| 145 | int hw_working; |
| 146 | int selftest_enabled; |
| 147 | |
| 148 | atomic_t enabled; |
| 149 | int on_before_suspend; |
| 150 | |
| 151 | u8 sensitivity; |
| 152 | |
| 153 | u8 resume_state[RESUME_ENTRIES]; |
| 154 | |
| 155 | int irq1; |
| 156 | struct work_struct irq1_work; |
| 157 | struct workqueue_struct *irq1_work_queue; |
| 158 | int irq2; |
| 159 | struct work_struct irq2_work; |
| 160 | struct workqueue_struct *irq2_work_queue; |
| 161 | |
| 162 | u8 reg_addr; |
| 163 | |
| 164 | int ext_adap_enabled; |
| 165 | void *ext_handle; |
| 166 | }; |
| 167 | |
Flemmard | 6b1be1e | 2014-02-21 19:34:00 +0100 | [diff] [blame] | 168 | struct lsm303dlh_mag_platform_data { |
| 169 | |
| 170 | int poll_interval; |
| 171 | int min_interval; |
| 172 | |
| 173 | u8 h_range; |
| 174 | |
| 175 | u8 axis_map_x; |
| 176 | u8 axis_map_y; |
| 177 | u8 axis_map_z; |
| 178 | |
| 179 | u8 negate_x; |
| 180 | u8 negate_y; |
| 181 | u8 negate_z; |
| 182 | |
| 183 | int (*init)(void); |
| 184 | void (*exit)(void); |
| 185 | int (*power_on)(void); |
| 186 | int (*power_off)(void); |
| 187 | |
| 188 | }; |
trostanski | 576fee1 | 2013-12-13 09:50:30 +0100 | [diff] [blame] | 189 | |
| 190 | struct lsm303dlh_mag_data { |
| 191 | struct i2c_client *client; |
| 192 | struct lsm303dlh_mag_platform_data *pdata; |
| 193 | |
| 194 | struct mutex lock; |
| 195 | |
| 196 | struct input_polled_dev *input_poll_dev; |
| 197 | |
| 198 | int hw_initialized; |
| 199 | atomic_t enabled; |
| 200 | atomic_t self_test_enabled; |
| 201 | |
| 202 | u16 xy_sensitivity; |
| 203 | u16 z_sensitivity; |
| 204 | |
| 205 | u8 resume_state[3]; |
| 206 | |
| 207 | u8 reg_addr; |
| 208 | |
| 209 | int on_before_suspend; |
| 210 | int ext_adap_enabled; |
| 211 | void *ext_handle; |
| 212 | }; |
Flemmard | 6b1be1e | 2014-02-21 19:34:00 +0100 | [diff] [blame] | 213 | #endif /* __KERNEL__ */ |
| 214 | |
| 215 | #endif /* __LSM303DLH_H__ */ |