aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/mpu3050/accel
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-01-22 10:38:37 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-01-22 10:38:37 -0500
commitfcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch)
treea57612d1888735a2ec7972891b68c1ac5ec8faea /drivers/misc/mpu3050/accel
parent8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff)
Added missing tegra files.HEADmaster
Diffstat (limited to 'drivers/misc/mpu3050/accel')
-rw-r--r--drivers/misc/mpu3050/accel/kxtf9.c669
1 files changed, 669 insertions, 0 deletions
diff --git a/drivers/misc/mpu3050/accel/kxtf9.c b/drivers/misc/mpu3050/accel/kxtf9.c
new file mode 100644
index 00000000000..938cd572a8f
--- /dev/null
+++ b/drivers/misc/mpu3050/accel/kxtf9.c
@@ -0,0 +1,669 @@
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 * @defgroup ACCELDL (Motion Library - Accelerometer Driver Layer)
22 * @brief Provides the interface to setup and handle an accelerometers
23 * connected to the secondary I2C interface of the gyroscope.
24 *
25 * @{
26 * @file kxtf9.c
27 * @brief Accelerometer setup and handling methods.
28*/
29
30/* ------------------ */
31/* - Include Files. - */
32/* ------------------ */
33
34#undef MPL_LOG_NDEBUG
35#define MPL_LOG_NDEBUG 1
36
37#ifdef __KERNEL__
38#include <linux/module.h>
39#endif
40
41#include "mpu.h"
42#include "mlsl.h"
43#include "mlos.h"
44
45#include <log.h>
46#undef MPL_LOG_TAG
47#define MPL_LOG_TAG "MPL-acc"
48
49#define KXTF9_XOUT_HPF_L (0x00) /* 0000 0000 */
50#define KXTF9_XOUT_HPF_H (0x01) /* 0000 0001 */
51#define KXTF9_YOUT_HPF_L (0x02) /* 0000 0010 */
52#define KXTF9_YOUT_HPF_H (0x03) /* 0000 0011 */
53#define KXTF9_ZOUT_HPF_L (0x04) /* 0001 0100 */
54#define KXTF9_ZOUT_HPF_H (0x05) /* 0001 0101 */
55#define KXTF9_XOUT_L (0x06) /* 0000 0110 */
56#define KXTF9_XOUT_H (0x07) /* 0000 0111 */
57#define KXTF9_YOUT_L (0x08) /* 0000 1000 */
58#define KXTF9_YOUT_H (0x09) /* 0000 1001 */
59#define KXTF9_ZOUT_L (0x0A) /* 0001 1010 */
60#define KXTF9_ZOUT_H (0x0B) /* 0001 1011 */
61#define KXTF9_ST_RESP (0x0C) /* 0000 1100 */
62#define KXTF9_WHO_AM_I (0x0F) /* 0000 1111 */
63#define KXTF9_TILT_POS_CUR (0x10) /* 0001 0000 */
64#define KXTF9_TILT_POS_PRE (0x11) /* 0001 0001 */
65#define KXTF9_INT_SRC_REG1 (0x15) /* 0001 0101 */
66#define KXTF9_INT_SRC_REG2 (0x16) /* 0001 0110 */
67#define KXTF9_STATUS_REG (0x18) /* 0001 1000 */
68#define KXTF9_INT_REL (0x1A) /* 0001 1010 */
69#define KXTF9_CTRL_REG1 (0x1B) /* 0001 1011 */
70#define KXTF9_CTRL_REG2 (0x1C) /* 0001 1100 */
71#define KXTF9_CTRL_REG3 (0x1D) /* 0001 1101 */
72#define KXTF9_INT_CTRL_REG1 (0x1E) /* 0001 1110 */
73#define KXTF9_INT_CTRL_REG2 (0x1F) /* 0001 1111 */
74#define KXTF9_INT_CTRL_REG3 (0x20) /* 0010 0000 */
75#define KXTF9_DATA_CTRL_REG (0x21) /* 0010 0001 */
76#define KXTF9_TILT_TIMER (0x28) /* 0010 1000 */
77#define KXTF9_WUF_TIMER (0x29) /* 0010 1001 */
78#define KXTF9_TDT_TIMER (0x2B) /* 0010 1011 */
79#define KXTF9_TDT_H_THRESH (0x2C) /* 0010 1100 */
80#define KXTF9_TDT_L_THRESH (0x2D) /* 0010 1101 */
81#define KXTF9_TDT_TAP_TIMER (0x2E) /* 0010 1110 */
82#define KXTF9_TDT_TOTAL_TIMER (0x2F) /* 0010 1111 */
83#define KXTF9_TDT_LATENCY_TIMER (0x30) /* 0011 0000 */
84#define KXTF9_TDT_WINDOW_TIMER (0x31) /* 0011 0001 */
85#define KXTF9_WUF_THRESH (0x5A) /* 0101 1010 */
86#define KXTF9_TILT_ANGLE (0x5C) /* 0101 1100 */
87#define KXTF9_HYST_SET (0x5F) /* 0101 1111 */
88
89#define KXTF9_MAX_DUR (0xFF)
90#define KXTF9_MAX_THS (0xFF)
91#define KXTF9_THS_COUNTS_P_G (32)
92
93/* --------------------- */
94/* - Variables. - */
95/* --------------------- */
96
97struct kxtf9_config {
98 unsigned int odr; /* Output data rate mHz */
99 unsigned int fsr; /* full scale range mg */
100 unsigned int ths; /* Motion no-motion thseshold mg */
101 unsigned int dur; /* Motion no-motion duration ms */
102 unsigned int irq_type;
103 unsigned char reg_ths;
104 unsigned char reg_dur;
105 unsigned char reg_odr;
106 unsigned char reg_int_cfg1;
107 unsigned char reg_int_cfg2;
108 unsigned char ctrl_reg1;
109};
110
111struct kxtf9_private_data {
112 struct kxtf9_config suspend;
113 struct kxtf9_config resume;
114};
115
116/*****************************************
117 Accelerometer Initialization Functions
118*****************************************/
119
120static int kxtf9_set_ths(void *mlsl_handle,
121 struct ext_slave_platform_data *pdata,
122 struct kxtf9_config *config,
123 int apply,
124 long ths)
125{
126 int result = ML_SUCCESS;
127 if ((ths * KXTF9_THS_COUNTS_P_G / 1000) > KXTF9_MAX_THS)
128 ths = (KXTF9_MAX_THS * 1000) / KXTF9_THS_COUNTS_P_G;
129
130 if (ths < 0)
131 ths = 0;
132
133 config->ths = ths;
134 config->reg_ths = (unsigned char)
135 ((long)(ths * KXTF9_THS_COUNTS_P_G) / 1000);
136 MPL_LOGV("THS: %d, 0x%02x\n", config->ths, (int)config->reg_ths);
137 if (apply)
138 result = MLSLSerialWriteSingle(mlsl_handle, pdata->address,
139 KXTF9_WUF_THRESH,
140 config->reg_ths);
141 return result;
142}
143
144static int kxtf9_set_dur(void *mlsl_handle,
145 struct ext_slave_platform_data *pdata,
146 struct kxtf9_config *config,
147 int apply,
148 long dur)
149{
150 int result = ML_SUCCESS;
151 long reg_dur = (dur * config->odr) / 1000000;
152 config->dur = dur;
153
154 if (reg_dur > KXTF9_MAX_DUR)
155 reg_dur = KXTF9_MAX_DUR;
156
157 config->reg_dur = (unsigned char) reg_dur;
158 MPL_LOGV("DUR: %d, 0x%02x\n", config->dur, (int)config->reg_dur);
159 if (apply)
160 result = MLSLSerialWriteSingle(mlsl_handle, pdata->address,
161 KXTF9_WUF_TIMER,
162 (unsigned char)reg_dur);
163 return result;
164}
165
166/**
167 * Sets the IRQ to fire when one of the IRQ events occur. Threshold and
168 * duration will not be used uless the type is MOT or NMOT.
169 *
170 * @param config configuration to apply to, suspend or resume
171 * @param irq_type The type of IRQ. Valid values are
172 * - MPU_SLAVE_IRQ_TYPE_NONE
173 * - MPU_SLAVE_IRQ_TYPE_MOTION
174 * - MPU_SLAVE_IRQ_TYPE_DATA_READY
175 */
176static int kxtf9_set_irq(void *mlsl_handle,
177 struct ext_slave_platform_data *pdata,
178 struct kxtf9_config *config,
179 int apply,
180 long irq_type)
181{
182 int result = ML_SUCCESS;
183 struct kxtf9_private_data *private_data = pdata->private_data;
184
185 config->irq_type = (unsigned char)irq_type;
186 config->ctrl_reg1 &= ~0x22;
187 if (irq_type == MPU_SLAVE_IRQ_TYPE_DATA_READY) {
188 config->ctrl_reg1 |= 0x20;
189 config->reg_int_cfg1 = 0x38;
190 config->reg_int_cfg2 = 0x00;
191 } else if (irq_type == MPU_SLAVE_IRQ_TYPE_MOTION) {
192 config->ctrl_reg1 |= 0x02;
193 if ((unsigned long) config ==
194 (unsigned long) &private_data->suspend)
195 config->reg_int_cfg1 = 0x34;
196 else
197 config->reg_int_cfg1 = 0x24;
198 config->reg_int_cfg2 = 0xE0;
199 } else {
200 config->reg_int_cfg1 = 0x00;
201 config->reg_int_cfg2 = 0x00;
202 }
203
204 if (apply) {