Index: linux-2.6.35/drivers/misc/mpu3050/accel/bma023.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.35/drivers/misc/mpu3050/accel/bma023.c 2010-12-24
11:18:41.000000000 +0800
@@ -0,0 +1,371 @@
+/**********************************************************************
*********
+ *
+ * $Id: bma023.c 3687 2010-09-07 22:40:14Z kkeal $
+ *
+
************************************************************************
*******/
+
+/**********************************************************************
*********
+ * Copyright (c) 2009 InvenSense Corporation, All Rights Reserved.
+
************************************************************************
******/
+
+/**
+ * @defgroup ACCELDL (Motion Library - Accelerometer Driver Layer)
+ * @brief Provides the interface to setup and handle an
accelerometers
+ * connected to the secondary I2C interface of the
gyroscope.
+ *
+ * @{
+ * @file bma023.c
+ * @brief Accelerometer setup and handling methods.
+**/
+
+/* ------------------ */
+/* - Include Files. - */
+/* ------------------ */
+
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/ctype.h>
+
+#include "mpu3050.h"
+#include "mlsl.h"
+#include "mldl_cfg.h"
+
+#include "bma023.h"
+
+/* --------------------- */
+/* - Variables. - */
+/* --------------------- */
+
+/*********************************************
+ Accelerometer Initialization Functions
+**********************************************/
+
+static struct accel_config aconfig = { 0x00, 0x03, 0x00, 0x00, 0x03,
0xA0, 0x03, 0xA0, 0x00 };
+
+struct accel_config* accel_get_config(void){
+ return &aconfig;
+}
+EXPORT_SYMBOL(accel_get_config);
+
+static int atoi(const char *array){
+ const char *parray = array;
+ long res;
+ int base;
+ int ret_val, nagetive = 0;
+ while (isspace(*parray))
+ parray++;
+ if(parray[1]=='x')
+ base = 16;
+ else{
+ base = 10;
+ if(parray[0] == '-'){
+ nagetive = 1;
+ parray++;
+ }
+ }
+ ret_val = strict_strtoul(parray, base, &res);
+ if(nagetive && ~ret_val)
+ res *= -1;
+ return ret_val ? 0 : res;
+}
+
+int bma023_read_accel_xyz(struct i2c_adapter *accel_adapter,
+ struct
mldl_cfg *mldl_cfg, signed short *xyz_axes){
+ unsigned char data[6];
+ if(MLSLSerialRead(accel_adapter, mldl_cfg->pdata->accel.address,
BMA023_X_AXIS_LSB_REG, 6, data))
+ return -1;
+ xyz_axes[0] = data[0] & BMA023_OFFSET_X_LSB__MSK;
+ xyz_axes[0] = xyz_axes[0] >> BMA023_OFFSET_X_LSB__POS | data[1]
<< BMA023_OFFSET_X_LSB__LEN;
+ xyz_axes[0] = xyz_axes[0] << BMA023_OFFSET_X_LSB__POS;
+ xyz_axes[0] = xyz_axes[0] >> BMA023_OFFSET_X_LSB__POS;
+ xyz_axes[1] = data[2] & BMA023_OFFSET_Y_LSB__MSK;
+ xyz_axes[1] = xyz_axes[1] >> BMA023_OFFSET_Y_LSB__POS | data[3]
<< BMA023_OFFSET_Y_LSB__LEN;
+ xyz_axes[1] = xyz_axes[1] << BMA023_OFFSET_Y_LSB__POS;
+ xyz_axes[1] = xyz_axes[1] >> BMA023_OFFSET_Y_LSB__POS;
+ xyz_axes[2] = data[4] & BMA023_OFFSET_Z_LSB__MSK;
+ xyz_axes[2] = xyz_axes[2] >> BMA023_OFFSET_Z_LSB__POS | data[5]
<< BMA023_OFFSET_Z_LSB__LEN;
+ xyz_axes[2] = xyz_axes[2] << BMA023_OFFSET_Z_LSB__POS;
+ xyz_axes[2] = xyz_axes[2] >> BMA023_OFFSET_Z_LSB__POS;
+ return 0;
+}
+
+unsigned char bma023_get_power_mode(struct i2c_adapter *accel_adapter,
+ struct
mldl_cfg *mldl_cfg){
+ unsigned char data;
+ if(MLSLSerialRead(accel_adapter, mldl_cfg->pdata->accel.address,
BMA023_CTRL_REG, 1, &data)){
+ printk("Can't get power status\n");
+ return 0;
+ }
+ data &= BMA023_SLEEP__MSK;
+ return data;
+}
+
+int bma023_get_bandwidth(void){
+ int bw_hz=0;
+ unsigned char bw = aconfig.range_bandwidth &
BMA023_BANDWIDTH__MSK;
+ switch(bw){
+ case 0x00: bw_hz=25; break;
+ case 0x01: bw_hz=50; break;
+ case 0x02: bw_hz=100; break;
+ case 0x03: bw_hz=190; break;
+ case 0x04: bw_hz=375; break;
+ case 0x05: bw_hz=750; break;
+ case 0x06: bw_hz=1500; break;
+ default: break;
+ }
+ return bw_hz;
+}
+
+int bma023_set_bandwidth(struct i2c_adapter *accel_adapter, const char
*buf){
+ unsigned char reg, bw = aconfig.range_bandwidth &
BMA023_BANDWIDTH__MSK;
+ if(buf[0] == '-'){
+ if(bw == 0x00)
+ return 0;
+ aconfig.range_bandwidth--;
+ }
+ else if(buf[0] == '+'){
+ if(bw == 0x06)
+ return 0;
+ aconfig.range_bandwidth++;
+ }
+ else {
+ printk("accel_bw: wrong command %s",buf);
+ return -1;
+ }
+ if(MLSLSerialRead(accel_adapter, BMA023_I2C_ADDR,
BMA023_RANGE_BWIDTH_REG, 1, ®)){
+ printk("%s: Can't get bandwidth reg\n",__func__);
+ return -1;
+ }
+ reg &= 0xe0;
+ reg |= aconfig.range_bandwidth;
+ if(MLSLSerialWriteSingle(accel_adapter, BMA023_I2C_ADDR,
BMA023_RANGE_BWIDTH_REG, reg )){
+ printk("%s: Can't set bandwidth reg\n",__func__);
+ return -1;
+ }
+ return 0;
+}
+
+int bma023_get_range(void){
+ unsigned char range;
+ int g_range = 0;
+ range = aconfig.range_bandwidth & BMA023_RANGE__MSK;
+ switch(range){
+ case 0x00: g_range = 2; break;
+ case 0x08: g_range = 4; break;
+ case 0x10: g_range = 8; break;
+ default: break;
+ }
+ return g_range;
+}
+
+int bma023_set_range(struct i2c_adapter *accel_adapter, const char
*buf){
+ unsigned char reg, range = aconfig.range_bandwidth &
BMA023_RANGE__MSK;
+ if(buf[0] == '-'){
+ if(range == 0x00)
+ return 0;
+ aconfig.range_bandwidth -= 0x08;
+ }
+ else if(buf[0] == '+'){
+ if(range == 0x10)
+ return 0;
+ aconfig.range_bandwidth += 0x08;
+ }
+ else {
+ printk("accel_range: wrong command %s\n",buf);
+ return -1;
+ }
+ if(MLSLSerialRead(accel_adapter, BMA023_I2C_ADDR,
BMA023_RANGE_BWIDTH_REG, 1, ®)){
+ printk("%s: Can't get range reg\n",__func__);
+ return -1;
+ }
+ reg &= 0xe0;
+ reg |= aconfig.range_bandwidth;
+ if(MLSLSerialWriteSingle(accel_adapter, BMA023_I2C_ADDR,
BMA023_RANGE_BWIDTH_REG, reg )){
+ printk("%s: Can't set range reg\n",__func__);
+ return -1;
+ }
+ return 0;
+}
+
+int bma023_set_hg_duration(struct i2c_adapter *accel_adapter, const
char *buf){
+ int value;
+ value = atoi(buf);
+ if(value > 255)
+ aconfig.hg_dur = 0xFF;
+ else if(value < 0)
+ aconfig.hg_dur = 0x00;
+ else
+ aconfig.hg_dur = value;
+ if(MLSLSerialWriteSingle(accel_adapter, BMA023_I2C_ADDR,
BMA023_HG_DURATION_REG, aconfig.hg_dur)){
+ printk("%s: Can't set high g duration\n",__func__);
+ return -1;
+ }
+ return 0;
+}
+
+int bma023_set_hg_threshold(struct i2c_adapter *accel_adapter, const
char *buf){
+ int value;
+ value = atoi(buf);
+ if(value > 255)
+ aconfig.hg_thres = 0xFF;
+ else if(value < 0)
+ aconfig.hg_thres = 0x00;
+ else
+ aconfig.hg_thres = value;
+ if(MLSLSerialWriteSingle(accel_adapter, BMA023_I2C_ADDR,
BMA023_HG_THRESHOLD_REG, aconfig.hg_thres)){
+ printk("%s: Can't set high g threshold\n",__func__);
+ return -1;
+ }
+ return 0;
+}
+
+int bma023_set_lg_duration(struct i2c_adapter *accel_adapter, const
char *buf){
+ int value;
+ value = atoi(buf);
+ if(value > 255)
+ aconfig.lg_dur = 0xFF;
+ else if(value < 0)
+ aconfig.lg_dur = 0x00;
+ else
+ aconfig.lg_dur = value;
+ if(MLSLSerialWriteSingle(accel_adapter, BMA023_I2C_ADDR,
BMA023_LG_DURATION_REG, aconfig.lg_dur)){
+ printk("%s: Can't set low g duration\n",__func__);
+ return -1;
+ }
+ return 0;
+}
+
+int bma023_set_lg_threshold(struct i2c_adapter *accel_adapter, const
char *buf){
+ int value;
+ value = atoi(buf);
+ if(value > 255)
+ aconfig.lg_thres = 0xFF;
+ else if(value < 0)
+ aconfig.lg_thres = 0x00;
+ else
+ aconfig.lg_thres = value;
+ if(MLSLSerialWriteSingle(accel_adapter, BMA023_I2C_ADDR,
BMA023_LG_THRESHOLD_REG, aconfig.lg_thres)){
+ printk("%s: Can't set low g threshold\n",__func__);
+ return -1;
+ }
+ return 0;
+}
+
+static int bma023_set_config(void *mlsl_handle,
+ struct
ext_slave_platform_data *pdata){
+ int result = 0 ;
+ unsigned char reg = 0;
+
+ // 0x14 Bandwidth & Range
+ reg = 0;
+ result = MLSLSerialRead(mlsl_handle, pdata->address,
BMA023_RANGE_BWIDTH_REG, 1, ®);
+ ERROR_CHECK(result);
+ reg &= 0xe0;
+ reg |= aconfig.range_bandwidth; // Bandwidth 3=190
+ result = MLSLSerialWriteSingle(mlsl_handle, pdata->address,
BMA023_RANGE_BWIDTH_REG, reg );
+ ERROR_CHECK(result);
+
+ // 0x11 Any_motion_dur, HG_hyst, LG_hyst
+ result = MLSLSerialWriteSingle(mlsl_handle, pdata->address,
BMA023_HYSTERESIS_REG, aconfig.hg_lg_hyst);
+ ERROR_CHECK(result);
+
+ // 0x10 Any Motion Threshold
+ result = MLSLSerialWriteSingle(mlsl_handle, pdata->address,
BMA023_MOTION_THRS_REG, aconfig.any_motion_thres);
+ ERROR_CHECK(result);
+
+ // 0x0F HG Duration
+ result = MLSLSerialWriteSingle(mlsl_handle, pdata->address,
BMA023_HG_DURATION_REG, aconfig.hg_dur);
+ ERROR_CHECK(result);
+
+ // 0x0E HG Threshold
+ result = MLSLSerialWriteSingle(mlsl_handle, pdata->address,
BMA023_HG_THRESHOLD_REG, aconfig.hg_thres);
+ ERROR_CHECK(result);
+
+ // 0x0D LG duration
+ result = MLSLSerialWriteSingle(mlsl_handle, pdata->address,
BMA023_LG_DURATION_REG, aconfig.lg_dur);
+ ERROR_CHECK(result);
+
+ // 0x0C LG Threshold
+ result = MLSLSerialWriteSingle(mlsl_handle, pdata->address,
BMA023_LG_THRESHOLD_REG, aconfig.lg_thres);
+ ERROR_CHECK(result);
+
+ // 0x0B Interrupt mode
+ result = MLSLSerialWriteSingle(mlsl_handle, pdata->address,
BMA023_CONF1_REG, aconfig.enable_count_hg_lg);
+ ERROR_CHECK(result);
+
+ return result;
+}
+
+static int bma023_suspend(void *mlsl_handle,
+ struct ext_slave_descr *slave,
+ struct ext_slave_platform_data *pdata)
+{
+ int result;
+ result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x0a,
0x01);
+ return result;
+}
+
+// full scale setting - register and mask
+#define ACCEL_BOSCH_CTRL_REG (0x14)
+#define ACCEL_BOSCH_CTRL_MASK (0x18)
+
+static int bma023_resume(void *mlsl_handle,
+ struct ext_slave_descr *slave,
+ struct ext_slave_platform_data *pdata)
+{
+ int result;
+
+ /* Soft reset */
+ result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x0a,
0x02 );
+ ERROR_CHECK(result);
+ msleep(10);
+
+ result = bma023_set_config( mlsl_handle, pdata );
+ ERROR_CHECK(result);
+
+ return result;
+}
+
+static int bma023_read(void *mlsl_handle,
+ struct ext_slave_descr *slave,
+ struct ext_slave_platform_data *pdata,
+ unsigned char * data)
+{
+ return ML_ERROR_FEATURE_NOT_IMPLEMENTED;
+}
+
+static struct ext_slave_descr bma023_descr = {
+ /*.suspend = */ bma023_suspend,
+ /*.resume = */ bma023_resume,
+ /*.read = */ bma023_read,
+ /*.name = */ "bma023",
+ /*.type = */ EXT_SLAVE_TYPE_ACCELEROMETER,
+ /*.id = */ ACCEL_ID_BMA023,
+ /*.reg = */ 0x02,
+ /*.len = */ 6,
+ /*.endian = */ EXT_SLAVE_LITTLE_ENDIAN,
+ /*.range = */ { 2, 0 },
+};
+
+struct ext_slave_descr* bma023_get_slave_descr(void)
+{
+ return &bma023_descr;
+}
+EXPORT_SYMBOL(bma023_get_slave_descr);
+
+EXPORT_SYMBOL(bma023_read_accel_xyz);
+EXPORT_SYMBOL(bma023_get_power_mode);
+EXPORT_SYMBOL(bma023_get_bandwidth);
+EXPORT_SYMBOL(bma023_set_bandwidth);
+EXPORT_SYMBOL(bma023_get_range);
+EXPORT_SYMBOL(bma023_set_range);
+EXPORT_SYMBOL(bma023_set_hg_duration);
+EXPORT_SYMBOL(bma023_set_hg_threshold);
+EXPORT_SYMBOL(bma023_set_lg_duration);
+EXPORT_SYMBOL(bma023_set_lg_threshold);
+
+MODULE_AUTHOR("Wistron");
+MODULE_DESCRIPTION("User space IRQ handler for MPU3xxx devices");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("bma");
+
Index: linux-2.6.35/drivers/misc/mpu3050/accel/bma023.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.35/drivers/misc/mpu3050/accel/bma023.h 2010-12-24
11:14:28.000000000 +0800
@@ -0,0 +1,653 @@
+/* $Date: 2009/03/24 18:34:52 $
+ * $Revision: 1.8 $
+ */
+
+/*
+ * Copyright (C) 2009 Bosch Sensortec GmbH
+ *
+ * BMA023 acceleration sensor API
+ *
+ * Usage: Application Programming Interface for BMA023
configuration and data read out
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you
may not use this file except in
+ compliance with the License and the following stipulations. The
Apache License , Version 2.0 is applicable unless
+ otherwise stated by the stipulations of the disclaimer below.
+
+ * You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+
+
+ Disclaimer
+ *
+ * Common:
+ * This Work is developed for the consumer goods industry. It may only
be used
+ * within the parameters of the respective valid product data sheet.
The Work
+ * provided with the express understanding that there is no warranty of
fitness for a particular purpose.
+ * It is not fit for use in life-sustaining, safety or security
sensitive systems or any system or device
+ * that may lead to bodily harm or property damage if the system or
device malfunctions. In addition,
+ * the Work is not fit for use in products which interact with motor
vehicle systems.
+ * The resale and/or use of the Work are at the purchaser?s own risk
and his own responsibility. The
+ * examination of fitness for the intended use is the sole
responsibility of the Purchaser.
+ *
+ * The purchaser shall indemnify Bosch Sensortec from all third party
claims, including any claims for
+ * incidental, or consequential damages, arising from any Work or
Derivative Work use not covered by the parameters of
+ * the respective valid product data sheet or not approved by Bosch
Sensortec and reimburse Bosch
+ * Sensortec for all costs in connection with such claims.
+ *
+ * The purchaser must monitor the market for the purchased Work and
Derivative Works, particularly with regard to
+ * product safety and inform Bosch Sensortec without delay of all
security relevant incidents.
+ *
+ * Engineering Samples are marked with an asterisk (*) or (e). Samples
may vary from the valid
+ * technical specifications of the product series. They are therefore
not intended or fit for resale to third
+ * parties or for use in end products. Their sole purpose is internal
client testing. The testing of an
+ * engineering sample may in no way replace the testing of a product
series. Bosch Sensortec
+ * assumes no liability for the use of engineering samples. By
accepting the engineering samples, the
+ * Purchaser agrees to indemnify Bosch Sensortec from all claims
arising from the use of engineering
+ * samples.
+ *
+ * Special:
+ * This Work and any related information (hereinafter called
"Information") is provided free of charge
+ * for the sole purpose to support your application work. The Woek and
Information is subject to the
+ * following terms and conditions:
+ *
+ * The Work is specifically designed for the exclusive use for Bosch
Sensortec products by
+ * personnel who have special experience and training. Do not use this
Work or Derivative Works if you do not have the
+ * proper experience or training. Do not use this Work or Derivative
Works fot other products than Bosch Sensortec products.
+ *
+ * The Information provided is believed to be accurate and reliable.
Bosch Sensortec assumes no
+ * responsibility for the consequences of use of such Information nor
for any infringement of patents or
+ * other rights of third parties which may result from its use. No
license is granted by implication or
+ * otherwise under any patent or patent rights of Bosch. Specifications
mentioned in the Information are
+ * subject to change without notice.
+ */
+
+#include <linux/i2c.h>
+#include "mpu3050.h"
+#include "mldl_cfg.h"
+
+struct accel_config {
+ unsigned char int_latch; // byte 0x15
+ unsigned char range_bandwidth; // byte 0x14
+ unsigned char hg_lg_hyst; // byte 0x11
+ unsigned char any_motion_thres; // byte 0x10
+ unsigned char hg_dur; // byte 0x0f
+ unsigned char hg_thres; // byte 0x0e
+ unsigned char lg_dur; // byte 0x0d
+ unsigned char lg_thres; // byte 0x0c
+ unsigned char enable_count_hg_lg; // byte 0x0b
+// unsigned char reset_sleep; // byte 0x0a
+};
+
+struct accel_config *accel_get_config(void);
+
+int bma023_read_accel_xyz(struct i2c_adapter *, struct mldl_cfg *,
signed short *);
+unsigned char bma023_get_power_mode(struct i2c_adapter *, struct
mldl_cfg *mldl_cfg);
+int bma023_get_bandwidth(void);
+int bma023_set_bandwidth(struct i2c_adapter *, const char *);
+int bma023_get_range(void);
+int bma023_set_range(struct i2c_adapter *, const char *);
+int bma023_set_hg_duration(struct i2c_adapter *, const char *);
+int bma023_set_hg_threshold(struct i2c_adapter *, const char *);
+int bma023_set_lg_duration(struct i2c_adapter *, const char *);
+int bma023_set_lg_threshold(struct i2c_adapter *, const char *);
+
+/** BMA023 I2C Address
+*/
+
+#define BMA023_I2C_ADDR 0x38
+
+/*
+ *
+ * register definitions
+ *
+ */
+
+#define BMA023_EEP_OFFSET 0x20
+#define BMA023_IMAGE_BASE 0x0b
+#define BMA023_IMAGE_LEN 19
+
+#define BMA023_CHIP_ID_REG 0x00
+#define BMA023_VERSION_REG 0x01
+#define BMA023_X_AXIS_LSB_REG 0x02
+#define BMA023_X_AXIS_MSB_REG 0x03
+#define BMA023_Y_AXIS_LSB_REG 0x04
+#define BMA023_Y_AXIS_MSB_REG 0x05
+#define BMA023_Z_AXIS_LSB_REG 0x06
+#define BMA023_Z_AXIS_MSB_REG 0x07
+#define BMA023_TEMP_RD_REG 0x08
+#define BMA023_STATUS_REG 0x09
+#define BMA023_CTRL_REG 0x0a
+#define BMA023_CONF1_REG 0x0b
+#define BMA023_LG_THRESHOLD_REG 0x0c
+#define BMA023_LG_DURATION_REG 0x0d
+#define BMA023_HG_THRESHOLD_REG 0x0e
+#define BMA023_HG_DURATION_REG 0x0f
+#define BMA023_MOTION_THRS_REG 0x10
+#define BMA023_HYSTERESIS_REG 0x11
+#define BMA023_CUSTOMER1_REG 0x12
+#define BMA023_CUSTOMER2_REG 0x13
+#define BMA023_RANGE_BWIDTH_REG 0x14
+#define BMA023_CONF2_REG 0x15
+
+#define BMA023_OFFS_GAIN_X_REG 0x16
+#define BMA023_OFFS_GAIN_Y_REG 0x17
+#define BMA023_OFFS_GAIN_Z_REG 0x18
+#define BMA023_OFFS_GAIN_T_REG 0x19
+#define BMA023_OFFSET_X_REG 0x1a
+#define BMA023_OFFSET_Y_REG 0x1b
+#define BMA023_OFFSET_Z_REG 0x1c
+#define BMA023_OFFSET_T_REG 0x1d
+
+/* register write and read delays */
+
+#define BMA023_MDELAY_DATA_TYPE unsigned int
+#define BMA023_EE_W_DELAY 28 /* delay after EEP write is 28 msec */
+
+/** BMA023 image registers data structure
+ \brief Register type that contains all BMA023 image registers
from address 0x0b to 0x15
+ This structure can hold the complete image data of BMA023
+*/
+
+/*
+ *
+ * bit slice positions in registers
+ *
+ */
+
+/* cond BITSLICE */
+#define BMA023_CHIP_ID__POS 0
+#define BMA023_CHIP_ID__MSK 0x07
+#define BMA023_CHIP_ID__LEN 3
+#define BMA023_CHIP_ID__REG BMA023_CHIP_ID_REG
+
+#define BMA023_ML_VERSION__POS 0
+#define BMA023_ML_VERSION__LEN 4
+#define BMA023_ML_VERSION__MSK 0x0F
+#define BMA023_ML_VERSION__REG BMA023_VERSION_REG
+
+#define BMA023_AL_VERSION__POS 4
+#define BMA023_AL_VERSION__LEN 4
+#define BMA023_AL_VERSION__MSK 0xF0
+#define BMA023_AL_VERSION__REG BMA023_VERSION_REG
+
+/* DATA REGISTERS */
+
+#define BMA023_NEW_DATA_X__POS 0
+#define BMA023_NEW_DATA_X__LEN 1
+#define BMA023_NEW_DATA_X__MSK 0x01
+#define BMA023_NEW_DATA_X__REG BMA023_X_AXIS_LSB_REG
+
+#define BMA023_ACC_X_LSB__POS 6
+#define BMA023_ACC_X_LSB__LEN 2
+#define BMA023_ACC_X_LSB__MSK 0xC0
+#define BMA023_ACC_X_LSB__REG BMA023_X_AXIS_LSB_REG
+
+#define BMA023_ACC_X_MSB__POS 0
+#define BMA023_ACC_X_MSB__LEN 8
+#define BMA023_ACC_X_MSB__MSK 0xFF
+#define BMA023_ACC_X_MSB__REG BMA023_X_AXIS_MSB_REG
+
+#define BMA023_NEW_DATA_Y__POS 0
+#define BMA023_NEW_DATA_Y__LEN 1
+#define BMA023_NEW_DATA_Y__MSK 0x01
+#define BMA023_NEW_DATA_Y__REG BMA023_Y_AXIS_LSB_REG
+
+#define BMA023_ACC_Y_LSB__POS 6
+#define BMA023_ACC_Y_LSB__LEN 2
+#define BMA023_ACC_Y_LSB__MSK 0xC0
+#define BMA023_ACC_Y_LSB__REG BMA023_Y_AXIS_LSB_REG
+
+#define BMA023_ACC_Y_MSB__POS 0
+#define BMA023_ACC_Y_MSB__LEN 8
+#define BMA023_ACC_Y_MSB__MSK 0xFF
+#define BMA023_ACC_Y_MSB__REG BMA023_Y_AXIS_MSB_REG
+
+#define BMA023_NEW_DATA_Z__POS 0
+#define BMA023_NEW_DATA_Z__LEN 1
+#define BMA023_NEW_DATA_Z__MSK 0x01
+#define BMA023_NEW_DATA_Z__REG BMA023_Z_AXIS_LSB_REG
+
+#define BMA023_ACC_Z_LSB__POS 6
+#define BMA023_ACC_Z_LSB__LEN 2
+#define BMA023_ACC_Z_LSB__MSK 0xC0
+#define BMA023_ACC_Z_LSB__REG BMA023_Z_AXIS_LSB_REG
+
+#define BMA023_ACC_Z_MSB__POS 0
+#define BMA023_ACC_Z_MSB__LEN 8
+#define BMA023_ACC_Z_MSB__MSK 0xFF
+#define BMA023_ACC_Z_MSB__REG BMA023_Z_AXIS_MSB_REG
+
+#define BMA023_TEMPERATURE__POS 0
+#define BMA023_TEMPERATURE__LEN 8
+#define BMA023_TEMPERATURE__MSK 0xFF
+#define BMA023_TEMPERATURE__REG BMA023_TEMP_RD_REG
+
+/* STATUS BITS */
+
+#define BMA023_STATUS_HG__POS 0
+#define BMA023_STATUS_HG__LEN 1
+#define BMA023_STATUS_HG__MSK 0x01
+#define BMA023_STATUS_HG__REG BMA023_STATUS_REG
+
+#define BMA023_STATUS_LG__POS 1
+#define BMA023_STATUS_LG__LEN 1
+#define BMA023_STATUS_LG__MSK 0x02
+#define BMA023_STATUS_LG__REG BMA023_STATUS_REG
+
+#define BMA023_HG_LATCHED__POS 2
+#define BMA023_HG_LATCHED__LEN 1
+#define BMA023_HG_LATCHED__MSK 0x04
+#define BMA023_HG_LATCHED__REG BMA023_STATUS_REG
+
+#define BMA023_LG_LATCHED__POS 3
+#define BMA023_LG_LATCHED__LEN 1
+#define BMA023_LG_LATCHED__MSK 8
+#define BMA023_LG_LATCHED__REG BMA023_STATUS_REG
+
+#define BMA023_ALERT_PHASE__POS 4
+#define BMA023_ALERT_PHASE__LEN 1
+#define BMA023_ALERT_PHASE__MSK 0x10
+#define BMA023_ALERT_PHASE__REG BMA023_STATUS_REG
+
+#define BMA023_ST_RESULT__POS 7
+#define BMA023_ST_RESULT__LEN 1
+#define BMA023_ST_RESULT__MSK 0x80
+#define BMA023_ST_RESULT__REG BMA023_STATUS_REG
+
+/* CONTROL BITS */
+
+#define BMA023_SLEEP__POS 0
+#define BMA023_SLEEP__LEN 1
+#define BMA023_SLEEP__MSK 0x01
+#define BMA023_SLEEP__REG BMA023_CTRL_REG
+
+#define BMA023_SOFT_RESET__POS 1
+#define BMA023_SOFT_RESET__LEN 1
+#define BMA023_SOFT_RESET__MSK 0x02
+#define BMA023_SOFT_RESET__REG BMA023_CTRL_REG
+
+#define BMA023_SELF_TEST__POS 2
+#define BMA023_SELF_TEST__LEN 2
+#define BMA023_SELF_TEST__MSK 0x0C
+#define BMA023_SELF_TEST__REG BMA023_CTRL_REG
+
+#define BMA023_SELF_TEST0__POS 2
+#define BMA023_SELF_TEST0__LEN 1
+#define BMA023_SELF_TEST0__MSK 0x04
+#define BMA023_SELF_TEST0__REG BMA023_CTRL_REG
+
+#define BMA023_SELF_TEST1__POS 3
+#define BMA023_SELF_TEST1__LEN 1
+#define BMA023_SELF_TEST1__MSK 0x08
+#define BMA023_SELF_TEST1__REG BMA023_CTRL_REG
+
+#define BMA023_EE_W__POS 4
+#define BMA023_EE_W__LEN 1
+#define BMA023_EE_W__MSK 0x10
+#define BMA023_EE_W__REG BMA023_CTRL_REG
+
+#define BMA023_UPDATE_IMAGE__POS 5
+#define BMA023_UPDATE_IMAGE__LEN 1
+#define BMA023_UPDATE_IMAGE__MSK 0x20
+#define BMA023_UPDATE_IMAGE__REG BMA023_CTRL_REG
+
+#define BMA023_RESET_INT__POS 6
+#define BMA023_RESET_INT__LEN 1
+#define BMA023_RESET_INT__MSK 0x40
+#define BMA023_RESET_INT__REG BMA023_CTRL_REG
+
+/* LOW-G, HIGH-G settings */
+
+#define BMA023_ENABLE_LG__POS 0
+#define BMA023_ENABLE_LG__LEN 1
+#define BMA023_ENABLE_LG__MSK 0x01
+#define BMA023_ENABLE_LG__REG BMA023_CONF1_REG
+
+#define BMA023_ENABLE_HG__POS 1
+#define BMA023_ENABLE_HG__LEN 1
+#define BMA023_ENABLE_HG__MSK 0x02
+#define BMA023_ENABLE_HG__REG BMA023_CONF1_REG
+
+/* LG/HG counter */
+
+#define BMA023_COUNTER_LG__POS 2
+#define BMA023_COUNTER_LG__LEN 2
+#define BMA023_COUNTER_LG__MSK 0x0C
+#define BMA023_COUNTER_LG__REG BMA023_CONF1_REG
+
+#define BMA023_COUNTER_HG__POS 4
+#define BMA023_COUNTER_HG__LEN 2
+#define BMA023_COUNTER_HG__MSK 0x30
+#define BMA023_COUNTER_HG__REG BMA023_CONF1_REG
+
+/* LG/HG duration is in ms */
+
+#define BMA023_LG_DUR__POS 0
+#define BMA023_LG_DUR__LEN 8
+#define BMA023_LG_DUR__MSK 0xFF
+#define BMA023_LG_DUR__REG BMA023_LG_DURATION_REG
+
+#define BMA023_HG_DUR__POS 0
+#define BMA023_HG_DUR__LEN 8
+#define BMA023_HG_DUR__MSK 0xFF
+#define BMA023_HG_DUR__REG BMA023_HG_DURATION_REG
+
+#define BMA023_LG_THRES__POS 0
+#define BMA023_LG_THRES__LEN 8
+#define BMA023_LG_THRES__MSK 0xFF
+#define BMA023_LG_THRES__REG BMA023_LG_THRESHOLD_REG
+
+#define BMA023_HG_THRES__POS 0
+#define BMA023_HG_THRES__LEN 8
+#define BMA023_HG_THRES__MSK 0xFF
+#define BMA023_HG_THRES__REG BMA023_HG_THRESHOLD_REG
+
+#define BMA023_LG_HYST__POS 0
+#define BMA023_LG_HYST__LEN 3
+#define BMA023_LG_HYST__MSK 0x07
+#define BMA023_LG_HYST__REG BMA023_HYSTERESIS_REG
+
+#define BMA023_HG_HYST__POS 3
+#define BMA023_HG_HYST__LEN 3
+#define BMA023_HG_HYST__MSK 0x38
+#define BMA023_HG_HYST__REG BMA023_HYSTERESIS_REG
+
+/* ANY MOTION and ALERT settings */
+
+#define BMA023_EN_ANY_MOTION__POS 6
+#define BMA023_EN_ANY_MOTION__LEN 1
+#define BMA023_EN_ANY_MOTION__MSK 0x40
+#define BMA023_EN_ANY_MOTION__REG BMA023_CONF1_REG
+
+/* ALERT settings */
+
+#define BMA023_ALERT__POS 7
+#define BMA023_ALERT__LEN 1
+#define BMA023_ALERT__MSK 0x80
+#define BMA023_ALERT__REG BMA023_CONF1_REG
+
+/* ANY MOTION Duration */
+
+#define BMA023_ANY_MOTION_THRES__POS 0
+#define BMA023_ANY_MOTION_THRES__LEN 8
+#define BMA023_ANY_MOTION_THRES__MSK 0xFF
+#define BMA023_ANY_MOTION_THRES__REG BMA023_MOTION_THRS_REG
+
+#define BMA023_ANY_MOTION_DUR__POS 6
+#define BMA023_ANY_MOTION_DUR__LEN 2
+#define BMA023_ANY_MOTION_DUR__MSK 0xC0
+#define BMA023_ANY_MOTION_DUR__REG BMA023_HYSTERESIS_REG
+
+#define BMA023_CUSTOMER_RESERVED1__POS 0
+#define BMA023_CUSTOMER_RESERVED1__LEN 8
+#define BMA023_CUSTOMER_RESERVED1__MSK 0xFF
+#define BMA023_CUSTOMER_RESERVED1__REG BMA023_CUSTOMER1_REG
+
+#define BMA023_CUSTOMER_RESERVED2__POS 0
+#define BMA023_CUSTOMER_RESERVED2__LEN 8
+#define BMA023_CUSTOMER_RESERVED2__MSK 0xFF
+#define BMA023_CUSTOMER_RESERVED2__REG BMA023_CUSTOMER2_REG
+
+/* BANDWIDTH dependend definitions */
+
+#define BMA023_BANDWIDTH__POS 0
+#define BMA023_BANDWIDTH__LEN 3
+#define BMA023_BANDWIDTH__MSK 0x07
+#define BMA023_BANDWIDTH__REG
BMA023_RANGE_BWIDTH_REG
+
+/* RANGE */
+
+#define BMA023_RANGE__POS 3
+#define BMA023_RANGE__LEN 2
+#define BMA023_RANGE__MSK 0x18
+#define BMA023_RANGE__REG
BMA023_RANGE_BWIDTH_REG
+
+/* WAKE UP */
+
+#define BMA023_WAKE_UP__POS 0
+#define BMA023_WAKE_UP__LEN 1
+#define BMA023_WAKE_UP__MSK 0x01
+#define BMA023_WAKE_UP__REG BMA023_CONF2_REG
+
+#define BMA023_WAKE_UP_PAUSE__POS 1
+#define BMA023_WAKE_UP_PAUSE__LEN 2
+#define BMA023_WAKE_UP_PAUSE__MSK 0x06
+#define BMA023_WAKE_UP_PAUSE__REG BMA023_CONF2_REG
+
+/* ACCELERATION DATA SHADOW */
+
+#define BMA023_SHADOW_DIS__POS 3
+#define BMA023_SHADOW_DIS__LEN 1
+#define BMA023_SHADOW_DIS__MSK 0x08
+#define BMA023_SHADOW_DIS__REG BMA023_CONF2_REG
+
+/* LATCH Interrupt */
+
+#define BMA023_LATCH_INT__POS 4
+#define BMA023_LATCH_INT__LEN 1
+#define BMA023_LATCH_INT__MSK 0x10
+#define BMA023_LATCH_INT__REG BMA023_CONF2_REG
+
+/* new data interrupt */
+
+#define BMA023_NEW_DATA_INT__POS 5
+#define BMA023_NEW_DATA_INT__LEN 1
+#define BMA023_NEW_DATA_INT__MSK 0x20
+#define BMA023_NEW_DATA_INT__REG BMA023_CONF2_REG
+
+#define BMA023_ENABLE_ADV_INT__POS 6
+#define BMA023_ENABLE_ADV_INT__LEN 1
+#define BMA023_ENABLE_ADV_INT__MSK 0x40
+#define BMA023_ENABLE_ADV_INT__REG BMA023_CONF2_REG
+
+#define BMA023_BMA023_SPI4_OFF 0
+#define BMA023_BMA023_SPI4_ON 1
+
+#define BMA023_SPI4__POS 7
+#define BMA023_SPI4__LEN 1
+#define BMA023_SPI4__MSK 0x80
+#define BMA023_SPI4__REG BMA023_CONF2_REG
+
+#define BMA023_OFFSET_X_LSB__POS 6
+#define BMA023_OFFSET_X_LSB__LEN 2
+#define BMA023_OFFSET_X_LSB__MSK 0xC0
+#define BMA023_OFFSET_X_LSB__REG BMA023_OFFS_GAIN_X_REG
+
+#define BMA023_GAIN_X__POS 0
+#define BMA023_GAIN_X__LEN 6
+#define BMA023_GAIN_X__MSK 0x3f
+#define BMA023_GAIN_X__REG BMA023_OFFS_GAIN_X_REG
+
+#define BMA023_OFFSET_Y_LSB__POS 6
+#define BMA023_OFFSET_Y_LSB__LEN 2
+#define BMA023_OFFSET_Y_LSB__MSK 0xC0
+#define BMA023_OFFSET_Y_LSB__REG BMA023_OFFS_GAIN_Y_REG
+
+#define BMA023_GAIN_Y__POS 0
+#define BMA023_GAIN_Y__LEN 6
+#define BMA023_GAIN_Y__MSK 0x3f
+#define BMA023_GAIN_Y__REG BMA023_OFFS_GAIN_Y_REG
+
+#define BMA023_OFFSET_Z_LSB__POS 6
+#define BMA023_OFFSET_Z_LSB__LEN 2
+#define BMA023_OFFSET_Z_LSB__MSK 0xC0
+#define BMA023_OFFSET_Z_LSB__REG BMA023_OFFS_GAIN_Z_REG
+
+#define BMA023_GAIN_Z__POS 0
+#define BMA023_GAIN_Z__LEN 6
+#define BMA023_GAIN_Z__MSK 0x3f
+#define BMA023_GAIN_Z__REG BMA023_OFFS_GAIN_Z_REG
+
+#define BMA023_OFFSET_T_LSB__POS 6
+#define BMA023_OFFSET_T_LSB__LEN 2
+#define BMA023_OFFSET_T_LSB__MSK 0xC0
+#define BMA023_OFFSET_T_LSB__REG BMA023_OFFS_GAIN_T_REG
+
+#define BMA023_GAIN_T__POS 0
+#define BMA023_GAIN_T__LEN 6
+#define BMA023_GAIN_T__MSK 0x3f
+#define BMA023_GAIN_T__REG BMA023_OFFS_GAIN_T_REG
+
+#define BMA023_OFFSET_X_MSB__POS 0
+#define BMA023_OFFSET_X_MSB__LEN 8
+#define BMA023_OFFSET_X_MSB__MSK 0xFF
+#define BMA023_OFFSET_X_MSB__REG BMA023_OFFSET_X_REG
+
+#define BMA023_OFFSET_Y_MSB__POS 0
+#define BMA023_OFFSET_Y_MSB__LEN 8
+#define BMA023_OFFSET_Y_MSB__MSK 0xFF
+#define BMA023_OFFSET_Y_MSB__REG BMA023_OFFSET_Y_REG
+
+#define BMA023_OFFSET_Z_MSB__POS 0
+#define BMA023_OFFSET_Z_MSB__LEN 8
+#define BMA023_OFFSET_Z_MSB__MSK 0xFF
+#define BMA023_OFFSET_Z_MSB__REG BMA023_OFFSET_Z_REG
+
+#define BMA023_OFFSET_T_MSB__POS 0
+#define BMA023_OFFSET_T_MSB__LEN 8
+#define BMA023_OFFSET_T_MSB__MSK 0xFF
+#define BMA023_OFFSET_T_MSB__REG BMA023_OFFSET_T_REG
+
+#define BMA023_GET_BITSLICE(regvar, bitname)\
+ (regvar & bitname##__MSK) >> bitname##__POS
+
+#define BMA023_SET_BITSLICE(regvar, bitname, val)\
+ (regvar & ~bitname##__MSK) |
((val<<bitname##__POS)&bitname##__MSK)
+
+/* CONSTANTS */
+/* range and bandwidth */
+
+#define BMA023_RANGE_2G 0 /**< sets range to 2G
mode \see bma023_set_range() */
+#define BMA023_RANGE_4G 1 /**< sets range to 4G
mode \see bma023_set_range() */
+#define BMA023_RANGE_8G 2 /**< sets range to 8G
mode \see bma023_set_range() */
+
+#define BMA023_BW_25HZ 0 /**< sets bandwidth to 25HZ \see
bma023_set_bandwidth() */
+#define BMA023_BW_50HZ 1 /**< sets bandwidth to 50HZ \see
bma023_set_bandwidth() */
+#define BMA023_BW_100HZ 2 /**< sets bandwidth to
100HZ \see bma023_set_bandwidth() */
+#define BMA023_BW_190HZ 3 /**< sets bandwidth to
190HZ \see bma023_set_bandwidth() */
+#define BMA023_BW_375HZ 4 /**< sets bandwidth to
375HZ \see bma023_set_bandwidth() */
+#define BMA023_BW_750HZ 5 /**< sets bandwidth to
750HZ \see bma023_set_bandwidth() */
+#define BMA023_BW_1500HZ 6 /**< sets bandwidth to 1500HZ
\see bma023_set_bandwidth() */
+
+/* mode settings */
+
+#define BMA023_MODE_NORMAL 0
+#define BMA023_MODE_SLEEP 2
+#define BMA023_MODE_WAKE_UP 3
+
+/* wake up */
+
+#define BMA023_WAKE_UP_PAUSE_20MS 0
+#define BMA023_WAKE_UP_PAUSE_80MS 1
+#define BMA023_WAKE_UP_PAUSE_320MS 2
+#define BMA023_WAKE_UP_PAUSE_2560MS 3
+
+/* LG/HG thresholds are in LSB and depend on RANGE setting */
+/* no range check on threshold calculation */
+
+#define BMA023_SELF_TEST0_ON 1
+#define BMA023_SELF_TEST1_ON 2
+
+#define BMA023_EE_W_OFF 0
+#define BMA023_EE_W_ON 1
+
+/* low-g, high-g, any_motion */
+
+#define BMA023_COUNTER_LG_RST 0
+#define BMA023_COUNTER_LG_0LSB BMA023_COUNTER_LG_RST
+#define BMA023_COUNTER_LG_1LSB 1
+#define BMA023_COUNTER_LG_2LSB 2
+#define BMA023_COUNTER_LG_3LSB 3
+
+#define BMA023_COUNTER_HG_RST 0
+#define BMA023_COUNTER_HG_0LSB BMA023_COUNTER_HG_RST
+#define BMA023_COUNTER_HG_1LSB 1
+#define BMA023_COUNTER_HG_2LSB 2
+#define BMA023_COUNTER_HG_3LSB 3
+
+#define BMA023_COUNTER_RST 0
+#define BMA023_COUNTER_0LSB BMA023_COUNTER_RST
+#define BMA023_COUNTER_1LSB 1
+#define BMA023_COUNTER_2LSB 2
+#define BMA023_COUNTER_3LSB 3
+
+/** Macro to convert floating point low-g-thresholds in G to 8-bit
register values.<br>
+ * Example: BMA023_LG_THRES_IN_G( 0.3, 2.0) generates the register
value for 0.3G threshold in 2G mode.
+ * \brief convert g-values to 8-bit value
+ */
+#define BMA023_LG_THRES_IN_G( gthres, range) ((256 *
gthres ) / range)
+
+/** Macro to convert floating point high-g-thresholds in G to 8-bit
register values.<br>
+ * Example: BMA023_HG_THRES_IN_G( 1.4, 2.0) generates the register
value for 1.4G threshold in 2G mode.
+ * \brief convert g-values to 8-bit value
+ */
+#define BMA023_HG_THRES_IN_G(gthres, range)
((256 * gthres ) / range)
+
+/** Macro to convert floating point low-g-hysteresis in G to 8-bit
register values.<br>
+ * Example: BMA023_LG_HYST_THRES_IN_G( 0.2, 2.0) generates the
register value for 0.2G threshold in 2G mode.
+ * \brief convert g-values to 8-bit value
+ */
+#define BMA023_LG_HYST_IN_G( ghyst, range )
((32 * ghyst) / range)
+
+/** Macro to convert floating point high-g-hysteresis in G to 8-bit
register values.<br>
+ * Example: BMA023_HG_HYST_THRES_IN_G( 0.2, 2.0) generates the
register value for 0.2G threshold in 2G mode.
+ * \brief convert g-values to 8-bit value
+ */
+#define BMA023_HG_HYST_IN_G( ghyst, range )
((32 * ghyst) / range)
+
+/** Macro to convert floating point G-thresholds to 8-bit register
values<br>
+ * Example: BMA023_ANY_MOTION_THRES_IN_G( 1.2, 2.0) generates the
register value for 1.2G threshold in 2G mode.
+ * \brief convert g-values to 8-bit value
+ */
+
+#define BMA023_ANY_MOTION_THRES_IN_G( gthres, range) ((128 * gthres )
/ range)
+
+#define BMA023_ANY_MOTION_DUR_1 0
+#define BMA023_ANY_MOTION_DUR_3 1
+#define BMA023_ANY_MOTION_DUR_5 2
+#define BMA023_ANY_MOTION_DUR_7 3
+
+#define BMA023_SHADOW_DIS_OFF 0
+#define BMA023_SHADOW_DIS_ON 1
+
+#define BMA023_LATCH_INT_OFF 0
+#define BMA023_LATCH_INT_ON 1
+
+#define BMA023_NEW_DATA_INT_OFF 0
+#define BMA023_NEW_DATA_INT_ON 1
+
+#define BMA023_ENABLE_ADV_INT_OFF 0
+#define BMA023_ENABLE_ADV_INT_ON 1
+
+#define BMA023_EN_ANY_MOTION_OFF 0
+#define BMA023_EN_ANY_MOTION_ON 1
+
+#define BMA023_ALERT_OFF 0
+#define BMA023_ALERT_ON 1
+
+#define BMA023_ENABLE_LG_OFF 0
+#define BMA023_ENABLE_LG_ON 1
+
+#define BMA023_ENABLE_HG_OFF 0
+#define BMA023_ENABLE_HG_ON 1
+
+#define BMA023_INT_ALERT (1<<7)
+#define BMA023_INT_ANY_MOTION (1<<6)
+#define BMA023_INT_EN_ADV_INT (1<<5)
+#define BMA023_INT_NEW_DATA (1<<4)
+#define BMA023_INT_LATCH (1<<3)
+#define BMA023_INT_HG (1<<1)
+#define BMA023_INT_LG (1<<0)
+
+#define BMA023_INT_STATUS_HG (1<<0)
+#define BMA023_INT_STATUS_LG (1<<1)
+#define BMA023_INT_STATUS_HG_LATCHED (1<<2)
+#define BMA023_INT_STATUS_LG_LATCHED (1<<3)
+#define BMA023_INT_STATUS_ALERT (1<<4)
+#define BMA023_INT_STATUS_ST_RESULT (1<<7)
+
+#define BMA023_CONF1_INT_MSK ((1<<BMA023_ALERT__POS) |
(1<<BMA023_EN_ANY_MOTION__POS) | (1<<BMA023_ENABLE_HG__POS) |
(1<<BMA023_ENABLE_LG__POS))
+#define BMA023_CONF2_INT_MSK ((1<<BMA023_ENABLE_ADV_INT__POS) |
(1<<BMA023_NEW_DATA_INT__POS) | (1<<BMA023_LATCH_INT__POS))
Index: linux-2.6.35/drivers/misc/mpu3050/accel/bma150.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.35/drivers/misc/mpu3050/accel/bma150.c 2010-12-24
11:08:32.000000000 +0800
@@ -0,0 +1,133 @@
+/*
+ $License:
+ Copyright (C) 2010 InvenSense Corporation, All Rights Reserved.
+
+ This program is free software; you can redistribute it and/or
modify
+ it under the terms of the GNU General Public License as published
by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
<http://www.gnu.org/licenses/>.
+ $
+ */
+
+/**
+ * @defgroup ACCELDL (Motion Library - Accelerometer Driver Layer)
+ * @brief Provides the interface to setup and handle an
accelerometers
+ * connected to the secondary I2C interface of the
gyroscope.
+ *
+ * @{
+ * @file bma150.c
+ * @brief Accelerometer setup and handling methods.
+ */
+
+/* ------------------ */
+/* - Include Files. - */
+/* ------------------ */
+
+#include <linux/module.h>
+#include <linux/delay.h>
+
+#include "mpu.h"
+#include "mlsl.h"
+
+/* --------------------- */
+/* - Variables. - */
+/* --------------------- */
+
+/*********************************************
+ Accelerometer Initialization Functions
+**********************************************/
+
+static int bma150_suspend(void *mlsl_handle,
+ struct ext_slave_descr *slave,
+ struct ext_slave_platform_data *pdata)
+{
+ int result;
+ result =
+ MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x0a,
0x01);
+ msleep(3); /* 3 ms powerup time maximum */
+ ERROR_CHECK(result);
+ return result;
+}
+
+/* full scale setting - register and mask */
+#define ACCEL_BOSCH_CTRL_REG (0x14)
+#define ACCEL_BOSCH_CTRL_MASK (0x18)
+
+static int bma150_resume(void *mlsl_handle,
+ struct ext_slave_descr *slave,
+ struct ext_slave_platform_data *pdata)
+{
+ int result;
+ unsigned char reg = 0;
+
+ /* Soft reset */
+ result =
+ MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x0a,
0x02);
+ ERROR_CHECK(result);
+ msleep(10);
+
+ result =
+ MLSLSerialRead(mlsl_handle, pdata->address, 0x14, 1, ®);
+ ERROR_CHECK(result);
+
+ /* Bandwidth */
+ reg &= 0xc0;
+ reg |= 3; /* 3=190 Hz */
+
+ /* Full Scale */
+ reg &= ~ACCEL_BOSCH_CTRL_MASK;
+ if (slave->range.mantissa == 2)
+ reg |= 0x00;
+ else if (slave->range.mantissa == 4)
+ reg |= 0x08;
+ else if (slave->range.mantissa == 8)
+ reg |= 0x10;
+
+ result =
+ MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x14,
reg);
+ ERROR_CHECK(result);
+
+ return result;
+}
+
+static int bma150_read(void *mlsl_handle,
+ struct ext_slave_descr *slave,
+ struct ext_slave_platform_data *pdata,
+ unsigned char *data)
+{
+ return ML_ERROR_FEATURE_NOT_IMPLEMENTED;
+}
+
+static struct ext_slave_descr bma150_descr = {
+ /*.suspend = */ bma150_suspend,
+ /*.resume = */ bma150_resume,
+ /*.read = */ bma150_read,
+ /*.name = */ "bma150",
+ /*.type = */ EXT_SLAVE_TYPE_ACCELEROMETER,
+ /*.id = */ ACCEL_ID_BMA150,
+ /*.reg = */ 0x02,
+ /*.len = */ 6,
+ /*.endian = */ EXT_SLAVE_LITTLE_ENDIAN,
+ /*.range = */ {2, 0},
+};
+
+struct ext_slave_descr *bma150_get_slave_descr(void)
+{
+ return &bma150_descr;
+}
+
+EXPORT_SYMBOL(bma150_get_slave_descr);
+
+MODULE_AUTHOR("Wistron");
+MODULE_DESCRIPTION("User space IRQ handler for MPU3xxx devices");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("bma");
+
Index: linux-2.6.35/drivers/misc/mpu3050/accel/bma222.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.35/drivers/misc/mpu3050/accel/bma222.c 2010-12-24
11:18:55.000000000 +0800
@@ -0,0 +1,128 @@
+/*
+ $License:
+ Copyright (C) 2010 InvenSense Corporation, All Rights Reserved.
+
+ This program is free software; you can redistribute it and/or
modify
+ it under the terms of the GNU General Public License as published
by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
<http://www.gnu.org/licenses/>.
+ $
+ */
+
+/*
+ * @defgroup ACCELDL (Motion Library - Accelerometer Driver Layer)
+ * @brief Provides the interface to setup and handle an
accelerometers
+ * connected to the secondary I2C interface of the
gyroscope.
+ *
+ * @{
+ * @file bma222.c
+ * @brief Accelerometer setup and handling methods.
+ */
+
+/* ------------------ */
+/* - Include Files. - */
+/* ------------------ */
+
+#include <linux/module.h>
+#include <linux/delay.h>
+
+#include "mpu.h"
+#include "mlsl.h"
+
+#define ACCEL_BMA222_RANGE_REG (0x0F)
+#define ACCEL_BMA222_BW_REG (0x10)
+#define ACCEL_BMA222_SUSPEND_REG (0x11)
+#define ACCEL_BMA222_SFT_RST_REG (0x14)
+
+/*********************************************
+ Accelerometer Initialization Functions
+**********************************************/
+
+static int bma222_suspend(void *mlsl_handle,
+ struct ext_slave_descr *slave,
+ struct ext_slave_platform_data *pdata)
+{
+ int result;
+
+ result =
+ MLSLSerialWriteSingle(mlsl_handle, pdata->address,
+ ACCEL_BMA222_SUSPEND_REG, 0x80);
+ ERROR_CHECK(result);
+
+ return result;
+}
+
+static int bma222_resume(void *mlsl_handle,
+ struct ext_slave_descr *slave,
+ struct ext_slave_platform_data *pdata)
+{
+ int result;
+ unsigned char reg = 0;
+
+ /* Soft reset */
+ result =
+ MLSLSerialWriteSingle(mlsl_handle, pdata->address,
+ ACCEL_BMA222_SFT_RST_REG, 0xB6);
+ ERROR_CHECK(result);
+ msleep(10);
+
+ /*Bandwidth */
+ result =
+ MLSLSerialWriteSingle(mlsl_handle, pdata->address,
+ ACCEL_BMA222_BW_REG, 0x0C);
+ ERROR_CHECK(result);
+
+ /* Full Scale */
+ if (slave->range.mantissa == 2)
+ reg |= 0x03;
+ else if (slave->range.mantissa == 4)
+ reg |= 0x05;
+ else if (slave->range.mantissa == 8)
+ reg |= 0x08;
+ else if (slave->range.mantissa == 16)
+ reg |= 0x0C;
+
+ result =
+ MLSLSerialWriteSingle(mlsl_handle, pdata->address,
+ ACCEL_BMA222_RANGE_REG, reg);
+ ERROR_CHECK(result);
+
+ return result;
+}
+
+static int bma222_read(void *mlsl_handle,
+ struct ext_slave_descr *slave,
+ struct ext_slave_platform_data *pdata,
+ unsigned char *data)
+{
+ return ML_ERROR_FEATURE_NOT_IMPLEMENTED;
+}
+
+static struct ext_slave_descr bma222_descr = {
+ /*.suspend = */ bma222_suspend,
+ /*.resume = */ bma222_resume,
+ /*.read = */ bma222_read,
+ /*.name = */ "bma222",
+ /*.type = */ EXT_SLAVE_TYPE_ACCELEROMETER,
+ /*.id = */ ACCEL_ID_BMA222,
+ /*.reg = */ 0x02,
+ /*.len = */ 6,
+ /*.endian = */ EXT_SLAVE_LITTLE_ENDIAN,
+ /*.range = */ {2, 0},
+};
+
+struct ext_slave_descr *bma222_get_slave_descr(void)
+{
+ return &bma222_descr;
+}
+
+EXPORT_SYMBOL(bma222_get_slave_descr);
+
_______________________________________________
MeeGo-kernel mailing list
[email protected]
http://lists.meego.com/listinfo/meego-kernel