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-22 14:09:28.000000000 +0800 @@ -0,0 +1,142 @@ +/* + $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. - */ +/* ------------------ */ + +#ifdef __KERNEL__ +#include <linux/module.h> +#endif + +#include "mpu.h" +#include "mlos.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); + MLOSSleep(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); + MLOSSleep(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; +} + +#ifdef __KERNEL__ +EXPORT_SYMBOL(bma150_get_slave_descr); +#endif + +#ifdef __KERNEL__ +MODULE_AUTHOR("Wistron"); +MODULE_DESCRIPTION("User space IRQ handler for MPU3xxx devices"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("bma"); +#endif + +/** + * @} +**/ 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-22 14:09:28.000000000 +0800 @@ -0,0 +1,135 @@ +/* + $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. - */ +/* ------------------ */ + +#ifdef __KERNEL__ +#include <linux/module.h> +#endif + +#include "mpu.h" +#include "mlos.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); + MLOSSleep(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; +} + +#ifdef __KERNEL__ +EXPORT_SYMBOL(bma222_get_slave_descr); +#endif + +/* + * @} + */ Index: linux-2.6.35/drivers/misc/mpu3050/accel/kxsd9.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux-2.6.35/drivers/misc/mpu3050/accel/kxsd9.c 2010-12-22 14:09:28.000000000 +0800 @@ -0,0 +1,137 @@ +/* + $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 kxsd9.c + * @brief Accelerometer setup and handling methods. + */ + +/* ------------------ */ +/* - Include Files. - */ +/* ------------------ */ + +#ifdef __KERNEL__ +#include <linux/kernel.h> +#include <linux/module.h> +#endif + +#include "mpu.h" +#include "mlsl.h" +#include "mlos.h" + +#include <log.h> +#undef MPL_LOG_TAG +#define MPL_LOG_TAG "MPL-acc" + +/* --------------------- */ +/* - Variables. - */ +/* --------------------- */ + +/***************************************** + Accelerometer Initialization Functions +*****************************************/ + +static int kxsd9_suspend(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result; + (void *) slave; + /* CTRL_REGB: low-power standby mode */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x0d, 0x0); + ERROR_CHECK(result); + return result; +} + +/* full scale setting - register and mask */ +#define ACCEL_KIONIX_CTRL_REG (0x0C) +#define ACCEL_KIONIX_CTRL_MASK (0x3) + +static int kxsd9_resume(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result = ML_SUCCESS; + unsigned char reg; + + /* Full Scale */ + reg = 0x0; + reg &= ~ACCEL_KIONIX_CTRL_MASK; + reg |= 0x00; + if (slave->range.mantissa == 2) /* 2g scale = 2.5006 */ + reg |= 0x3; + else if (slave->range.mantissa == 4) /* 4g scale = 4.9951 */ + reg |= 0x2; + else if (slave->range.mantissa == 7) /* 6g scale = 7.5018 */ + reg |= 0x1; + else if (slave->range.mantissa == 9) /* 8g scale = 9.9902 */ + reg |= 0x0; + + reg |= 0xC0; /* 100Hz LPF */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_KIONIX_CTRL_REG, reg); + ERROR_CHECK(result); + /* normal operation */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x0d, 0x40); + ERROR_CHECK(result); + + return ML_SUCCESS; +} + +static int kxsd9_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 kxsd9_descr = { + /*.suspend = */ kxsd9_suspend, + /*.resume = */ kxsd9_resume, + /*.read = */ kxsd9_read, + /*.name = */ "kxsd9", + /*.type = */ EXT_SLAVE_TYPE_ACCELEROMETER, + /*.id = */ ACCEL_ID_KXSD9, + /*.reg = */ 0x00, + /*.len = */ 6, + /*.endian = */ EXT_SLAVE_BIG_ENDIAN, + /*.range = */ {2, 5006}, +}; + +struct ext_slave_descr *kxsd9_get_slave_descr(void) +{ + return &kxsd9_descr; +} + +#ifdef __KERNEL__ +EXPORT_SYMBOL(kxsd9_get_slave_descr); +#endif + +/** + * @} +**/ Index: linux-2.6.35/drivers/misc/mpu3050/accel/lis331_lpp.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux-2.6.35/drivers/misc/mpu3050/accel/lis331_lpp.c 2010-12-22 14:09:28.000000000 +0800 @@ -0,0 +1,189 @@ +/* + $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 lis331_lpp.c + * @brief Accelerometer setup and handling methods for ST LIS331 + * Configures the lis331 for low power pedometer. + */ + +/* ------------------ */ +/* - Include Files. - */ +/* ------------------ */ + +#ifdef __KERNEL__ +#include <linux/module.h> +#endif + +#include "mpu.h" +#include "mlsl.h" +#include "mlos.h" + +#include <log.h> +#undef MPL_LOG_TAG +#define MPL_LOG_TAG "MPL-acc" + +/* full scale setting - register & mask */ +#define ACCEL_ST_CTRL_REG1 (0x20) +#define ACCEL_ST_CTRL_REG2 (0x21) +#define ACCEL_ST_CTRL_REG3 (0x22) +#define ACCEL_ST_CTRL_REG4 (0x23) +#define ACCEL_ST_CTRL_REG5 (0x24) +#define ACCEL_ST_HP_FILTER_RESET (0x25) +#define ACCEL_ST_REFERENCE (0x26) +#define ACCEL_ST_STATUS_REG (0x27) +#define ACCEL_ST_OUT_X_L (0x28) +#define ACCEL_ST_OUT_X_H (0x29) +#define ACCEL_ST_OUT_Y_L (0x2a) +#define ACCEL_ST_OUT_Y_H (0x2b) +#define ACCEL_ST_OUT_Z_L (0x2b) +#define ACCEL_ST_OUT_Z_H (0x2d) + +#define ACCEL_ST_INT1_CFG (0x30) +#define ACCEL_ST_INT1_SRC (0x31) +#define ACCEL_ST_INT1_THS (0x32) +#define ACCEL_ST_INT1_DURATION (0x33) + +#define ACCEL_ST_INT2_CFG (0x34) +#define ACCEL_ST_INT2_SRC (0x35) +#define ACCEL_ST_INT2_THS (0x36) +#define ACCEL_ST_INT2_DURATION (0x37) + +#define ACCEL_ST_CTRL_MASK (0x30) +#define ACCEL_ST_SLEEP_MASK (0x20) + +/* --------------------- */ +/* - Variables. - */ +/* --------------------- */ + +/***************************************** + Accelerometer Initialization Functions +*****************************************/ + +static int lis331dlh_suspend(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result; + + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ST_CTRL_REG1, 0x47); + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ST_CTRL_REG2, 0x0f); + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ST_CTRL_REG3, 0x00); + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ST_CTRL_REG4, 0x40); + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ST_INT1_THS, 0x05); + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ST_INT1_DURATION, 0x01); + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ST_INT1_CFG, 0x2a); + return result; +} + +static int lis331dlh_resume(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result = ML_SUCCESS; + unsigned char reg; + + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ST_CTRL_REG1, 0x27); + ERROR_CHECK(result); + MLOSSleep(500); + + reg = 0x40; + + /* Full Scale */ + reg &= ~ACCEL_ST_CTRL_MASK; + if (slave->range.mantissa == 2 + && slave->range.fraction == 480) { + reg |= 0x00; + } else if (slave->range.mantissa == 4 + && slave->range.fraction == 960) { + reg |= 0x10; + } else if (slave->range.mantissa == 8 + && slave->range.fraction == 1920) { + reg |= 0x30; + } + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ST_CTRL_REG4, reg); + ERROR_CHECK(result); + + /* Configure high pass filter */ + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ST_CTRL_REG2, 0x0f); + ERROR_CHECK(result); + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ST_CTRL_REG3, 0x00); + ERROR_CHECK(result); + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ST_INT1_THS, 0x10); + ERROR_CHECK(result); + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ST_INT1_DURATION, 0x10); + ERROR_CHECK(result); + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ST_INT1_CFG, 0x00); + ERROR_CHECK(result); + MLOSSleep(50); + return result; +} + +static int lis331dlh_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 lis331dlh_descr = { + /*.suspend = */ lis331dlh_suspend, + /*.resume = */ lis331dlh_resume, + /*.read = */ lis331dlh_read, + /*.name = */ "lis331dlh", + /*.type = */ EXT_SLAVE_TYPE_ACCELEROMETER, + /*.id = */ ACCEL_ID_LIS331, + /*.reg = */ 0x28, + /*.len = */ 6, + /*.endian = */ EXT_SLAVE_BIG_ENDIAN, + /*.range = */ {2, 480}, +}; + +struct ext_slave_descr *lis331dlh_lpp_get_slave_descr(void) +{ + return &lis331dlh_descr; +} + +#ifdef __KERNEL__ +EXPORT_SYMBOL(lis331dlh_lpp_get_slave_descr); +#endif + +/** + * @} +**/ Index: linux-2.6.35/drivers/misc/mpu3050/accel/lsm303a.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux-2.6.35/drivers/misc/mpu3050/accel/lsm303a.c 2010-12-22 14:09:28.000000000 +0800 @@ -0,0 +1,172 @@ +/* + $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 lsm303a.c + * @brief Accelerometer setup and handling methods for ST LSM303 + */ + +/* ------------------ */ +/* - Include Files. - */ +/* ------------------ */ + +#ifdef __KERNEL__ +#include <linux/module.h> +#endif + +#include "mpu.h" +#include "mlsl.h" +#include "mlos.h" + +#include <log.h> +#undef MPL_LOG_TAG +#define MPL_LOG_TAG "MPL-acc" + +#define ACCEL_ST_SLEEP_REG (0x20) +#define ACCEL_ST_SLEEP_MASK (0x20) + +/* --------------------- */ +/* - Variables. - */ +/* --------------------- */ + +/***************************************** + Accelerometer Initialization Functions +*****************************************/ + +int lsm303dlha_suspend(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result; + unsigned char reg; + + result = + MLSLSerialRead(mlsl_handle, pdata->address, ACCEL_ST_SLEEP_REG, + 1, ®); + ERROR_CHECK(result); + reg &= ~(0x27); + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ST_SLEEP_REG, reg); + ERROR_CHECK(result); + return result; +} + +/* full scale setting - register & mask */ +#define ACCEL_ST_CTRL_REG (0x23) +#define ACCEL_ST_CTRL_MASK (0x30) + +int lsm303dlha_resume(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result = ML_SUCCESS; + unsigned char reg; + + result = + MLSLSerialRead(mlsl_handle, pdata->address, ACCEL_ST_SLEEP_REG, + 1, ®); + ERROR_CHECK(result); + reg |= 0x27; + /*wake up if sleeping */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ST_SLEEP_REG, reg); + ERROR_CHECK(result); + + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x20, 0x37); + ERROR_CHECK(result); + MLOSSleep(500); + + reg = 0x40; + + /* Full Scale */ + reg &= ~ACCEL_ST_CTRL_MASK; + if (slave->range.mantissa == 2 + && slave->range.fraction == 480) { + reg |= 0x00; + } else if (slave->range.mantissa == 4 + && slave->range.fraction == 960) { + reg |= 0x10; + } else if (slave->range.mantissa == 8 + && slave->range.fraction == 1920) { + reg |= 0x30; + } + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x23, reg); + ERROR_CHECK(result); + + /* Configure high pass filter */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x21, 0x0F); + ERROR_CHECK(result); + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x32, 0x00); + ERROR_CHECK(result); + /* Configure INT1_DURATION */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x33, 0x7F); + ERROR_CHECK(result); + /* Configure INT1_CFG */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x30, 0x95); + ERROR_CHECK(result); + MLOSSleep(50); + return result; +} + +int lsm303dlha_read(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata, + unsigned char *data) +{ + return ML_ERROR_FEATURE_NOT_IMPLEMENTED; +} + +struct ext_slave_descr lsm303dlha_descr = { + /*.suspend = */ lsm303dlha_suspend, + /*.resume = */ lsm303dlha_resume, + /*.read = */ lsm303dlha_read, + /*.name = */ "lsm303dlha", + /*.type = */ EXT_SLAVE_TYPE_ACCELEROMETER, + /*.id = */ ACCEL_ID_LSM303, + /*.reg = */ 0x28, + /*.len = */ 6, + /*.endian = */ EXT_SLAVE_BIG_ENDIAN, + /*.range = */ {2, 480}, +}; + +struct ext_slave_descr *lsm303dlha_get_slave_descr(void) +{ + return &lsm303dlha_descr; +} + +#ifdef __KERNEL__ +EXPORT_SYMBOL(lsm303dlha_get_slave_descr); +#endif + +/** + * @} +**/ Index: linux-2.6.35/drivers/misc/mpu3050/accel/mantis.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux-2.6.35/drivers/misc/mpu3050/accel/mantis.c 2010-12-22 14:09:28.000000000 +0800 @@ -0,0 +1,124 @@ +/* + $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 lis331.c + * @brief Accelerometer setup and handling methods for ST LIS331 + */ + +/* ------------------ */ +/* - Include Files. - */ +/* ------------------ */ + +#ifdef __KERNEL__ +#include <linux/module.h> +#endif + +#include "mpu.h" +#include "mlsl.h" +#include "mlos.h" + +#include <log.h> +#undef MPL_LOG_TAG +#define MPL_LOG_TAG "MPL-acc" + +#define ACCEL_ST_SLEEP_REG (0x20) +#define ACCEL_ST_SLEEP_MASK (0x20) + +/* --------------------- */ +/* - Variables. - */ +/* --------------------- */ + +/***************************************** + Accelerometer Initialization Functions +*****************************************/ + +int mantis_suspend(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + return ML_SUCCESS; +} + +/* full scale setting - register & mask */ +#define ACCEL_ST_CTRL_REG (0x23) +#define ACCEL_ST_CTRL_MASK (0x30) + +int mantis_resume(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result = ML_SUCCESS; +#ifdef M_HW + unsigned char reg; + + if (slave->range.mantissa == 2) + reg = 0; + else if (slave->range.mantissa == 4) + reg = 1 << 3; + else if (slave->range.mantissa == 8) + reg = 2 << 3; + else if (slave->range.mantissa == 16) + reg = 3 << 3; + else + return ML_ERROR; + + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, + MPUREG_ACCEL_CONFIG, reg); +#endif + return result; +} + +int mantis_read(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata, unsigned char *data) +{ + return ML_ERROR_FEATURE_NOT_IMPLEMENTED; +} + +struct ext_slave_descr mantis_descr = { + /*.suspend = */ mantis_suspend, + /*.resume = */ mantis_resume, + /*.read = */ mantis_read, + /*.name = */ "mantis", + /*.type = */ EXT_SLAVE_TYPE_ACCELEROMETER, + /*.id = */ ID_INVALID, + /*.reg = */ 0xA8, + /*.len = */ 6, + /*.endian = */ EXT_SLAVE_BIG_ENDIAN, + /*.range = */ {2, 0}, +}; + +struct ext_slave_descr *mantis_get_slave_descr(void) +{ + return &mantis_descr; +} + +#ifdef __KERNEL__ +EXPORT_SYMBOL(mantis_get_slave_descr); +#endif + +/** + * @} + */ + Index: linux-2.6.35/drivers/misc/mpu3050/accel/mma8450.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux-2.6.35/drivers/misc/mpu3050/accel/mma8450.c 2010-12-22 14:09:28.000000000 +0800 @@ -0,0 +1,146 @@ +/* + $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 mma8450.c + * @brief Accelerometer setup and handling methods for Freescale MMA8450 + */ + +/* ------------------ */ +/* - Include Files. - */ +/* ------------------ */ + +#include "mpu.h" +#include "mlsl.h" +#include "mlos.h" + +#include <log.h> +#undef MPL_LOG_TAG +#define MPL_LOG_TAG "MPL-acc" + +#define ACCEL_MMA8450_SLEEP_REG (0x38) +#define ACCEL_MMA8450_SLEEP_MASK (0x3) + + +/* --------------------- */ +/* - Variables. - */ +/* --------------------- */ + +/***************************************** + Accelerometer Initialization Functions +*****************************************/ + +int mma8450_suspend(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result; + unsigned char reg; + result = + MLSLSerialRead(mlsl_handle, pdata->address, + ACCEL_MMA8450_SLEEP_REG, 1, ®); + ERROR_CHECK(result); + reg &= ~ACCEL_MMA8450_SLEEP_MASK; + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_MMA8450_SLEEP_REG, reg); + ERROR_CHECK(result); + return result; +} + +/* full scale setting - register & mask */ +#define ACCEL_MMA8450_CTRL_REG (0x38) +#define ACCEL_MMA8450_CTRL_MASK (0x3) + +int mma8450_resume(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result = ML_SUCCESS; + unsigned char reg; + + result = + MLSLSerialRead(mlsl_handle, pdata->address, + ACCEL_MMA8450_CTRL_REG, 1, ®); + ERROR_CHECK(result); + + /* data rate = 200Hz */ + reg &= 0xE3; + reg |= 0x4; + + /* Full Scale */ + reg &= ~ACCEL_MMA8450_CTRL_MASK; + if (slave->range.mantissa == 2) + reg |= 0x1; + else if (slave->range.mantissa == 4) + reg |= 0x2; + else if (slave->range.mantissa == 8) + reg |= 0x3; + + /* XYZ_DATA_CFG: event flag enabled on all axis */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x16, 0x05); + ERROR_CHECK(result); + /* CTRL_REG1: rate + scale config + wakeup */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_MMA8450_CTRL_REG, reg); + ERROR_CHECK(result); + + return result; +} + +int mma8450_read(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata, + unsigned char *data) +{ + return ML_ERROR_FEATURE_NOT_IMPLEMENTED; +} + +struct ext_slave_descr mma8450_descr = { + /*.suspend = */ mma8450_suspend, + /*.resume = */ mma8450_resume, + /*.read = */ mma8450_read, + /*.name = */ "mma8450", + /*.type = */ EXT_SLAVE_TYPE_ACCELEROMETER, + /*.id = */ ACCEL_ID_MMA8450, + /*.reg = */ 0x00, + /*.len = */ 3, + /*.endian = */ EXT_SLAVE_FS8_BIG_ENDIAN, + /*.range = */ {2, 0}, +}; + +struct ext_slave_descr *mma8450_get_slave_descr(void) +{ + return &mma8450_descr; +} + +#ifdef __KERNEL__ +EXPORT_SYMBOL(mma8450_get_slave_descr); +#endif + +/** + * @} +**/ Index: linux-2.6.35/drivers/misc/mpu3050/accel/mma8451.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux-2.6.35/drivers/misc/mpu3050/accel/mma8451.c 2010-12-22 14:09:28.000000000 +0800 @@ -0,0 +1,145 @@ +/* + $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 mma8451.c + * @brief Accelerometer setup and handling methods for Freescale MMA8451 + */ + +/* ------------------ */ +/* - Include Files. - */ +/* ------------------ */ + +#ifdef __KERNEL__ +#include <linux/module.h> +#endif + +#include "mpu.h" +#include "mlsl.h" +#include "mlos.h" + +#include <log.h> +#undef MPL_LOG_TAG +#define MPL_LOG_TAG "MPL-acc" + +#define ACCEL_MMA8451_SLEEP_REG (0x2A) +#define ACCEL_MMA8451_SLEEP_MASK (0x01) + + +/* --------------------- */ +/* - Variables. - */ +/* --------------------- */ + +/***************************************** + Accelerometer Initialization Functions +*****************************************/ + +int mma8451_suspend(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result; + unsigned char reg; + result = + MLSLSerialRead(mlsl_handle, pdata->address, + ACCEL_MMA8451_SLEEP_REG, 1, ®); + ERROR_CHECK(result); + reg &= ~ACCEL_MMA8451_SLEEP_MASK; + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_MMA8451_SLEEP_REG, reg); + ERROR_CHECK(result); + return result; +} + +/* full scale setting - register & mask */ +#define ACCEL_MMA8451_CTRL_REG (0x0E) +#define ACCEL_MMA8451_CTRL_MASK (0x03) + +int mma8451_resume(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result = ML_SUCCESS; + unsigned char reg; + + result = + MLSLSerialRead(mlsl_handle, pdata->address, 0x0E, 1, ®); + ERROR_CHECK(result); + + /* data rate = 200Hz */ + + /* Full Scale */ + reg &= ~ACCEL_MMA8451_CTRL_MASK; + if (slave->range.mantissa == 2) + reg |= 0x0; + else if (slave->range.mantissa == 4) + reg |= 0x1; + else if (slave->range.mantissa == 8) + reg |= 0x2; + + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x0E, reg); + ERROR_CHECK(result); + /* 200Hz + active mode */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x2A, 0x11); + ERROR_CHECK(result); + + return result; +} + +int mma8451_read(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata, + unsigned char *data) +{ + return ML_ERROR_FEATURE_NOT_IMPLEMENTED; +} + +struct ext_slave_descr mma8451_descr = { + /*.suspend = */ mma8451_suspend, + /*.resume = */ mma8451_resume, + /*.read = */ mma8451_read, + /*.name = */ "mma8451", + /*.type = */ EXT_SLAVE_TYPE_ACCELEROMETER, + /*.id = */ ACCEL_ID_MMA8451, + /*.reg = */ 0x00, + /*.len = */ 6, + /*.endian = */ EXT_SLAVE_FS16_BIG_ENDIAN, + /*.range = */ {2, 0}, +}; + +struct ext_slave_descr *mma8451_get_slave_descr(void) +{ + return &mma8451_descr; +} + +#ifdef __KERNEL__ +EXPORT_SYMBOL(mma8451_get_slave_descr); +#endif + +/** + * @} +**/ Index: linux-2.6.35/drivers/misc/mpu3050/compass/hscdtd002b.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux-2.6.35/drivers/misc/mpu3050/compass/hscdtd002b.c 2010-12-22 14:09:28.000000000 +0800 @@ -0,0 +1,171 @@ +/* + $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/>. + $ + */ + +/** + * @brief Provides the interface to setup and handle a compass + * connected to the primary I2C interface of the gyroscope. + * + * @{ + * @file hscdtd002b.c + * @brief Magnetometer setup and handling methods for Alps hscdtd002b + * compass. + */ + +/* ------------------ */ +/* - Include Files. - */ +/* ------------------ */ + +#ifdef __KERNEL__ +#include <linux/module.h> +#endif + +#include "mpu.h" +#include "mlsl.h" +#include "mlos.h" + +#include <log.h> +#undef MPL_LOG_TAG +#define MPL_LOG_TAG "MPL-compass" + +/*----- ALPS HSCDTD002B Registers ------*/ +#define COMPASS_HSCDTD002B_STAT (0x18) +#define COMPASS_HSCDTD002B_CTRL1 (0x1B) +#define COMPASS_HSCDTD002B_CTRL2 (0x1C) +#define COMPASS_HSCDTD002B_CTRL3 (0x1D) +#define COMPASS_HSCDTD002B_DATAX (0x10) + +/* --------------------- */ +/* - Variables. - */ +/* --------------------- */ + +/***************************************** + Compass Initialization Functions +*****************************************/ + +int hscdtd002b_suspend(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result = ML_SUCCESS; + + /* Power mode: stand-by */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + COMPASS_HSCDTD002B_CTRL1, 0x00); + ERROR_CHECK(result); + MLOSSleep(1); /* turn-off time */ + + return result; +} + +int hscdtd002b_resume(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result = ML_SUCCESS; + + /* Soft reset */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + COMPASS_HSCDTD002B_CTRL3, 0x80); + ERROR_CHECK(result); + /* Force state; Power mode: active */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + COMPASS_HSCDTD002B_CTRL1, 0x82); + ERROR_CHECK(result); + /* Data ready enable */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + COMPASS_HSCDTD002B_CTRL2, 0x08); + ERROR_CHECK(result); + MLOSSleep(1); /* turn-on time */ + + return result; +} + +int hscdtd002b_read(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata, + unsigned char *data) +{ + unsigned char stat; + tMLError result = ML_SUCCESS; + + /* Read status reg. to check if data is ready */ + result = + MLSLSerialRead(mlsl_handle, pdata->address, + COMPASS_HSCDTD002B_STAT, 1, &stat); + ERROR_CHECK(result); + if (stat & 0x40) { + result = + MLSLSerialRead(mlsl_handle, pdata->address, + COMPASS_HSCDTD002B_DATAX, 6, + (unsigned char *) data); + ERROR_CHECK(result); + + /* trigger next measurement read */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + COMPASS_HSCDTD002B_CTRL3, 0x40); + ERROR_CHECK(result); + + return ML_SUCCESS; + } else if (stat & 0x20) { + /* trigger next measurement read */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + COMPASS_HSCDTD002B_CTRL3, 0x40); + ERROR_CHECK(result); + return ML_ERROR_COMPASS_DATA_OVERFLOW; + } else { + /* trigger next measurement read */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + COMPASS_HSCDTD002B_CTRL3, 0x40); + ERROR_CHECK(result); + return ML_ERROR_COMPASS_DATA_NOT_READY; + } +} + +struct ext_slave_descr hscdtd002b_descr = { + /*.suspend = */ hscdtd002b_suspend, + /*.resume = */ hscdtd002b_resume, + /*.read = */ hscdtd002b_read, + /*.name = */ "hscdtd002b", + /*.type = */ EXT_SLAVE_TYPE_COMPASS, + /*.id = */ COMPASS_ID_HSCDTD002B, + /*.reg = */ 0x10, + /*.len = */ 6, + /*.endian = */ EXT_SLAVE_LITTLE_ENDIAN, + /*.range = */ {9830, 4000}, +}; + +struct ext_slave_descr *hscdtd002b_get_slave_descr(void) +{ + return &hscdtd002b_descr; +} + +#ifdef __KERNEL__ +EXPORT_SYMBOL(hscdtd002b_get_slave_descr); +#endif + +/** + * @} +**/
Index: linux-2.6.35/drivers/misc/mpu3050/compass/lsm303m.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux-2.6.35/drivers/misc/mpu3050/compass/lsm303m.c 2010-12-22 14:09:28.000000000 +0800 @@ -0,0 +1,222 @@ +/* + $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/>. + $ + */ + +/** + * @brief Provides the interface to setup and handle a compass + * connected to the primary I2C interface of the gyroscope. + * + * @{ + * @file lsm303m.c + * @brief Magnetometer setup and handling methods for ST LSM303. + */ + +/* ------------------ */ +/* - Include Files. - */ +/* ------------------ */ + +#ifdef __KERNEL__ +#include <linux/module.h> +#endif + +#include "mpu.h" +#include "mlsl.h" +#include "mlos.h" + +#include <log.h> +#undef MPL_LOG_TAG +#define MPL_LOG_TAG "MPL-compass" + +/*----- ST LSM303 Registers ------*/ +enum LSM_REG { + LSM_REG_CONF_A = 0x0, + LSM_REG_CONF_B = 0x1, + LSM_REG_MODE = 0x2, + LSM_REG_X_M = 0x3, + LSM_REG_X_L = 0x4, + LSM_REG_Z_M = 0x5, + LSM_REG_Z_L = 0x6, + LSM_REG_Y_M = 0x7, + LSM_REG_Y_L = 0x8, + LSM_REG_STATUS = 0x9, + LSM_REG_ID_A = 0xA, + LSM_REG_ID_B = 0xB, + LSM_REG_ID_C = 0xC +}; + +enum LSM_CONF_A { + LSM_CONF_A_DRATE_MASK = 0x1C, + LSM_CONF_A_DRATE_0_75 = 0x00, + LSM_CONF_A_DRATE_1_5 = 0x04, + LSM_CONF_A_DRATE_3 = 0x08, + LSM_CONF_A_DRATE_7_5 = 0x0C, + LSM_CONF_A_DRATE_15 = 0x10, + LSM_CONF_A_DRATE_30 = 0x14, + LSM_CONF_A_DRATE_75 = 0x18, + LSM_CONF_A_MEAS_MASK = 0x3, + LSM_CONF_A_MEAS_NORM = 0x0, + LSM_CONF_A_MEAS_POS = 0x1, + LSM_CONF_A_MEAS_NEG = 0x2 +}; + +enum LSM_CONF_B { + LSM_CONF_B_GAIN_MASK = 0xE0, + LSM_CONF_B_GAIN_0_9 = 0x00, + LSM_CONF_B_GAIN_1_2 = 0x20, + LSM_CONF_B_GAIN_1_9 = 0x40, + LSM_CONF_B_GAIN_2_5 = 0x60, + LSM_CONF_B_GAIN_4_0 = 0x80, + LSM_CONF_B_GAIN_4_6 = 0xA0, + LSM_CONF_B_GAIN_5_5 = 0xC0, + LSM_CONF_B_GAIN_7_9 = 0xE0 +}; + +enum LSM_MODE { + LSM_MODE_MASK = 0x3, + LSM_MODE_CONT = 0x0, + LSM_MODE_SINGLE = 0x1, + LSM_MODE_IDLE = 0x2, + LSM_MODE_SLEEP = 0x3 +}; + +/* --------------------- */ +/* - Variables. - */ +/* --------------------- */ + +/***************************************** + Accelerometer Initialization Functions +*****************************************/ + +int lsm303dlhm_suspend(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result = ML_SUCCESS; + + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + LSM_REG_MODE, LSM_MODE_SLEEP); + ERROR_CHECK(result); + MLOSSleep(3); + + return result; +} + +int lsm303dlhm_resume(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result = ML_SUCCESS; + + /* Use single measurement mode. Start at sleep state. */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + LSM_REG_MODE, LSM_MODE_SLEEP); + ERROR_CHECK(result); + /* Config normal measurement */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + LSM_REG_CONF_A, 0); + ERROR_CHECK(result); + /* Adjust gain to 320 LSB/Gauss */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + LSM_REG_CONF_B, LSM_CONF_B_GAIN_5_5); + ERROR_CHECK(result); + + return result; +} + +int lsm303dlhm_read(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata, + unsigned char *data) +{ + unsigned char stat; + tMLError result = ML_SUCCESS; + short zAxisfixed; + + /* Read status reg. to check if data is ready */ + result = + MLSLSerialRead(mlsl_handle, pdata->address, LSM_REG_STATUS, 1, + &stat); + ERROR_CHECK(result); + if (stat & 0x01) { + result = + MLSLSerialRead(mlsl_handle, pdata->address, + LSM_REG_X_M, 6, (unsigned char *) data); + ERROR_CHECK(result); + + /*drop data if overflows */ + if ((data[0] == 0xf0) || (data[2] == 0xf0) + || (data[4] == 0xf0)) { + return ML_ERROR_COMPASS_DATA_OVERFLOW; + } + /* convert to fixed point and apply sensitivity correction for + Z-axis */ + zAxisfixed = + (short) ((unsigned short) data[5] + + (unsigned short) data[4] * 256); + /* scale up by 1.122 (320/285) */ + zAxisfixed = (short) (zAxisfixed * 9) >> 3; + data[4] = zAxisfixed >> 8; + data[5] = zAxisfixed & 0xFF; + + /* trigger next measurement read */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + LSM_REG_MODE, LSM_MODE_SINGLE); + ERROR_CHECK(result); + + return ML_SUCCESS; + } else { + /* trigger next measurement read */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + LSM_REG_MODE, LSM_MODE_SINGLE); + ERROR_CHECK(result); + + return ML_ERROR_COMPASS_DATA_NOT_READY; + } +} + +struct ext_slave_descr lsm303dlhm_descr = { + /*.suspend = */ lsm303dlhm_suspend, + /*.resume = */ lsm303dlhm_resume, + /*.read = */ lsm303dlhm_read, + /*.name = */ "lsm303dlhm", + /*.type = */ EXT_SLAVE_TYPE_COMPASS, + /*.id = */ COMPASS_ID_LSM303, + /*.reg = */ 0x06, + /*.len = */ 6, + /*.endian = */ EXT_SLAVE_BIG_ENDIAN, + /*.range = */ {10240, 0}, +}; + +struct ext_slave_descr *lsm303dlhm_get_slave_descr(void) +{ + return &lsm303dlhm_descr; +} + +#ifdef __KERNEL__ +EXPORT_SYMBOL(lsm303dlhm_get_slave_descr); +#endif + +/** + * @} +**/ _______________________________________________ MeeGo-kernel mailing list [email protected] http://lists.meego.com/listinfo/meego-kernel
