1 /******************** (C) COPYRIGHT 2010 STMicroelectronics ******************** 2 * 3 * File Name : l3g4200d.c 4 * Authors : MH - C&I BU - Application Team 5 * : Carmine Iascone (carmine.iascone@st.com) 6 * : Matteo Dameno (matteo.dameno@st.com) 7 * Version : V 0.2 8 * Date : 09/04/2010 9 * Description : L3G4200D digital output gyroscope 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 * THIS SOFTWARE IS SPECIFICALLY DESIGNED FOR EXCLUSIVE USE WITH ST PARTS. 26 * 27 ******************************************************************************** 28 * REVISON HISTORY 29 * 30 * VERSION | DATE | AUTHORS | DESCRIPTION 31 * 32 * 0.1 | 29/01/2010 | Carmine Iascone | First Release 33 * 34 * 0.2 | 09/04/2010 | Carmine Iascone | Updated the struct l3g4200d_t 35 * 36 *******************************************************************************/ 37 38 #ifndef __L3G4200D_H__ 39 #define __L3G4200D_H__ 40 41 #include <linux/ioctl.h> /* For IOCTL macros */ 42 43 /** This define controls compilation of the master device interface */ 44 /*#define L3G4200D_MASTER_DEVICE*/ 45 46 #define L3G4200D_IOCTL_BASE 77 47 48 #define L3G4200D_IOCTL_SET_DELAY _IOW(L3G4200D_IOCTL_BASE, 0, int) 49 #define L3G4200D_IOCTL_GET_DELAY _IOR(L3G4200D_IOCTL_BASE, 1, int) 50 #define L3G4200D_IOCTL_SET_ENABLE _IOW(L3G4200D_IOCTL_BASE, 2, int) 51 #define L3G4200D_IOCTL_GET_ENABLE _IOR(L3G4200D_IOCTL_BASE, 3, int) 52 #define L3G4200D_IOCTL_GET_CALIBRATION _IOR(L3G4200D_IOCTL_BASE, 4, int[3]) 53 54 #define L3G4200D_FS_250DPS 0x00 55 #define L3G4200D_FS_500DPS 0x10 56 #define L3G4200D_FS_2000DPS 0x30 57 58 #define PM_OFF 0x00 59 #define PM_NORMAL 0x08 60 #define ENABLE_ALL_AXES 0x07 61 62 /* l3g4200d gyroscope registers */ 63 #define GYRO_WHO_AM_I 0x0F 64 #define GYRO_CTRL_REG1 0x20 /* power control reg */ 65 #define GYRO_CTRL_REG2 0x21 /* power control reg */ 66 #define GYRO_CTRL_REG3 0x22 /* power control reg */ 67 #define GYRO_CTRL_REG4 0x23 /* interrupt control reg */ 68 #define GYRO_CTRL_REG5 0x24 /* interrupt control reg */ 69 #define GYRO_DATA_REG 0x28 70 #define GYRO_INT_SRC 0x31 71 72 73 74 75 /*status*/ 76 #define L3G4200D_SUSPEND 2 77 #define L3G4200D_OPEN 1 78 #define L3G4200D_CLOSE 0 79 80 #define ODR100_BW12_5 0x00 /* ODR = 100Hz; BW = 12.5Hz */ 81 #define ODR100_BW25 0x10 /* ODR = 100Hz; BW = 25Hz */ 82 #define ODR200_BW12_5 0x40 /* ODR = 200Hz; BW = 12.5Hz */ 83 #define ODR200_BW25 0x50 /* ODR = 200Hz; BW = 25Hz */ 84 #define ODR200_BW50 0x60 /* ODR = 200Hz; BW = 50Hz */ 85 #define ODR400_BW25 0x90 /* ODR = 400Hz; BW = 25Hz */ 86 #define ODR400_BW50 0xA0 /* ODR = 400Hz; BW = 50Hz */ 87 #define ODR400_BW110 0xB0 /* ODR = 400Hz; BW = 110Hz */ 88 #define ODR800_BW50 0xE0 /* ODR = 800Hz; BW = 50Hz */ 89 #define ODR800_BW100 0xF0 /* ODR = 800Hz; BW = 100Hz */ 90 91 #define L3G4200D_REG_WHO_AM_I 0x0f 92 #define L3G4200D_REG_CTRL_REG1 0x20 93 #define ACTIVE_MASK 0x08 94 95 #define GYRO_DEVID_L3G4200D 0xD3 96 #define GYRO_DEVID_L3G20D 0xD4 97 98 99 #ifdef __KERNEL__ 100 struct l3g4200d_platform_data { 101 u8 fs_range; 102 103 u8 axis_map_x; 104 u8 axis_map_y; 105 u8 axis_map_z; 106 107 u8 negate_x; 108 u8 negate_y; 109 u8 negate_z; 110 signed char orientation[9]; 111 int x_min; 112 int y_min; 113 int z_min; 114 int (*init)(void); 115 void (*exit)(void); 116 int (*power_on)(void); 117 int (*power_off)(void); 118 119 }; 120 121 #endif /* __KERNEL__ */ 122 123 struct l3g4200d_axis { 124 int x; 125 int y; 126 int z; 127 }; 128 129 130 struct l3g4200d_data { 131 char status; 132 char curr_tate; 133 unsigned int devid; 134 struct input_dev *input_dev; 135 struct i2c_client *client; 136 struct work_struct work; 137 struct delayed_work delaywork; /*report second event*/ 138 struct l3g4200d_platform_data *pdata; 139 struct l3g4200d_axis axis; 140 }; 141 142 #define GSENSOR_DEV_PATH "/dev/gyrosensors" 143 144 145 #endif /* __L3G4200D_H__ */ 146