Index: linux-2.6.35/drivers/misc/mpu3050/accel/lis331.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux-2.6.35/drivers/misc/mpu3050/accel/lis331.c 2010-12-24 11:19:41.000000000 +0800 @@ -0,0 +1,180 @@ +/* + $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. - */ +/* ------------------ */ + +#include <linux/module.h> +#include <linux/delay.h> + +#include "mpu.h" +#include "mlsl.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 +*****************************************/ + +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; +} + +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, 0x37); + ERROR_CHECK(result); + msleep(500); + + /* Full Scale */ + reg = 0x40; + 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); + msleep(50); + return result; +} + +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; +} + +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_get_slave_descr(void) +{ + return &lis331dlh_descr; +} + +EXPORT_SYMBOL(lis331dlh_get_slave_descr); + Index: linux-2.6.35/drivers/misc/mpu3050/accel/kxtf9.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux-2.6.35/drivers/misc/mpu3050/accel/kxtf9.c 2010-12-24 11:19:05.000000000 +0800 @@ -0,0 +1,147 @@ +/* + $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 kxtf9.c + * @brief Accelerometer setup and handling methods. +*/ + +/* ------------------ */ +/* - Include Files. - */ +/* ------------------ */ + +#include <linux/module.h> +#include <linux/delay.h> + +#include "mpu.h" +#include "mlsl.h" + +#include <log.h> +#undef MPL_LOG_TAG +#define MPL_LOG_TAG "MPL-acc" + +/* --------------------- */ +/* - Variables. - */ +/* --------------------- */ + +/***************************************** + Accelerometer Initialization Functions +*****************************************/ + +static int kxtf9_suspend(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result; + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x1b, 0); + ERROR_CHECK(result); + return result; +} + +/* full scale setting - register and mask */ +#define ACCEL_KIONIX_CTRL_REG (0x1b) +#define ACCEL_KIONIX_CTRL_MASK (0x18) + +static int kxtf9_resume(void *mlsl_handle, + struct ext_slave_descr *slave, + struct ext_slave_platform_data *pdata) +{ + int result = ML_SUCCESS; + unsigned char reg; + + /* RAM reset */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x1d, 0xcd); + ERROR_CHECK(result); + msleep(10); + /* Wake up */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x1b, 0x42); + ERROR_CHECK(result); + /* INT_CTRL_REG1: */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x1e, 0x14); + ERROR_CHECK(result); + /* WUF_THRESH: */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x5a, 0x00); + ERROR_CHECK(result); + /* DATA_CTRL_REG */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x21, 0x04); + ERROR_CHECK(result); + /* WUF_TIMER */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x29, 0x02); + ERROR_CHECK(result); + + /* Full Scale */ + reg = 0xc2; + reg &= ~ACCEL_KIONIX_CTRL_MASK; + reg |= 0x00; + if (slave->range.mantissa == 2) + reg |= 0x00; + else if (slave->range.mantissa == 4) + reg |= 0x08; + else if (slave->range.mantissa == 8) + reg |= 0x10; + + /* Normal operation */ + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x1b, reg); + ERROR_CHECK(result); + msleep(50); + + return ML_SUCCESS; +} + +static int kxtf9_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 kxtf9_descr = { + /*.suspend = */ kxtf9_suspend, + /*.resume = */ kxtf9_resume, + /*.read = */ kxtf9_read, + /*.name = */ "kxtf9", + /*.type = */ EXT_SLAVE_TYPE_ACCELEROMETER, + /*.id = */ ACCEL_ID_KXTF9, + /*.reg = */ 0x06, + /*.len = */ 6, + /*.endian = */ EXT_SLAVE_LITTLE_ENDIAN, + /*.range = */ {2, 0}, +}; + +struct ext_slave_descr *kxtf9_get_slave_descr(void) +{ + return &kxtf9_descr; +} + +EXPORT_SYMBOL(kxtf9_get_slave_descr); + Index: linux-2.6.35/drivers/misc/mpu3050/accel/adxl346.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux-2.6.35/drivers/misc/mpu3050/accel/adxl346.c 2010-12-24 11:18:33.000000000 +0800 @@ -0,0 +1,150 @@ +/* + $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 adxl346.c + * @brief Accelerometer setup and handling methods for AD adxl346. + */ + +/* ------------------ */ +/* - Include Files. - */ +/* ------------------ */ + +#include <linux/module.h> +#include <linux/delay.h> + +#include "mpu.h" +#include "mlsl.h" + +#include <log.h> +#undef MPL_LOG_TAG +#define MPL_LOG_TAG "MPL-acc" + +#define ACCEL_ADI346_SLEEP_REG (0x2D) +#define ACCEL_ADI346_SLEEP_MASK (0x04) + +/* --------------------- */ +/* - Variables. - */ +/* --------------------- */ + +/***************************************** + Accelerometer Initialization Functions +*****************************************/ + +int adxl346_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_ADI346_SLEEP_REG, 1, ®); + ERROR_CHECK(result); + reg |= ACCEL_ADI346_SLEEP_MASK; + result = + MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ADI346_SLEEP_REG, reg); + ERROR_CHECK(result); + return result; +} + +/* full scale setting - register & mask */ +#define ACCEL_ADI346_CTRL_REG (0x31) +#define ACCEL_ADI346_CTRL_MASK (0x03) + +int adxl346_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_ADI346_SLEEP_REG, 1, ®); + ERROR_CHECK(result); + reg &= ~ACCEL_ADI346_SLEEP_MASK; + /*wake up if sleeping */ + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, + ACCEL_ADI346_SLEEP_REG, reg); + ERROR_CHECK(result); + /*msleep(10) */ + + /* Full Scale */ + reg = 0x04; + reg &= ~ACCEL_ADI346_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; + else if (slave->range.mantissa == 16) + reg |= 0x3; + + /* DATA_FORMAT: full resolution of +/-2g; data is left justified */ + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x31, reg); + ERROR_CHECK(result); + /* BW_RATE: normal power operation with output data rate of 200Hz */ + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x2C, 0x0B); + ERROR_CHECK(result); + /* POWER_CTL: power on in measurement mode */ + result = MLSLSerialWriteSingle(mlsl_handle, pdata->address, 0x2D, 0x28); + ERROR_CHECK(result); + /*--- after wake up, it takes at least [1/(data rate) + 1.1]ms ==> + 6.1ms to get valid sensor data ---*/ + msleep(10); + + return result; +} + +int adxl346_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 adxl346_descr = { + /*.suspend = */ adxl346_suspend, + /*.resume = */ adxl346_resume, + /*.read = */ adxl346_read, + /*.name = */ "adx1346", + /*.type = */ EXT_SLAVE_TYPE_ACCELEROMETER, + /*.id = */ ACCEL_ID_ADI346, + /*.reg = */ 0x32, + /*.len = */ 6, + /*.endian = */ EXT_SLAVE_LITTLE_ENDIAN, + /*.range = */ {2, 0}, +}; + +struct ext_slave_descr *adxl346_get_slave_descr(void) +{ + return &adxl346_descr; +} + +EXPORT_SYMBOL(adxl346_get_slave_descr); + 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-24 11:19:28.000000000 +0800 @@ -0,0 +1,129 @@ +/* + $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. - */ +/* ------------------ */ + +#include <linux/kernel.h> +#include <linux/module.h> + +#include "mpu.h" +#include "mlsl.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; +} + +EXPORT_SYMBOL(kxsd9_get_slave_descr); + 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-24 11:19:49.000000000 +0800 @@ -0,0 +1,182 @@ +/* + $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. - */ +/* ------------------ */ + +#include <linux/module.h> +#include <linux/delay.h> + +#include "mpu.h" +#include "mlsl.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); + msleep(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); + msleep(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; +} + +EXPORT_SYMBOL(lis331dlh_lpp_get_slave_descr); + 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-24 11:20:26.000000000 +0800 @@ -0,0 +1,165 @@ +/* + $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. - */ +/* ------------------ */ + +#include <linux/module.h> +#include <linux/delay.h> + +#include "mpu.h" +#include "mlsl.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); + msleep(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); + msleep(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; +} + +EXPORT_SYMBOL(lsm303dlha_get_slave_descr); + 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-24 11:21:01.000000000 +0800 @@ -0,0 +1,115 @@ +/* + $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. - */ +/* ------------------ */ + +#include <linux/module.h> + +#include "mpu.h" +#include "mlsl.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; +} + +EXPORT_SYMBOL(mantis_get_slave_descr); + 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-24 11:21:33.000000000 +0800 @@ -0,0 +1,139 @@ +/* + $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 <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; +} + +EXPORT_SYMBOL(mma8450_get_slave_descr); 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-24 11:21:55.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 mma8451.c + * @brief Accelerometer setup and handling methods for Freescale MMA8451 + */ + +/* ------------------ */ +/* - Include Files. - */ +/* ------------------ */ + +#include <linux/module.h> + +#include "mpu.h" +#include "mlsl.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; +} + +EXPORT_SYMBOL(mma8451_get_slave_descr); +
_______________________________________________ MeeGo-kernel mailing list [email protected] http://lists.meego.com/listinfo/meego-kernel
