[ARM/tegra] Integrate Accelerometer source code files.
[linux-2.6.git] / drivers / misc / mpu3050 / accel / kxtf9.c
1 /*
2  $License:
3     Copyright (C) 2010 InvenSense Corporation, All Rights Reserved.
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17   $
18  */
19 /*******************************************************************************
20  *
21  * $Id: kxtf9.c 3867 2010-10-09 01:06:18Z prao $
22  *
23  *******************************************************************************/
24
25 /**
26  *  @defgroup   ACCELDL (Motion Library - Accelerometer Driver Layer)
27  *  @brief      Provides the interface to setup and handle an accelerometers
28  *              connected to the secondary I2C interface of the gyroscope.
29  *
30  *  @{
31  *      @file   kxtf9.c
32  *      @brief  Accelerometer setup and handling methods.
33 **/
34
35 /* ------------------ */
36 /* - Include Files. - */
37 /* ------------------ */
38
39 #ifdef __KERNEL__
40 #include <linux/module.h>
41 #endif
42
43 #include "mpu3050.h"
44 #include "mlsl.h"
45 #include "mlos.h"
46
47 #include <log.h>
48 #undef MPL_LOG_TAG
49 #define MPL_LOG_TAG "MPL-acc"
50
51 /* --------------------- */
52 /* -    Variables.     - */
53 /* --------------------- */
54
55 /*****************************************
56     Accelerometer Initialization Functions
57 *****************************************/
58
59 static int kxtf9_suspend(mlsl_handle_t mlsl_handle,
60                          struct ext_slave_descr *slave,
61                          struct ext_slave_platform_data *pdata)
62 {
63         int result;
64         /* RAM reset */
65         result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x1d, 0xcd);
66         return result;
67 }
68
69 /* full scale setting - register and mask */
70 #define ACCEL_KIONIX_CTRL_REG      (0x1b)
71 #define ACCEL_KIONIX_CTRL_MASK     (0x18)
72
73 static int kxtf9_resume(mlsl_handle_t mlsl_handle,
74                         struct ext_slave_descr *slave,
75                         struct ext_slave_platform_data *pdata)
76 {
77         int result = ML_SUCCESS;
78         unsigned char reg;
79
80         /* RAM reset */
81         result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x1d, 0xcd);
82         MLOSSleep(10);
83         /* Wake up */
84         result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x1b, 0x42);
85         /* INT_CTRL_REG1: */
86         result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x1e, 0x14);
87         /* WUF_THRESH: */
88         result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x5a, 0x00);
89         /* DATA_CTRL_REG */
90         result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x21, 0x04);
91         /* WUF_TIMER */
92         result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x29, 0x02);
93
94         /* Full Scale */
95         reg = 0xc2;
96         reg &= ~ACCEL_KIONIX_CTRL_MASK;
97         reg |= 0x00;            /* TODO FIXME michelle */
98         if (slave->range.mantissa == 2) {
99                 reg |= 0x00;
100         } else if (slave->range.mantissa == 4) {
101                 reg |= 0x08;
102         } else if (slave->range.mantissa == 8) {
103                 reg |= 0x10;
104         }
105         /* Normal operation */
106         result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x1b, reg);
107         MLOSSleep(50);
108
109         return ML_SUCCESS;
110 }
111
112 static int kxtf9_read(mlsl_handle_t mlsl_handle,
113                       struct ext_slave_descr *slave,
114                       struct ext_slave_platform_data *pdata,
115                       unsigned char *data)
116 {
117         return ML_ERROR_FEATURE_NOT_IMPLEMENTED;
118 }
119
120 static struct ext_slave_descr kxtf9_descr = {
121         /*.suspend          = */ kxtf9_suspend,
122         /*.resume           = */ kxtf9_resume,
123         /*.read             = */ kxtf9_read,
124         /*.name             = */ "kxtf9",
125         /*.type             = */ EXT_SLAVE_TYPE_ACCELEROMETER,
126         /*.id               = */ ACCEL_ID_KXTF9,
127         /*.reg              = */ 0x06,
128         /*.len              = */ 6,
129         /*.endian           = */ EXT_SLAVE_LITTLE_ENDIAN,
130         /*.range            = */ {2, 0},
131 };
132
133 struct ext_slave_descr *kxtf9_get_slave_descr(void)
134 {
135         return &kxtf9_descr;
136 }
137
138 #ifdef __KERNEL__
139 EXPORT_SYMBOL(kxtf9_get_slave_descr);
140 #endif
141
142 /**
143  *  @}
144 **/