aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/inv_mpu/compass
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc/inv_mpu/compass')
-rw-r--r--drivers/misc/inv_mpu/compass/Kconfig94
-rw-r--r--drivers/misc/inv_mpu/compass/Makefile30
-rw-r--r--drivers/misc/inv_mpu/compass/ak8972.c499
-rw-r--r--drivers/misc/inv_mpu/compass/ak8975.c504
-rw-r--r--drivers/misc/inv_mpu/compass/hscdtd002b.c294
-rw-r--r--drivers/misc/inv_mpu/compass/hscdtd004a.c318
-rw-r--r--drivers/misc/inv_mpu/compass/lsm303dlx_m.c395
-rw-r--r--drivers/misc/inv_mpu/compass/mmc314x.c313
-rw-r--r--drivers/misc/inv_mpu/compass/yas529-kernel.c611
-rw-r--r--drivers/misc/inv_mpu/compass/yas530.c596
-rw-r--r--drivers/misc/inv_mpu/compass/yas530_ext.c288
-rw-r--r--drivers/misc/inv_mpu/compass/yas530_ext.h28
12 files changed, 0 insertions, 3970 deletions
diff --git a/drivers/misc/inv_mpu/compass/Kconfig b/drivers/misc/inv_mpu/compass/Kconfig
deleted file mode 100644
index 0881d8d..0000000
--- a/drivers/misc/inv_mpu/compass/Kconfig
+++ /dev/null
@@ -1,94 +0,0 @@
-menuconfig INV_SENSORS_MPU6050_COMPASS
- bool "Compass Slave Sensors"
- default y
- ---help---
- Say Y here to get to see options for device drivers for various
- compasses. This option alone does not add any kernel code.
-
- If you say N, all options in this submenu will be skipped and disabled.
-
-if INV_SENSORS_MPU6050_COMPASS
-
-config MPU_SENSORS_MPU6050_AK8975
- tristate "AKM ak8975"
- help
- This enables support for the AKM ak8975 compass
- This support is for integration with the MPU3050 or MPU6050 gyroscope
- device driver. Only one compass can be registered at a time.
- Specifying more that one compass in the board file will result
- in runtime errors.
-
-config MPU_SENSORS_MPU6050_AK8972
- tristate "AKM ak8972"
- help
- This enables support for the AKM ak8972 compass
- This support is for integration with the MPU3050 or MPU6050 gyroscope
- device driver. Only one compass can be registered at a time.
- Specifying more that one compass in the board file will result
- in runtime errors.
-
-config MPU_SENSORS_MPU6050_MMC314X
- tristate "MEMSIC mmc314x"
- help
- This enables support for the MEMSIC mmc314x compass
- This support is for integration with the MPU3050 or MPU6050 gyroscope
- device driver. Only one compass can be registered at a time.
- Specifying more that one compass in the board file will result
- in runtime errors.
-
-config MPU_SENSORS_MPU6050_LSM303DLX_M
- tristate "ST lsm303dlx"
- help
- This enables support for the ST lsm303dlh and lsm303dlm compasses
- This support is for integration with the MPU3050 or MPU6050 gyroscope
- device driver. Only one compass can be registered at a time.
- Specifying more that one compass in the board file will result
- in runtime errors.
-
-config MPU_SENSORS_MPU6050_MMC314XMS
- tristate "MEMSIC mmc314xMS"
- help
- This enables support for the MEMSIC mmc314xMS compass
- This support is for integration with the MPU3050 or MPU6050 gyroscope
- device driver. Only one compass can be registered at a time.
- Specifying more that one compass in the board file will result
- in runtime errors.
-
-config MPU_SENSORS_MPU6050_YAS529
- tristate "Yamaha yas529"
- depends on INPUT_YAS_MAGNETOMETER
- help
- This enables support for the Yamaha yas529 compass
- This support is for integration with the MPU3050 or MPU6050 gyroscope
- device driver. Only one compass can be registered at a time.
- Specifying more that one compass in the board file will result
- in runtime errors.
-
-config MPU_SENSORS_MPU6050_YAS530
- tristate "Yamaha yas530"
- help
- This enables support for the Yamaha yas530 compass
- This support is for integration with the MPU3050 or MPU6050 gyroscope
- device driver. Only one compass can be registered at a time.
- Specifying more that one compass in the board file will result
- in runtime errors.
-
-config MPU_SENSORS_MPU6050_HSCDTD002B
- tristate "Alps hscdtd002b"
- help
- This enables support for the Alps hscdtd002b compass
- This support is for integration with the MPU3050 or MPU6050 gyroscope
- device driver. Only one compass can be registered at a time.
- Specifying more that one compass in the board file will result
- in runtime errors.
-
-config MPU_SENSORS_MPU6050_HSCDTD004A
- tristate "Alps hscdtd004a"
- help
- This enables support for the Alps hscdtd004a compass
- This support is for integration with the MPU3050 or MPU6050 gyroscope
- device driver. Only one compass can be registered at a time.
- Specifying more that one compass in the board file will result
- in runtime errors.
-
-endif
diff --git a/drivers/misc/inv_mpu/compass/Makefile b/drivers/misc/inv_mpu/compass/Makefile
deleted file mode 100644
index 5533d84..0000000
--- a/drivers/misc/inv_mpu/compass/Makefile
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-# Compass Slaves MPUxxxx
-#
-
-obj-$(CONFIG_MPU_SENSORS_MPU6050_LSM303DLX_M) += inv_mpu_lsm303dlx_m.o
-inv_mpu_lsm303dlx_m-objs += lsm303dlx_m.o
-
-obj-$(CONFIG_MPU_SENSORS_MPU6050_MMC314X) += inv_mpu_mmc314x.o
-inv_mpu_mmc314x-objs += mmc314x.o
-
-obj-$(CONFIG_MPU_SENSORS_MPU6050_YAS529) += inv_mpu_yas529.o
-inv_mpu_yas529-objs += yas529-kernel.o
-
-obj-$(CONFIG_MPU_SENSORS_MPU6050_YAS530_411) += inv_mpu_yas530.o
-inv_mpu_yas530-objs += yas530.o
-
-obj-$(CONFIG_MPU_SENSORS_MPU6050_HSCDTD002B) += inv_mpu_hscdtd002b.o
-inv_mpu_hscdtd002b-objs += hscdtd002b.o
-
-obj-$(CONFIG_MPU_SENSORS_MPU6050_HSCDTD004A) += inv_mpu_hscdtd004a.o
-inv_mpu_hscdtd004a-objs += hscdtd004a.o
-
-obj-$(CONFIG_MPU_SENSORS_MPU6050_AK8975) += inv_mpu_ak8975.o
-inv_mpu_ak8975-objs += ak8975.o
-
-obj-$(CONFIG_MPU_SENSORS_MPU6050_AK8972) += inv_mpu_ak8972.o
-inv_mpu_ak8972-objs += ak8972.o
-
-EXTRA_CFLAGS += -Idrivers/misc/inv_mpu
-EXTRA_CFLAGS += -D__C99_DESIGNATED_INITIALIZER
diff --git a/drivers/misc/inv_mpu/compass/ak8972.c b/drivers/misc/inv_mpu/compass/ak8972.c
deleted file mode 100644
index 7eb15b4..0000000
--- a/drivers/misc/inv_mpu/compass/ak8972.c
+++ /dev/null
@@ -1,499 +0,0 @@
-/*
- $License:
- Copyright (C) 2011 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/>.
- $
- */
-
-/**
- * @addtogroup COMPASSDL
- *
- * @{
- * @file ak8972.c
- * @brief Magnetometer setup and handling methods for the AKM AK8972 compass device.
- */
-
-/* -------------------------------------------------------------------------- */
-
-#include <linux/i2c.h>
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/slab.h>
-#include <linux/delay.h>
-#include "mpu-dev.h"
-
-#include <log.h>
-#include <linux/mpu.h>
-#include "mlsl.h"
-#include "mldl_cfg.h"
-#undef MPL_LOG_TAG
-#define MPL_LOG_TAG "MPL-compass"
-
-/* -------------------------------------------------------------------------- */
-#define AK8972_REG_ST1 (0x02)
-#define AK8972_REG_HXL (0x03)
-#define AK8972_REG_ST2 (0x09)
-
-#define AK8972_REG_CNTL (0x0A)
-#define AK8972_REG_ASAX (0x10)
-#define AK8972_REG_ASAY (0x11)
-#define AK8972_REG_ASAZ (0x12)
-
-#define AK8972_CNTL_MODE_POWER_DOWN (0x00)
-#define AK8972_CNTL_MODE_SINGLE_MEASUREMENT (0x01)
-#define AK8972_CNTL_MODE_FUSE_ROM_ACCESS (0x0f)
-
-/* -------------------------------------------------------------------------- */
-struct ak8972_config {
- char asa[COMPASS_NUM_AXES]; /* axis sensitivity adjustment */
-};
-
-struct ak8972_private_data {
- struct ak8972_config init;
-};
-
-/* -------------------------------------------------------------------------- */
-static int ak8972_init(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result;
- unsigned char serial_data[COMPASS_NUM_AXES];
-
- struct ak8972_private_data *private_data;
- private_data = (struct ak8972_private_data *)
- kzalloc(sizeof(struct ak8972_private_data), GFP_KERNEL);
-
- if (!private_data)
- return INV_ERROR_MEMORY_EXAUSTED;
-
- result = inv_serial_single_write(mlsl_handle, pdata->address,
- AK8972_REG_CNTL,
- AK8972_CNTL_MODE_POWER_DOWN);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- /* Wait at least 100us */
- udelay(100);
-
- result = inv_serial_single_write(mlsl_handle, pdata->address,
- AK8972_REG_CNTL,
- AK8972_CNTL_MODE_FUSE_ROM_ACCESS);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- /* Wait at least 200us */
- udelay(200);
-
- result = inv_serial_read(mlsl_handle, pdata->address,
- AK8972_REG_ASAX,
- COMPASS_NUM_AXES, serial_data);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- pdata->private_data = private_data;
-
- private_data->init.asa[0] = serial_data[0];
- private_data->init.asa[1] = serial_data[1];
- private_data->init.asa[2] = serial_data[2];
-
- result = inv_serial_single_write(mlsl_handle, pdata->address,
- AK8972_REG_CNTL,
- AK8972_CNTL_MODE_POWER_DOWN);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- udelay(100);
- return INV_SUCCESS;
-}
-
-static int ak8972_exit(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- kfree(pdata->private_data);
- return INV_SUCCESS;
-}
-
-static int ak8972_suspend(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- AK8972_REG_CNTL,
- AK8972_CNTL_MODE_POWER_DOWN);
- msleep(1); /* wait at least 100us */
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- return result;
-}
-
-static int ak8972_resume(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- AK8972_REG_CNTL,
- AK8972_CNTL_MODE_SINGLE_MEASUREMENT);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- return result;
-}
-
-static int ak8972_read(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata, unsigned char *data)
-{
- unsigned char regs[8];
- unsigned char *stat = &regs[0];
- unsigned char *stat2 = &regs[7];
- int result = INV_SUCCESS;
- int status = INV_SUCCESS;
-
- result =
- inv_serial_read(mlsl_handle, pdata->address, AK8972_REG_ST1,
- 8, regs);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- /* Always return the data and the status registers */
- memcpy(data, &regs[1], 6);
- data[6] = regs[0];
- data[7] = regs[7];
-
- /*
- * ST : data ready -
- * Measurement has been completed and data is ready to be read.
- */
- if (*stat & 0x01)
- status = INV_SUCCESS;
-
- /*
- * ST2 : data error -
- * occurs when data read is started outside of a readable period;
- * data read would not be correct.
- * Valid in continuous measurement mode only.
- * In single measurement mode this error should not occour but we
- * stil account for it and return an error, since the data would be
- * corrupted.
- * DERR bit is self-clearing when ST2 register is read.
- */
- if (*stat2 & 0x04)
- status = INV_ERROR_COMPASS_DATA_ERROR;
- /*
- * ST2 : overflow -
- * the sum of the absolute values of all axis |X|+|Y|+|Z| < 2400uT.
- * This is likely to happen in presence of an external magnetic
- * disturbance; it indicates, the sensor data is incorrect and should
- * be ignored.
- * An error is returned.
- * HOFL bit clears when a new measurement starts.
- */
- if (*stat2 & 0x08)
- status = INV_ERROR_COMPASS_DATA_OVERFLOW;
- /*
- * ST : overrun -
- * the previous sample was not fetched and lost.
- * Valid in continuous measurement mode only.
- * In single measurement mode this error should not occour and we
- * don't consider this condition an error.
- * DOR bit is self-clearing when ST2 or any meas. data register is
- * read.
- */
- if (*stat & 0x02) {
- /* status = INV_ERROR_COMPASS_DATA_UNDERFLOW; */
- status = INV_SUCCESS;
- }
-
- /*
- * trigger next measurement if:
- * - stat is non zero;
- * - if stat is zero and stat2 is non zero.
- * Won't trigger if data is not ready and there was no error.
- */
- if (*stat != 0x00 || *stat2 != 0x00) {
- result = inv_serial_single_write(
- mlsl_handle, pdata->address,
- AK8972_REG_CNTL, AK8972_CNTL_MODE_SINGLE_MEASUREMENT);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- }
-
- return status;
-}
-
-static int ak8972_config(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- struct ext_slave_config *data)
-{
- int result;
- if (!data->data)
- return INV_ERROR_INVALID_PARAMETER;
-
- switch (data->key) {
- case MPU_SLAVE_WRITE_REGISTERS:
- result = inv_serial_write(mlsl_handle, pdata->address,
- data->len,
- (unsigned char *)data->data);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- break;
- case MPU_SLAVE_CONFIG_ODR_SUSPEND:
- case MPU_SLAVE_CONFIG_ODR_RESUME:
- case MPU_SLAVE_CONFIG_FSR_SUSPEND:
- case MPU_SLAVE_CONFIG_FSR_RESUME:
- case MPU_SLAVE_CONFIG_MOT_THS:
- case MPU_SLAVE_CONFIG_NMOT_THS:
- case MPU_SLAVE_CONFIG_MOT_DUR:
- case MPU_SLAVE_CONFIG_NMOT_DUR:
- case MPU_SLAVE_CONFIG_IRQ_SUSPEND:
- case MPU_SLAVE_CONFIG_IRQ_RESUME:
- default:
- return INV_ERROR_FEATURE_NOT_IMPLEMENTED;
- };
-
- return INV_SUCCESS;
-}
-
-static int ak8972_get_config(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- struct ext_slave_config *data)
-{
- struct ak8972_private_data *private_data = pdata->private_data;
- int result;
- if (!data->data)
- return INV_ERROR_INVALID_PARAMETER;
-
- switch (data->key) {
- case MPU_SLAVE_READ_REGISTERS:
- {
- unsigned char *serial_data =
- (unsigned char *)data->data;
- result =
- inv_serial_read(mlsl_handle, pdata->address,
- serial_data[0], data->len - 1,
- &serial_data[1]);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- break;
- }
- case MPU_SLAVE_READ_SCALE:
- {
- unsigned char *serial_data =
- (unsigned char *)data->data;
- serial_data[0] = private_data->init.asa[0];
- serial_data[1] = private_data->init.asa[1];
- serial_data[2] = private_data->init.asa[2];
- result = INV_SUCCESS;
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- break;
- }
- case MPU_SLAVE_CONFIG_ODR_SUSPEND:
- (*(unsigned long *)data->data) = 0;
- break;
- case MPU_SLAVE_CONFIG_ODR_RESUME:
- (*(unsigned long *)data->data) = 8000;
- break;
- case MPU_SLAVE_CONFIG_FSR_SUSPEND:
- case MPU_SLAVE_CONFIG_FSR_RESUME:
- case MPU_SLAVE_CONFIG_MOT_THS:
- case MPU_SLAVE_CONFIG_NMOT_THS:
- case MPU_SLAVE_CONFIG_MOT_DUR:
- case MPU_SLAVE_CONFIG_NMOT_DUR:
- case MPU_SLAVE_CONFIG_IRQ_SUSPEND:
- case MPU_SLAVE_CONFIG_IRQ_RESUME:
- default:
- return INV_ERROR_FEATURE_NOT_IMPLEMENTED;
- };
-
- return INV_SUCCESS;
-}
-
-static struct ext_slave_read_trigger ak8972_read_trigger = {
- /*.reg = */ 0x0A,
- /*.value = */ 0x01
-};
-
-static struct ext_slave_descr ak8972_descr = {
- .init = ak8972_init,
- .exit = ak8972_exit,
- .suspend = ak8972_suspend,
- .resume = ak8972_resume,
- .read = ak8972_read,
- .config = ak8972_config,
- .get_config = ak8972_get_config,
- .name = "ak8972",
- .type = EXT_SLAVE_TYPE_COMPASS,
- .id = COMPASS_ID_AK8972,
- .read_reg = 0x01,
- .read_len = 9,
- .endian = EXT_SLAVE_LITTLE_ENDIAN,
- .range = {39321, 6000},
- .trigger = &ak8972_read_trigger,
-};
-
-static
-struct ext_slave_descr *ak8972_get_slave_descr(void)
-{
- return &ak8972_descr;
-}
-
-/* -------------------------------------------------------------------------- */
-struct ak8972_mod_private_data {
- struct i2c_client *client;
- struct ext_slave_platform_data *pdata;
-};
-
-static unsigned short normal_i2c[] = { I2C_CLIENT_END };
-
-static int ak8972_mod_probe(struct i2c_client *client,
- const struct i2c_device_id *devid)
-{
- struct ext_slave_platform_data *pdata;
- struct ak8972_mod_private_data *private_data;
- int result = 0;
-
- dev_info(&client->adapter->dev, "%s: %s\n", __func__, devid->name);
-
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
- result = -ENODEV;
- goto out_no_free;
- }
-
- pdata = client->dev.platform_data;
- if (!pdata) {
- dev_err(&client->adapter->dev,
- "Missing platform data for slave %s\n", devid->name);
- result = -EFAULT;
- goto out_no_free;
- }
-
- private_data = kzalloc(sizeof(*private_data), GFP_KERNEL);
- if (!private_data) {
- result = -ENOMEM;
- goto out_no_free;
- }
-
- i2c_set_clientdata(client, private_data);
- private_data->client = client;
- private_data->pdata = pdata;
-
- result = inv_mpu_register_slave(THIS_MODULE, client, pdata,
- ak8972_get_slave_descr);
- if (result) {
- dev_err(&client->adapter->dev,
- "Slave registration failed: %s, %d\n",
- devid->name, result);
- goto out_free_memory;
- }
-
- return result;
-
-out_free_memory:
- kfree(private_data);
-out_no_free:
- dev_err(&client->adapter->dev, "%s failed %d\n", __func__, result);
- return result;
-
-}
-
-static int ak8972_mod_remove(struct i2c_client *client)
-{
- struct ak8972_mod_private_data *private_data =
- i2c_get_clientdata(client);
-
- dev_dbg(&client->adapter->dev, "%s\n", __func__);
- inv_mpu_unregister_slave(client, private_data->pdata,
- ak8972_get_slave_descr);
-
- kfree(private_data);
- return 0;
-}
-
-static const struct i2c_device_id ak8972_mod_id[] = {
- { "ak8972", COMPASS_ID_AK8972 },
- {}
-};
-
-MODULE_DEVICE_TABLE(i2c, ak8972_mod_id);
-
-static struct i2c_driver ak8972_mod_driver = {
- .class = I2C_CLASS_HWMON,
- .probe = ak8972_mod_probe,
- .remove = ak8972_mod_remove,
- .id_table = ak8972_mod_id,
- .driver = {
- .owner = THIS_MODULE,
- .name = "ak8972_mod",
- },
- .address_list = normal_i2c,
-};
-
-static int __init ak8972_mod_init(void)
-{
- int res = i2c_add_driver(&ak8972_mod_driver);
- pr_info("%s: Probe name %s\n", __func__, "ak8972_mod");
- if (res)
- pr_err("%s failed\n", __func__);
- return res;
-}
-
-static void __exit ak8972_mod_exit(void)
-{
- pr_info("%s\n", __func__);
- i2c_del_driver(&ak8972_mod_driver);
-}
-
-module_init(ak8972_mod_init);
-module_exit(ak8972_mod_exit);
-
-MODULE_AUTHOR("Invensense Corporation");
-MODULE_DESCRIPTION("Driver to integrate AK8972 sensor with the MPU");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("ak8972_mod");
-
-/**
- * @}
- */
diff --git a/drivers/misc/inv_mpu/compass/ak8975.c b/drivers/misc/inv_mpu/compass/ak8975.c
deleted file mode 100644
index b8dea1b..0000000
--- a/drivers/misc/inv_mpu/compass/ak8975.c
+++ /dev/null
@@ -1,504 +0,0 @@
-/*
- $License:
- Copyright (C) 2011 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/>.
- $
- */
-
-/**
- * @addtogroup COMPASSDL
- *
- * @{
- * @file ak8975.c
- * @brief Magnetometer setup and handling methods for the AKM AK8975,
- * AKM AK8975B, and AKM AK8975C compass devices.
- */
-
-/* -------------------------------------------------------------------------- */
-
-#include <linux/i2c.h>
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/slab.h>
-#include <linux/delay.h>
-#include "mpu-dev.h"
-
-#include <log.h>
-#include <linux/mpu.h>
-#include "mlsl.h"
-#include "mldl_cfg.h"
-#undef MPL_LOG_TAG
-#define MPL_LOG_TAG "MPL-compass"
-
-/* -------------------------------------------------------------------------- */
-#define AK8975_REG_ST1 (0x02)
-#define AK8975_REG_HXL (0x03)
-#define AK8975_REG_ST2 (0x09)
-
-#define AK8975_REG_CNTL (0x0A)
-#define AK8975_REG_ASAX (0x10)
-#define AK8975_REG_ASAY (0x11)
-#define AK8975_REG_ASAZ (0x12)
-
-#define AK8975_CNTL_MODE_POWER_DOWN (0x10)
-#define AK8975_CNTL_MODE_SINGLE_MEASUREMENT (0x11)
-#define AK8975_CNTL_MODE_FUSE_ROM_ACCESS (0x1f)
-
-/* -------------------------------------------------------------------------- */
-struct ak8975_config {
- char asa[COMPASS_NUM_AXES]; /* axis sensitivity adjustment */
-};
-
-struct ak8975_private_data {
- struct ak8975_config init;
-};
-
-/* -------------------------------------------------------------------------- */
-static int ak8975_init(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result;
- unsigned char serial_data[COMPASS_NUM_AXES];
-
- struct ak8975_private_data *private_data;
- private_data = (struct ak8975_private_data *)
- kzalloc(sizeof(struct ak8975_private_data), GFP_KERNEL);
-
- if (!private_data)
- return INV_ERROR_MEMORY_EXAUSTED;
-
- result = inv_serial_single_write(mlsl_handle, pdata->address,
- AK8975_REG_CNTL,
- AK8975_CNTL_MODE_POWER_DOWN);
- if (result) {
- LOG_RESULT_LOCATION(result);
- kfree(private_data);
- return result;
- }
- /* Wait at least 100us */
- udelay(100);
-
- result = inv_serial_single_write(mlsl_handle, pdata->address,
- AK8975_REG_CNTL,
- AK8975_CNTL_MODE_FUSE_ROM_ACCESS);
- if (result) {
- LOG_RESULT_LOCATION(result);
- kfree(private_data);
- return result;
- }
-
- /* Wait at least 200us */
- udelay(200);
-
- result = inv_serial_read(mlsl_handle, pdata->address,
- AK8975_REG_ASAX,
- COMPASS_NUM_AXES, serial_data);
- if (result) {
- LOG_RESULT_LOCATION(result);
- kfree(private_data);
- return result;
- }
-
- pdata->private_data = private_data;
-
- private_data->init.asa[0] = serial_data[0];
- private_data->init.asa[1] = serial_data[1];
- private_data->init.asa[2] = serial_data[2];
-
- result = inv_serial_single_write(mlsl_handle, pdata->address,
- AK8975_REG_CNTL,
- AK8975_CNTL_MODE_POWER_DOWN);
- if (result) {
- LOG_RESULT_LOCATION(result);
- kfree(private_data);
- return result;
- }
-
- udelay(100);
- return INV_SUCCESS;
-}
-
-static int ak8975_exit(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- kfree(pdata->private_data);
- return INV_SUCCESS;
-}
-
-static int ak8975_suspend(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- AK8975_REG_CNTL,
- AK8975_CNTL_MODE_POWER_DOWN);
- msleep(20); /* wait at least 100us */
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- return result;
-}
-
-static int ak8975_resume(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- AK8975_REG_CNTL,
- AK8975_CNTL_MODE_SINGLE_MEASUREMENT);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- return result;
-}
-
-static int ak8975_read(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata, unsigned char *data)
-{
- unsigned char regs[8];
- unsigned char *stat = &regs[0];
- unsigned char *stat2 = &regs[7];
- int result = INV_SUCCESS;
- int status = INV_SUCCESS;
-
- result =
- inv_serial_read(mlsl_handle, pdata->address, AK8975_REG_ST1,
- 8, regs);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- /* Always return the data and the status registers */
- memcpy(data, &regs[1], 6);
- data[6] = regs[0];
- data[7] = regs[7];
-
- /*
- * ST : data ready -
- * Measurement has been completed and data is ready to be read.
- */
- if (*stat & 0x01)
- status = INV_SUCCESS;
-
- /*
- * ST2 : data error -
- * occurs when data read is started outside of a readable period;
- * data read would not be correct.
- * Valid in continuous measurement mode only.
- * In single measurement mode this error should not occour but we
- * stil account for it and return an error, since the data would be
- * corrupted.
- * DERR bit is self-clearing when ST2 register is read.
- */
- if (*stat2 & 0x04)
- status = INV_ERROR_COMPASS_DATA_ERROR;
- /*
- * ST2 : overflow -
- * the sum of the absolute values of all axis |X|+|Y|+|Z| < 2400uT.
- * This is likely to happen in presence of an external magnetic
- * disturbance; it indicates, the sensor data is incorrect and should
- * be ignored.
- * An error is returned.
- * HOFL bit clears when a new measurement starts.
- */
- if (*stat2 & 0x08)
- status = INV_ERROR_COMPASS_DATA_OVERFLOW;
- /*
- * ST : overrun -
- * the previous sample was not fetched and lost.
- * Valid in continuous measurement mode only.
- * In single measurement mode this error should not occour and we
- * don't consider this condition an error.
- * DOR bit is self-clearing when ST2 or any meas. data register is
- * read.
- */
- if (*stat & 0x02) {
- /* status = INV_ERROR_COMPASS_DATA_UNDERFLOW; */
- status = INV_SUCCESS;
- }
-
- /*
- * trigger next measurement if:
- * - stat is non zero;
- * - if stat is zero and stat2 is non zero.
- * Won't trigger if data is not ready and there was no error.
- */
- if (*stat != 0x00 || *stat2 != 0x00) {
- result = inv_serial_single_write(
- mlsl_handle, pdata->address,
- AK8975_REG_CNTL, AK8975_CNTL_MODE_SINGLE_MEASUREMENT);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- }
-
- return status;
-}
-
-static int ak8975_config(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- struct ext_slave_config *data)
-{
- int result;
- if (!data->data)
- return INV_ERROR_INVALID_PARAMETER;
-
- switch (data->key) {
- case MPU_SLAVE_WRITE_REGISTERS:
- result = inv_serial_write(mlsl_handle, pdata->address,
- data->len,
- (unsigned char *)data->data);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- break;
- case MPU_SLAVE_CONFIG_ODR_SUSPEND:
- case MPU_SLAVE_CONFIG_ODR_RESUME:
- case MPU_SLAVE_CONFIG_FSR_SUSPEND:
- case MPU_SLAVE_CONFIG_FSR_RESUME:
- case MPU_SLAVE_CONFIG_MOT_THS:
- case MPU_SLAVE_CONFIG_NMOT_THS:
- case MPU_SLAVE_CONFIG_MOT_DUR:
- case MPU_SLAVE_CONFIG_NMOT_DUR:
- case MPU_SLAVE_CONFIG_IRQ_SUSPEND:
- case MPU_SLAVE_CONFIG_IRQ_RESUME:
- default:
- return INV_ERROR_FEATURE_NOT_IMPLEMENTED;
- };
-
- return INV_SUCCESS;
-}
-
-static int ak8975_get_config(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- struct ext_slave_config *data)
-{
- struct ak8975_private_data *private_data = pdata->private_data;
- int result;
- if (!data->data)
- return INV_ERROR_INVALID_PARAMETER;
-
- switch (data->key) {
- case MPU_SLAVE_READ_REGISTERS:
- {
- unsigned char *serial_data =
- (unsigned char *)data->data;
- result =
- inv_serial_read(mlsl_handle, pdata->address,
- serial_data[0], data->len - 1,
- &serial_data[1]);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- break;
- }
- case MPU_SLAVE_READ_SCALE:
- {
- unsigned char *serial_data =
- (unsigned char *)data->data;
- serial_data[0] = private_data->init.asa[0];
- serial_data[1] = private_data->init.asa[1];
- serial_data[2] = private_data->init.asa[2];
- result = INV_SUCCESS;
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- break;
- }
- case MPU_SLAVE_CONFIG_ODR_SUSPEND:
- (*(unsigned long *)data->data) = 0;
- break;
- case MPU_SLAVE_CONFIG_ODR_RESUME:
- (*(unsigned long *)data->data) = 8000;
- break;
- case MPU_SLAVE_CONFIG_FSR_SUSPEND:
- case MPU_SLAVE_CONFIG_FSR_RESUME:
- case MPU_SLAVE_CONFIG_MOT_THS:
- case MPU_SLAVE_CONFIG_NMOT_THS:
- case MPU_SLAVE_CONFIG_MOT_DUR:
- case MPU_SLAVE_CONFIG_NMOT_DUR:
- case MPU_SLAVE_CONFIG_IRQ_SUSPEND:
- case MPU_SLAVE_CONFIG_IRQ_RESUME:
- default:
- return INV_ERROR_FEATURE_NOT_IMPLEMENTED;
- };
-
- return INV_SUCCESS;
-}
-
-static struct ext_slave_read_trigger ak8975_read_trigger = {
- /*.reg = */ 0x0A,
- /*.value = */ 0x01
-};
-
-static struct ext_slave_descr ak8975_descr = {
- .init = ak8975_init,
- .exit = ak8975_exit,
- .suspend = ak8975_suspend,
- .resume = ak8975_resume,
- .read = ak8975_read,
- .config = ak8975_config,
- .get_config = ak8975_get_config,
- .name = "ak8975",
- .type = EXT_SLAVE_TYPE_COMPASS,
- .id = COMPASS_ID_AK8975,
- .read_reg = 0x01,
- .read_len = 10,
- .endian = EXT_SLAVE_LITTLE_ENDIAN,
- .range = {9830, 4000},
- .trigger = &ak8975_read_trigger,
-};
-
-static
-struct ext_slave_descr *ak8975_get_slave_descr(void)
-{
- return &ak8975_descr;
-}
-
-/* -------------------------------------------------------------------------- */
-struct ak8975_mod_private_data {
- struct i2c_client *client;
- struct ext_slave_platform_data *pdata;
-};
-
-static unsigned short normal_i2c[] = { I2C_CLIENT_END };
-
-static int ak8975_mod_probe(struct i2c_client *client,
- const struct i2c_device_id *devid)
-{
- struct ext_slave_platform_data *pdata;
- struct ak8975_mod_private_data *private_data;
- int result = 0;
-
- dev_info(&client->adapter->dev, "%s: %s\n", __func__, devid->name);
-
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
- result = -ENODEV;
- goto out_no_free;
- }
-
- pdata = client->dev.platform_data;
- if (!pdata) {
- dev_err(&client->adapter->dev,
- "Missing platform data for slave %s\n", devid->name);
- result = -EFAULT;
- goto out_no_free;
- }
-
- private_data = kzalloc(sizeof(*private_data), GFP_KERNEL);
- if (!private_data) {
- result = -ENOMEM;
- goto out_no_free;
- }
-
- i2c_set_clientdata(client, private_data);
- private_data->client = client;
- private_data->pdata = pdata;
-
- result = inv_mpu_register_slave(THIS_MODULE, client, pdata,
- ak8975_get_slave_descr);
- if (result) {
- dev_err(&client->adapter->dev,
- "Slave registration failed: %s, %d\n",
- devid->name, result);
- goto out_free_memory;
- }
-
- return result;
-
-out_free_memory:
- kfree(private_data);
-out_no_free:
- dev_err(&client->adapter->dev, "%s failed %d\n", __func__, result);
- return result;
-
-}
-
-static int ak8975_mod_remove(struct i2c_client *client)
-{
- struct ak8975_mod_private_data *private_data =
- i2c_get_clientdata(client);
-
- dev_dbg(&client->adapter->dev, "%s\n", __func__);
- inv_mpu_unregister_slave(client, private_data->pdata,
- ak8975_get_slave_descr);
-
- kfree(private_data);
- return 0;
-}
-
-static const struct i2c_device_id ak8975_mod_id[] = {
- { "ak8975_mod", COMPASS_ID_AK8975 },
- {}
-};
-
-MODULE_DEVICE_TABLE(i2c, ak8975_mod_id);
-
-static struct i2c_driver ak8975_mod_driver = {
- .class = I2C_CLASS_HWMON,
- .probe = ak8975_mod_probe,
- .remove = ak8975_mod_remove,
- .id_table = ak8975_mod_id,
- .driver = {
- .owner = THIS_MODULE,
- .name = "ak8975_mod",
- },
- .address_list = normal_i2c,
-};
-
-static int __init ak8975_mod_init(void)
-{
- int res = i2c_add_driver(&ak8975_mod_driver);
- pr_info("%s: Probe name %s\n", __func__, "ak8975_mod");
- if (res)
- pr_err("%s failed\n", __func__);
- return res;
-}
-
-static void __exit ak8975_mod_exit(void)
-{
- pr_info("%s\n", __func__);
- i2c_del_driver(&ak8975_mod_driver);
-}
-
-module_init(ak8975_mod_init);
-module_exit(ak8975_mod_exit);
-
-MODULE_AUTHOR("Invensense Corporation");
-MODULE_DESCRIPTION("Driver to integrate AK8975 sensor with the MPU");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("ak8975_mod");
-
-/**
- * @}
- */
diff --git a/drivers/misc/inv_mpu/compass/hscdtd002b.c b/drivers/misc/inv_mpu/compass/hscdtd002b.c
deleted file mode 100644
index 4f6013c..0000000
--- a/drivers/misc/inv_mpu/compass/hscdtd002b.c
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- $License:
- Copyright (C) 2011 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/>.
- $
- */
-
-/**
- * @addtogroup COMPASSDL
- *
- * @{
- * @file hscdtd002b.c
- * @brief Magnetometer setup and handling methods for Alps HSCDTD002B
- * compass.
- */
-
-/* -------------------------------------------------------------------------- */
-
-#include <linux/i2c.h>
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/slab.h>
-#include <linux/delay.h>
-#include "mpu-dev.h"
-
-#include <log.h>
-#include <linux/mpu.h>
-#include "mlsl.h"
-#include "mldl_cfg.h"
-#undef MPL_LOG_TAG
-#define MPL_LOG_TAG "MPL-compass"
-
-/* -------------------------------------------------------------------------- */
-#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)
-
-/* -------------------------------------------------------------------------- */
-static int hscdtd002b_suspend(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
-
- /* Power mode: stand-by */
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- COMPASS_HSCDTD002B_CTRL1, 0x00);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- msleep(1); /* turn-off time */
-
- return result;
-}
-
-static int hscdtd002b_resume(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
-
- /* Soft reset */
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- COMPASS_HSCDTD002B_CTRL3, 0x80);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- /* Force state; Power mode: active */
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- COMPASS_HSCDTD002B_CTRL1, 0x82);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- /* Data ready enable */
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- COMPASS_HSCDTD002B_CTRL2, 0x08);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- msleep(1); /* turn-on time */
-
- return result;
-}
-
-static int hscdtd002b_read(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- unsigned char *data)
-{
- unsigned char stat;
- int result = INV_SUCCESS;
- int status = INV_SUCCESS;
-
- /* Read status reg. to check if data is ready */
- result =
- inv_serial_read(mlsl_handle, pdata->address,
- COMPASS_HSCDTD002B_STAT, 1, &stat);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- if (stat & 0x40) {
- result =
- inv_serial_read(mlsl_handle, pdata->address,
- COMPASS_HSCDTD002B_DATAX, 6,
- (unsigned char *)data);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- status = INV_SUCCESS;
- } else if (stat & 0x20) {
- status = INV_ERROR_COMPASS_DATA_OVERFLOW;
- } else {
- status = INV_ERROR_COMPASS_DATA_NOT_READY;
- }
- /* trigger next measurement read */
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- COMPASS_HSCDTD002B_CTRL3, 0x40);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- return status;
-}
-
-static struct ext_slave_descr hscdtd002b_descr = {
- .init = NULL,
- .exit = NULL,
- .suspend = hscdtd002b_suspend,
- .resume = hscdtd002b_resume,
- .read = hscdtd002b_read,
- .config = NULL,
- .get_config = NULL,
- .name = "hscdtd002b",
- .type = EXT_SLAVE_TYPE_COMPASS,
- .id = COMPASS_ID_HSCDTD002B,
- .read_reg = 0x10,
- .read_len = 6,
- .endian = EXT_SLAVE_LITTLE_ENDIAN,
- .range = {9830, 4000},
- .trigger = NULL,
-};
-
-static
-struct ext_slave_descr *hscdtd002b_get_slave_descr(void)
-{
- return &hscdtd002b_descr;
-}
-
-/* -------------------------------------------------------------------------- */
-struct hscdtd002b_mod_private_data {
- struct i2c_client *client;
- struct ext_slave_platform_data *pdata;
-};
-
-static unsigned short normal_i2c[] = { I2C_CLIENT_END };
-
-static int hscdtd002b_mod_probe(struct i2c_client *client,
- const struct i2c_device_id *devid)
-{
- struct ext_slave_platform_data *pdata;
- struct hscdtd002b_mod_private_data *private_data;
- int result = 0;
-
- dev_info(&client->adapter->dev, "%s: %s\n", __func__, devid->name);
-
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
- result = -ENODEV;
- goto out_no_free;
- }
-
- pdata = client->dev.platform_data;
- if (!pdata) {
- dev_err(&client->adapter->dev,
- "Missing platform data for slave %s\n", devid->name);
- result = -EFAULT;
- goto out_no_free;
- }
-
- private_data = kzalloc(sizeof(*private_data), GFP_KERNEL);
- if (!private_data) {
- result = -ENOMEM;
- goto out_no_free;
- }
-
- i2c_set_clientdata(client, private_data);
- private_data->client = client;
- private_data->pdata = pdata;
-
- result = inv_mpu_register_slave(THIS_MODULE, client, pdata,
- hscdtd002b_get_slave_descr);
- if (result) {
- dev_err(&client->adapter->dev,
- "Slave registration failed: %s, %d\n",
- devid->name, result);
- goto out_free_memory;
- }
-
- return result;
-
-out_free_memory:
- kfree(private_data);
-out_no_free:
- dev_err(&client->adapter->dev, "%s failed %d\n", __func__, result);
- return result;
-
-}
-
-static int hscdtd002b_mod_remove(struct i2c_client *client)
-{
- struct hscdtd002b_mod_private_data *private_data =
- i2c_get_clientdata(client);
-
- dev_dbg(&client->adapter->dev, "%s\n", __func__);
-
- inv_mpu_unregister_slave(client, private_data->pdata,
- hscdtd002b_get_slave_descr);
-
- kfree(private_data);
- return 0;
-}
-
-static const struct i2c_device_id hscdtd002b_mod_id[] = {
- { "hscdtd002b", COMPASS_ID_HSCDTD002B },
- {}
-};
-
-MODULE_DEVICE_TABLE(i2c, hscdtd002b_mod_id);
-
-static struct i2c_driver hscdtd002b_mod_driver = {
- .class = I2C_CLASS_HWMON,
- .probe = hscdtd002b_mod_probe,
- .remove = hscdtd002b_mod_remove,
- .id_table = hscdtd002b_mod_id,
- .driver = {
- .owner = THIS_MODULE,
- .name = "hscdtd002b_mod",
- },
- .address_list = normal_i2c,
-};
-
-static int __init hscdtd002b_mod_init(void)
-{
- int res = i2c_add_driver(&hscdtd002b_mod_driver);
- pr_info("%s: Probe name %s\n", __func__, "hscdtd002b_mod");
- if (res)
- pr_err("%s failed\n", __func__);
- return res;
-}
-
-static void __exit hscdtd002b_mod_exit(void)
-{
- pr_info("%s\n", __func__);
- i2c_del_driver(&hscdtd002b_mod_driver);
-}
-
-module_init(hscdtd002b_mod_init);
-module_exit(hscdtd002b_mod_exit);
-
-MODULE_AUTHOR("Invensense Corporation");
-MODULE_DESCRIPTION("Driver to integrate HSCDTD002B sensor with the MPU");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("hscdtd002b_mod");
-
-/**
- * @}
- */
diff --git a/drivers/misc/inv_mpu/compass/hscdtd004a.c b/drivers/misc/inv_mpu/compass/hscdtd004a.c
deleted file mode 100644
index f091559..0000000
--- a/drivers/misc/inv_mpu/compass/hscdtd004a.c
+++ /dev/null
@@ -1,318 +0,0 @@
-/*
- $License:
- Copyright (C) 2011 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/>.
- $
- */
-
-/**
- * @addtogroup COMPASSDL
- *
- * @{
- * @file hscdtd004a.c
- * @brief Magnetometer setup and handling methods for Alps HSCDTD004A
- * compass.
- */
-
-/* -------------------------------------------------------------------------- */
-
-#include <linux/i2c.h>
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/slab.h>
-#include <linux/delay.h>
-#include "mpu-dev.h"
-
-#include <log.h>
-#include <linux/mpu.h>
-#include "mlsl.h"
-#include "mldl_cfg.h"
-#undef MPL_LOG_TAG
-#define MPL_LOG_TAG "MPL-compass"
-
-/* -------------------------------------------------------------------------- */
-#define COMPASS_HSCDTD004A_STAT (0x18)
-#define COMPASS_HSCDTD004A_CTRL1 (0x1B)
-#define COMPASS_HSCDTD004A_CTRL2 (0x1C)
-#define COMPASS_HSCDTD004A_CTRL3 (0x1D)
-#define COMPASS_HSCDTD004A_DATAX (0x10)
-
-/* -------------------------------------------------------------------------- */
-
-static int hscdtd004a_suspend(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
-
- /* Power mode: stand-by */
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- COMPASS_HSCDTD004A_CTRL1, 0x00);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- msleep(1); /* turn-off time */
-
- return result;
-}
-
-static int hscdtd004a_init(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result;
- unsigned char data1, data2[2];
-
- result = inv_serial_read(mlsl_handle, pdata->address, 0xf, 1, &data1);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- result = inv_serial_read(mlsl_handle, pdata->address, 0xd, 2, data2);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- if (data1 != 0x49 || data2[0] != 0x45 || data2[1] != 0x54) {
- LOG_RESULT_LOCATION(INV_ERROR_SERIAL_DEVICE_NOT_RECOGNIZED);
- return INV_ERROR_SERIAL_DEVICE_NOT_RECOGNIZED;
- }
- return result;
-}
-
-static int hscdtd004a_resume(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
-
- /* Soft reset */
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- COMPASS_HSCDTD004A_CTRL3, 0x80);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- /* Normal state; Power mode: active */
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- COMPASS_HSCDTD004A_CTRL1, 0x82);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- /* Data ready enable */
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- COMPASS_HSCDTD004A_CTRL2, 0x7C);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- msleep(1); /* turn-on time */
- return result;
-}
-
-static int hscdtd004a_read(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- unsigned char *data)
-{
- unsigned char stat;
- int result = INV_SUCCESS;
- int status = INV_SUCCESS;
-
- /* Read status reg. to check if data is ready */
- result =
- inv_serial_read(mlsl_handle, pdata->address,
- COMPASS_HSCDTD004A_STAT, 1, &stat);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- if (stat & 0x48) {
- result =
- inv_serial_read(mlsl_handle, pdata->address,
- COMPASS_HSCDTD004A_DATAX, 6,
- (unsigned char *)data);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- status = INV_SUCCESS;
- } else if (stat & 0x68) {
- status = INV_ERROR_COMPASS_DATA_OVERFLOW;
- } else {
- status = INV_ERROR_COMPASS_DATA_NOT_READY;
- }
- /* trigger next measurement read */
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- COMPASS_HSCDTD004A_CTRL3, 0x40);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- return status;
-
-}
-
-static struct ext_slave_descr hscdtd004a_descr = {
- .init = hscdtd004a_init,
- .exit = NULL,
- .suspend = hscdtd004a_suspend,
- .resume = hscdtd004a_resume,
- .read = hscdtd004a_read,
- .config = NULL,
- .get_config = NULL,
- .name = "hscdtd004a",
- .type = EXT_SLAVE_TYPE_COMPASS,
- .id = COMPASS_ID_HSCDTD004A,
- .read_reg = 0x10,
- .read_len = 6,
- .endian = EXT_SLAVE_LITTLE_ENDIAN,
- .range = {9830, 4000},
- .trigger = NULL,
-};
-
-static
-struct ext_slave_descr *hscdtd004a_get_slave_descr(void)
-{
- return &hscdtd004a_descr;
-}
-
-/* -------------------------------------------------------------------------- */
-struct hscdtd004a_mod_private_data {
- struct i2c_client *client;
- struct ext_slave_platform_data *pdata;
-};
-
-static unsigned short normal_i2c[] = { I2C_CLIENT_END };
-
-static int hscdtd004a_mod_probe(struct i2c_client *client,
- const struct i2c_device_id *devid)
-{
- struct ext_slave_platform_data *pdata;
- struct hscdtd004a_mod_private_data *private_data;
- int result = 0;
-
- dev_info(&client->adapter->dev, "%s: %s\n", __func__, devid->name);
-
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
- result = -ENODEV;
- goto out_no_free;
- }
-
- pdata = client->dev.platform_data;
- if (!pdata) {
- dev_err(&client->adapter->dev,
- "Missing platform data for slave %s\n", devid->name);
- result = -EFAULT;
- goto out_no_free;
- }
-
- private_data = kzalloc(sizeof(*private_data), GFP_KERNEL);
- if (!private_data) {
- result = -ENOMEM;
- goto out_no_free;
- }
-
- i2c_set_clientdata(client, private_data);
- private_data->client = client;
- private_data->pdata = pdata;
-
- result = inv_mpu_register_slave(THIS_MODULE, client, pdata,
- hscdtd004a_get_slave_descr);
- if (result) {
- dev_err(&client->adapter->dev,
- "Slave registration failed: %s, %d\n",
- devid->name, result);
- goto out_free_memory;
- }
-
- return result;
-
-out_free_memory:
- kfree(private_data);
-out_no_free:
- dev_err(&client->adapter->dev, "%s failed %d\n", __func__, result);
- return result;
-
-}
-
-static int hscdtd004a_mod_remove(struct i2c_client *client)
-{
- struct hscdtd004a_mod_private_data *private_data =
- i2c_get_clientdata(client);
-
- dev_dbg(&client->adapter->dev, "%s\n", __func__);
-
- inv_mpu_unregister_slave(client, private_data->pdata,
- hscdtd004a_get_slave_descr);
-
- kfree(private_data);
- return 0;
-}
-
-static const struct i2c_device_id hscdtd004a_mod_id[] = {
- { "hscdtd004a", COMPASS_ID_HSCDTD004A },
- {}
-};
-
-MODULE_DEVICE_TABLE(i2c, hscdtd004a_mod_id);
-
-static struct i2c_driver hscdtd004a_mod_driver = {
- .class = I2C_CLASS_HWMON,
- .probe = hscdtd004a_mod_probe,
- .remove = hscdtd004a_mod_remove,
- .id_table = hscdtd004a_mod_id,
- .driver = {
- .owner = THIS_MODULE,
- .name = "hscdtd004a_mod",
- },
- .address_list = normal_i2c,
-};
-
-static int __init hscdtd004a_mod_init(void)
-{
- int res = i2c_add_driver(&hscdtd004a_mod_driver);
- pr_info("%s: Probe name %s\n", __func__, "hscdtd004a_mod");
- if (res)
- pr_err("%s failed\n", __func__);
- return res;
-}
-
-static void __exit hscdtd004a_mod_exit(void)
-{
- pr_info("%s\n", __func__);
- i2c_del_driver(&hscdtd004a_mod_driver);
-}
-
-module_init(hscdtd004a_mod_init);
-module_exit(hscdtd004a_mod_exit);
-
-MODULE_AUTHOR("Invensense Corporation");
-MODULE_DESCRIPTION("Driver to integrate HSCDTD004A sensor with the MPU");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("hscdtd004a_mod");
-
-/**
- * @}
- */
diff --git a/drivers/misc/inv_mpu/compass/lsm303dlx_m.c b/drivers/misc/inv_mpu/compass/lsm303dlx_m.c
deleted file mode 100644
index 32f8cdd..0000000
--- a/drivers/misc/inv_mpu/compass/lsm303dlx_m.c
+++ /dev/null
@@ -1,395 +0,0 @@
-/*
- $License:
- Copyright (C) 2011 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/>.
- $
- */
-
-/**
- * @addtogroup COMPASSDL
- *
- * @{
- * @file lsm303dlx_m.c
- * @brief Magnetometer setup and handling methods for ST LSM303
- * compass.
- * This magnetometer device is part of a combo chip with the
- * ST LIS331DLH accelerometer and the logic in entirely based
- * on the Honeywell HMC5883 magnetometer.
- */
-
-/* -------------------------------------------------------------------------- */
-
-#include <linux/i2c.h>
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/slab.h>
-#include <linux/delay.h>
-#include "mpu-dev.h"
-
-#include <log.h>
-#include <linux/mpu.h>
-#include "mlsl.h"
-#include "mldl_cfg.h"
-#undef MPL_LOG_TAG
-#define MPL_LOG_TAG "MPL-compass"
-
-/* -------------------------------------------------------------------------- */
-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
-};
-
-/* -------------------------------------------------------------------------- */
-
-static int lsm303dlx_m_suspend(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
-
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- LSM_REG_MODE, LSM_MODE_SLEEP);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- msleep(3);
-
- return result;
-}
-
-static int lsm303dlx_m_resume(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
-
- /* Use single measurement mode. Start at sleep state. */
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- LSM_REG_MODE, LSM_MODE_SLEEP);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- /* Config normal measurement */
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- LSM_REG_CONF_A, 0);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- /* Adjust gain to 320 LSB/Gauss */
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- LSM_REG_CONF_B, LSM_CONF_B_GAIN_5_5);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- return result;
-}
-
-static int lsm303dlx_m_read(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- unsigned char *data)
-{
- unsigned char stat;
- int result = INV_SUCCESS;
- short axis_fixed;
-
- /* Read status reg. to check if data is ready */
- result =
- inv_serial_read(mlsl_handle, pdata->address, LSM_REG_STATUS, 1,
- &stat);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- if (stat & 0x01) {
- result =
- inv_serial_read(mlsl_handle, pdata->address,
- LSM_REG_X_M, 6, (unsigned char *)data);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- /*drop data if overflows */
- if ((data[0] == 0xf0) || (data[2] == 0xf0)
- || (data[4] == 0xf0)) {
- /* trigger next measurement read */
- result =
- inv_serial_single_write(mlsl_handle,
- pdata->address,
- LSM_REG_MODE,
- LSM_MODE_SINGLE);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- return INV_ERROR_COMPASS_DATA_OVERFLOW;
- }
- /* convert to fixed point and apply sensitivity correction for
- Z-axis */
- axis_fixed =
- (short)((unsigned short)data[5] +
- (unsigned short)data[4] * 256);
- /* scale up by 1.125 (36/32) approximate of 1.122 (320/285) */
- if (slave->id == COMPASS_ID_LSM303DLM) {
- /* NOTE/IMPORTANT:
- lsm303dlm compass axis definition doesn't
- respect the right hand rule. We invert
- the sign of the Z axis to fix that. */
- axis_fixed = (short)(-1 * axis_fixed * 36);
- } else {
- axis_fixed = (short)(axis_fixed * 36);
- }
- data[4] = axis_fixed >> 8;
- data[5] = axis_fixed & 0xFF;
-
- axis_fixed =
- (short)((unsigned short)data[3] +
- (unsigned short)data[2] * 256);
- axis_fixed = (short)(axis_fixed * 32);
- data[2] = axis_fixed >> 8;
- data[3] = axis_fixed & 0xFF;
-
- axis_fixed =
- (short)((unsigned short)data[1] +
- (unsigned short)data[0] * 256);
- axis_fixed = (short)(axis_fixed * 32);
- data[0] = axis_fixed >> 8;
- data[1] = axis_fixed & 0xFF;
-
- /* trigger next measurement read */
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- LSM_REG_MODE, LSM_MODE_SINGLE);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- return INV_SUCCESS;
- } else {
- /* trigger next measurement read */
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- LSM_REG_MODE, LSM_MODE_SINGLE);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- return INV_ERROR_COMPASS_DATA_NOT_READY;
- }
-}
-
-static struct ext_slave_descr lsm303dlx_m_descr = {
- .init = NULL,
- .exit = NULL,
- .suspend = lsm303dlx_m_suspend,
- .resume = lsm303dlx_m_resume,
- .read = lsm303dlx_m_read,
- .config = NULL,
- .get_config = NULL,
- .name = "lsm303dlx_m",
- .type = EXT_SLAVE_TYPE_COMPASS,
- .id = ID_INVALID,
- .read_reg = 0x06,
- .read_len = 6,
- .endian = EXT_SLAVE_BIG_ENDIAN,
- .range = {10240, 0},
- .trigger = NULL,
-};
-
-static
-struct ext_slave_descr *lsm303dlx_m_get_slave_descr(void)
-{
- return &lsm303dlx_m_descr;
-}
-
-/* -------------------------------------------------------------------------- */
-struct lsm303dlx_m_mod_private_data {
- struct i2c_client *client;
- struct ext_slave_platform_data *pdata;
-};
-
-static const struct i2c_device_id lsm303dlx_m_mod_id[] = {
- { "lsm303dlh", COMPASS_ID_LSM303DLH },
- { "lsm303dlm", COMPASS_ID_LSM303DLM },
- {}
-};
-MODULE_DEVICE_TABLE(i2c, lsm303dlx_m_mod_id);
-
-static unsigned short normal_i2c[] = { I2C_CLIENT_END };
-
-static int lsm303dlx_m_mod_probe(struct i2c_client *client,
- const struct i2c_device_id *devid)
-{
- struct ext_slave_platform_data *pdata;
- struct lsm303dlx_m_mod_private_data *private_data;
- int result = 0;
-
- dev_info(&client->adapter->dev, "%s: %s\n", __func__, devid->name);
- lsm303dlx_m_descr.id = devid->driver_data;
-
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
- result = -ENODEV;
- goto out_no_free;
- }
-
- pdata = client->dev.platform_data;
- if (!pdata) {
- dev_err(&client->adapter->dev,
- "Missing platform data for slave %s\n", devid->name);
- result = -EFAULT;
- goto out_no_free;
- }
-
- private_data = kzalloc(sizeof(*private_data), GFP_KERNEL);
- if (!private_data) {
- result = -ENOMEM;
- goto out_no_free;
- }
-
- i2c_set_clientdata(client, private_data);
- private_data->client = client;
- private_data->pdata = pdata;
-
- result = inv_mpu_register_slave(THIS_MODULE, client, pdata,
- lsm303dlx_m_get_slave_descr);
- if (result) {
- dev_err(&client->adapter->dev,
- "Slave registration failed: %s, %d\n",
- devid->name, result);
- goto out_free_memory;
- }
-
- return result;
-
-out_free_memory:
- kfree(private_data);
-out_no_free:
- dev_err(&client->adapter->dev, "%s failed %d\n", __func__, result);
- return result;
-
-}
-
-static int lsm303dlx_m_mod_remove(struct i2c_client *client)
-{
- struct lsm303dlx_m_mod_private_data *private_data =
- i2c_get_clientdata(client);
-
- dev_dbg(&client->adapter->dev, "%s\n", __func__);
-
- inv_mpu_unregister_slave(client, private_data->pdata,
- lsm303dlx_m_get_slave_descr);
-
- kfree(private_data);
- return 0;
-}
-
-static struct i2c_driver lsm303dlx_m_mod_driver = {
- .class = I2C_CLASS_HWMON,
- .probe = lsm303dlx_m_mod_probe,
- .remove = lsm303dlx_m_mod_remove,
- .id_table = lsm303dlx_m_mod_id,
- .driver = {
- .owner = THIS_MODULE,
- .name = "lsm303dlx_m_mod",
- },
- .address_list = normal_i2c,
-};
-
-static int __init lsm303dlx_m_mod_init(void)
-{
- int res = i2c_add_driver(&lsm303dlx_m_mod_driver);
- pr_info("%s: Probe name %s\n", __func__, "lsm303dlx_m_mod");
- if (res)
- pr_err("%s failed\n", __func__);
- return res;
-}
-
-static void __exit lsm303dlx_m_mod_exit(void)
-{
- pr_info("%s\n", __func__);
- i2c_del_driver(&lsm303dlx_m_mod_driver);
-}
-
-module_init(lsm303dlx_m_mod_init);
-module_exit(lsm303dlx_m_mod_exit);
-
-MODULE_AUTHOR("Invensense Corporation");
-MODULE_DESCRIPTION("Driver to integrate lsm303dlx_m sensor with the MPU");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("lsm303dlx_m_mod");
-
-/**
- * @}
- */
diff --git a/drivers/misc/inv_mpu/compass/mmc314x.c b/drivers/misc/inv_mpu/compass/mmc314x.c
deleted file mode 100644
index 786fadc..0000000
--- a/drivers/misc/inv_mpu/compass/mmc314x.c
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- $License:
- Copyright (C) 2011 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/>.
- $
- */
-
-/**
- * @addtogroup COMPASSDL
- *
- * @{
- * @file mmc314x.c
- * @brief Magnetometer setup and handling methods for the
- * MEMSIC MMC314x compass.
- */
-
-/* -------------------------------------------------------------------------- */
-
-#include <linux/i2c.h>
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/slab.h>
-#include <linux/delay.h>
-#include "mpu-dev.h"
-
-#include <log.h>
-#include <linux/mpu.h>
-#include "mlsl.h"
-#include "mldl_cfg.h"
-#undef MPL_LOG_TAG
-#define MPL_LOG_TAG "MPL-compass"
-
-/* -------------------------------------------------------------------------- */
-
-static int reset_int = 1000;
-static int read_count = 1;
-static char reset_mode; /* in Z-init section */
-
-/* -------------------------------------------------------------------------- */
-#define MMC314X_REG_ST (0x00)
-#define MMC314X_REG_X_MSB (0x01)
-
-#define MMC314X_CNTL_MODE_WAKE_UP (0x01)
-#define MMC314X_CNTL_MODE_SET (0x02)
-#define MMC314X_CNTL_MODE_RESET (0x04)
-
-/* -------------------------------------------------------------------------- */
-
-static int mmc314x_suspend(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
-
- return result;
-}
-
-static int mmc314x_resume(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
-
- int result;
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- MMC314X_REG_ST, MMC314X_CNTL_MODE_RESET);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- msleep(10);
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- MMC314X_REG_ST, MMC314X_CNTL_MODE_SET);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- msleep(10);
- read_count = 1;
- return INV_SUCCESS;
-}
-
-static int mmc314x_read(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- unsigned char *data)
-{
- int result, ii;
- short tmp[3];
- unsigned char tmpdata[6];
-
- if (read_count > 1000)
- read_count = 1;
-
- result =
- inv_serial_read(mlsl_handle, pdata->address, MMC314X_REG_X_MSB,
- 6, (unsigned char *)data);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- for (ii = 0; ii < 6; ii++)
- tmpdata[ii] = data[ii];
-
- for (ii = 0; ii < 3; ii++) {
- tmp[ii] = (short)((tmpdata[2 * ii] << 8) + tmpdata[2 * ii + 1]);
- tmp[ii] = tmp[ii] - 4096;
- tmp[ii] = tmp[ii] * 16;
- }
-
- for (ii = 0; ii < 3; ii++) {
- data[2 * ii] = (unsigned char)(tmp[ii] >> 8);
- data[2 * ii + 1] = (unsigned char)(tmp[ii]);
- }
-
- if (read_count % reset_int == 0) {
- if (reset_mode) {
- result =
- inv_serial_single_write(mlsl_handle,
- pdata->address,
- MMC314X_REG_ST,
- MMC314X_CNTL_MODE_RESET);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- reset_mode = 0;
- return INV_ERROR_COMPASS_DATA_NOT_READY;
- } else {
- result =
- inv_serial_single_write(mlsl_handle,
- pdata->address,
- MMC314X_REG_ST,
- MMC314X_CNTL_MODE_SET);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- reset_mode = 1;
- read_count++;
- return INV_ERROR_COMPASS_DATA_NOT_READY;
- }
- }
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- MMC314X_REG_ST, MMC314X_CNTL_MODE_WAKE_UP);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- read_count++;
-
- return INV_SUCCESS;
-}
-
-static struct ext_slave_descr mmc314x_descr = {
- .init = NULL,
- .exit = NULL,
- .suspend = mmc314x_suspend,
- .resume = mmc314x_resume,
- .read = mmc314x_read,
- .config = NULL,
- .get_config = NULL,
- .name = "mmc314x",
- .type = EXT_SLAVE_TYPE_COMPASS,
- .id = COMPASS_ID_MMC314X,
- .read_reg = 0x01,
- .read_len = 6,
- .endian = EXT_SLAVE_BIG_ENDIAN,
- .range = {400, 0},
- .trigger = NULL,
-};
-
-static
-struct ext_slave_descr *mmc314x_get_slave_descr(void)
-{
- return &mmc314x_descr;
-}
-
-/* -------------------------------------------------------------------------- */
-struct mmc314x_mod_private_data {
- struct i2c_client *client;
- struct ext_slave_platform_data *pdata;
-};
-
-static unsigned short normal_i2c[] = { I2C_CLIENT_END };
-
-static int mmc314x_mod_probe(struct i2c_client *client,
- const struct i2c_device_id *devid)
-{
- struct ext_slave_platform_data *pdata;
- struct mmc314x_mod_private_data *private_data;
- int result = 0;
-
- dev_info(&client->adapter->dev, "%s: %s\n", __func__, devid->name);
-
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
- result = -ENODEV;
- goto out_no_free;
- }
-
- pdata = client->dev.platform_data;
- if (!pdata) {
- dev_err(&client->adapter->dev,
- "Missing platform data for slave %s\n", devid->name);
- result = -EFAULT;
- goto out_no_free;
- }
-
- private_data = kzalloc(sizeof(*private_data), GFP_KERNEL);
- if (!private_data) {
- result = -ENOMEM;
- goto out_no_free;
- }
-
- i2c_set_clientdata(client, private_data);
- private_data->client = client;
- private_data->pdata = pdata;
-
- result = inv_mpu_register_slave(THIS_MODULE, client, pdata,
- mmc314x_get_slave_descr);
- if (result) {
- dev_err(&client->adapter->dev,
- "Slave registration failed: %s, %d\n",
- devid->name, result);
- goto out_free_memory;
- }
-
- return result;
-
-out_free_memory:
- kfree(private_data);
-out_no_free:
- dev_err(&client->adapter->dev, "%s failed %d\n", __func__, result);
- return result;
-
-}
-
-static int mmc314x_mod_remove(struct i2c_client *client)
-{
- struct mmc314x_mod_private_data *private_data =
- i2c_get_clientdata(client);
-
- dev_dbg(&client->adapter->dev, "%s\n", __func__);
-
- inv_mpu_unregister_slave(client, private_data->pdata,
- mmc314x_get_slave_descr);
-
- kfree(private_data);
- return 0;
-}
-
-static const struct i2c_device_id mmc314x_mod_id[] = {
- { "mmc314x", COMPASS_ID_MMC314X },
- {}
-};
-
-MODULE_DEVICE_TABLE(i2c, mmc314x_mod_id);
-
-static struct i2c_driver mmc314x_mod_driver = {
- .class = I2C_CLASS_HWMON,
- .probe = mmc314x_mod_probe,
- .remove = mmc314x_mod_remove,
- .id_table = mmc314x_mod_id,
- .driver = {
- .owner = THIS_MODULE,
- .name = "mmc314x_mod",
- },
- .address_list = normal_i2c,
-};
-
-static int __init mmc314x_mod_init(void)
-{
- int res = i2c_add_driver(&mmc314x_mod_driver);
- pr_info("%s: Probe name %s\n", __func__, "mmc314x_mod");
- if (res)
- pr_err("%s failed\n", __func__);
- return res;
-}
-
-static void __exit mmc314x_mod_exit(void)
-{
- pr_info("%s\n", __func__);
- i2c_del_driver(&mmc314x_mod_driver);
-}
-
-module_init(mmc314x_mod_init);
-module_exit(mmc314x_mod_exit);
-
-MODULE_AUTHOR("Invensense Corporation");
-MODULE_DESCRIPTION("Driver to integrate MMC314X sensor with the MPU");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("mmc314x_mod");
-
-/**
- * @}
- */
diff --git a/drivers/misc/inv_mpu/compass/yas529-kernel.c b/drivers/misc/inv_mpu/compass/yas529-kernel.c
deleted file mode 100644
index f53223f..0000000
--- a/drivers/misc/inv_mpu/compass/yas529-kernel.c
+++ /dev/null
@@ -1,611 +0,0 @@
-/*
- $License:
- Copyright (C) 2011 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/>.
- $
- */
-
-/* -------------------------------------------------------------------------- */
-
-#include <linux/i2c.h>
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/slab.h>
-#include <linux/delay.h>
-#include "mpu-dev.h"
-
-#include <log.h>
-#include <linux/mpu.h>
-#include "mlsl.h"
-#include "mldl_cfg.h"
-#undef MPL_LOG_TAG
-#define MPL_LOG_TAG "MPL-acc"
-
-/*----- YAMAHA YAS529 Registers ------*/
-enum YAS_REG {
- YAS_REG_CMDR = 0x00, /* 000 < 5 */
- YAS_REG_XOFFSETR = 0x20, /* 001 < 5 */
- YAS_REG_Y1OFFSETR = 0x40, /* 010 < 5 */
- YAS_REG_Y2OFFSETR = 0x60, /* 011 < 5 */
- YAS_REG_ICOILR = 0x80, /* 100 < 5 */
- YAS_REG_CAL = 0xA0, /* 101 < 5 */
- YAS_REG_CONFR = 0xC0, /* 110 < 5 */
- YAS_REG_DOUTR = 0xE0 /* 111 < 5 */
-};
-
-/* -------------------------------------------------------------------------- */
-
-static long a1;
-static long a2;
-static long a3;
-static long a4;
-static long a5;
-static long a6;
-static long a7;
-static long a8;
-static long a9;
-
-/* -------------------------------------------------------------------------- */
-static int yas529_sensor_i2c_write(struct i2c_adapter *i2c_adap,
- unsigned char address,
- unsigned int len, unsigned char *data)
-{
- struct i2c_msg msgs[1];
- int res;
-
- if (NULL == data || NULL == i2c_adap)
- return -EINVAL;
-
- msgs[0].addr = address;
- msgs[0].flags = 0; /* write */
- msgs[0].buf = (unsigned char *)data;
- msgs[0].len = len;
-
- res = i2c_transfer(i2c_adap, msgs, 1);
- if (res < 1)
- return res;
- else
- return 0;
-}
-
-static int yas529_sensor_i2c_read(struct i2c_adapter *i2c_adap,
- unsigned char address,
- unsigned char reg,
- unsigned int len, unsigned char *data)
-{
- struct i2c_msg msgs[2];
- int res;
-
- if (NULL == data || NULL == i2c_adap)
- return -EINVAL;
-
- msgs[0].addr = address;
- msgs[0].flags = I2C_M_RD;
- msgs[0].buf = data;
- msgs[0].len = len;
-
- res = i2c_transfer(i2c_adap, msgs, 1);
- if (res < 1)
- return res;
- else
- return 0;
-}
-
-static int yas529_suspend(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
-
- return result;
-}
-
-static int yas529_resume(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
-
- unsigned char dummyData[1] = { 0 };
- unsigned char dummyRegister = 0;
- unsigned char rawData[6];
- unsigned char calData[9];
-
- short xoffset, y1offset, y2offset;
- short d2, d3, d4, d5, d6, d7, d8, d9;
-
- /* YAS529 Application Manual MS-3C - Section 4.4.5 */
- /* =============================================== */
- /* Step 1 - register initialization */
- /* zero initialization coil register - "100 00 000" */
- dummyData[0] = YAS_REG_ICOILR | 0x00;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- /* zero config register - "110 00 000" */
- dummyData[0] = YAS_REG_CONFR | 0x00;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- /* Step 2 - initialization coil operation */
- dummyData[0] = YAS_REG_ICOILR | 0x11;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_ICOILR | 0x01;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_ICOILR | 0x12;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_ICOILR | 0x02;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_ICOILR | 0x13;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_ICOILR | 0x03;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_ICOILR | 0x14;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_ICOILR | 0x04;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_ICOILR | 0x15;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_ICOILR | 0x05;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_ICOILR | 0x16;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_ICOILR | 0x06;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_ICOILR | 0x17;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_ICOILR | 0x07;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_ICOILR | 0x10;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_ICOILR | 0x00;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- /* Step 3 - rough offset measurement */
- /* Config register - Measurements results - "110 00 000" */
- dummyData[0] = YAS_REG_CONFR | 0x00;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- /* Measurements command register - Rough offset measurement -
- "000 00001" */
- dummyData[0] = YAS_REG_CMDR | 0x01;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- msleep(2); /* wait at least 1.5ms */
-
- /* Measurement data read */
- result =
- yas529_sensor_i2c_read(mlsl_handle, pdata->address,
- dummyRegister, 6, rawData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- xoffset =
- (short)((unsigned short)rawData[5] +
- ((unsigned short)rawData[4] & 0x7) * 256) - 5;
- if (xoffset < 0)
- xoffset = 0;
- y1offset =
- (short)((unsigned short)rawData[3] +
- ((unsigned short)rawData[2] & 0x7) * 256) - 5;
- if (y1offset < 0)
- y1offset = 0;
- y2offset =
- (short)((unsigned short)rawData[1] +
- ((unsigned short)rawData[0] & 0x7) * 256) - 5;
- if (y2offset < 0)
- y2offset = 0;
-
- /* Step 4 - rough offset setting */
- /* Set rough offset register values */
- dummyData[0] = YAS_REG_XOFFSETR | xoffset;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_Y1OFFSETR | y1offset;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- dummyData[0] = YAS_REG_Y2OFFSETR | y2offset;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- /* CAL matrix read (first read is invalid) */
- /* Config register - CAL register read - "110 01 000" */
- dummyData[0] = YAS_REG_CONFR | 0x08;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- /* CAL data read */
- result =
- yas529_sensor_i2c_read(mlsl_handle, pdata->address,
- dummyRegister, 9, calData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- /* Config register - CAL register read - "110 01 000" */
- dummyData[0] = YAS_REG_CONFR | 0x08;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- /* CAL data read */
- result =
- yas529_sensor_i2c_read(mlsl_handle, pdata->address,
- dummyRegister, 9, calData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- /* Calculate coefficients of the sensitivity correction matrix */
- a1 = 100;
- d2 = (calData[0] & 0xFC) >> 2; /* [71..66] 6bit */
- a2 = (short)(d2 - 32);
- /* [65..62] 4bit */
- d3 = ((calData[0] & 0x03) << 2) | ((calData[1] & 0xC0) >> 6);
- a3 = (short)(d3 - 8);
- d4 = (calData[1] & 0x3F); /* [61..56] 6bit */
- a4 = (short)(d4 - 32);
- d5 = (calData[2] & 0xFC) >> 2; /* [55..50] 6bit */
- a5 = (short)(d5 - 32) + 70;
- /* [49..44] 6bit */
- d6 = ((calData[2] & 0x03) << 4) | ((calData[3] & 0xF0) >> 4);
- a6 = (short)(d6 - 32);
- /* [43..38] 6bit */
- d7 = ((calData[3] & 0x0F) << 2) | ((calData[4] & 0xC0) >> 6);
- a7 = (short)(d7 - 32);
- d8 = (calData[4] & 0x3F); /* [37..32] 6bit */
- a8 = (short)(d8 - 32);
- d9 = (calData[5] & 0xFE) >> 1; /* [31..25] 7bit */
- a9 = (short)(d9 - 64) + 130;
-
- return result;
-}
-
-static int yas529_read(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- unsigned char *data)
-{
- unsigned char stat;
- unsigned char rawData[6];
- unsigned char dummyData[1] = { 0 };
- unsigned char dummyRegister = 0;
- int result = INV_SUCCESS;
- short SX, SY1, SY2, SY, SZ;
- short row1fixed, row2fixed, row3fixed;
-
- /* Config register - Measurements results - "110 00 000" */
- dummyData[0] = YAS_REG_CONFR | 0x00;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- /* Measurements command register - Normal magnetic field measurement -
- "000 00000" */
- dummyData[0] = YAS_REG_CMDR | 0x00;
- result =
- yas529_sensor_i2c_write(mlsl_handle, pdata->address, 1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- msleep(10);
- /* Measurement data read */
- result =
- yas529_sensor_i2c_read(mlsl_handle, pdata->address,
- dummyRegister, 6, (unsigned char *)&rawData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- stat = rawData[0] & 0x80;
- if (stat == 0x00) {
- /* Extract raw data */
- SX = (short)((unsigned short)rawData[5] +
- ((unsigned short)rawData[4] & 0x7) * 256);
- SY1 =
- (short)((unsigned short)rawData[3] +
- ((unsigned short)rawData[2] & 0x7) * 256);
- SY2 =
- (short)((unsigned short)rawData[1] +
- ((unsigned short)rawData[0] & 0x7) * 256);
- if ((SX <= 1) || (SY1 <= 1) || (SY2 <= 1))
- return INV_ERROR_COMPASS_DATA_UNDERFLOW;
- if ((SX >= 1024) || (SY1 >= 1024) || (SY2 >= 1024))
- return INV_ERROR_COMPASS_DATA_OVERFLOW;
- /* Convert to XYZ axis */
- SX = -1 * SX;
- SY = SY2 - SY1;
- SZ = SY1 + SY2;
-
- /* Apply sensitivity correction matrix */
- row1fixed = (short)((a1 * SX + a2 * SY + a3 * SZ) >> 7) * 41;
- row2fixed = (short)((a4 * SX + a5 * SY + a6 * SZ) >> 7) * 41;
- row3fixed = (short)((a7 * SX + a8 * SY + a9 * SZ) >> 7) * 41;
-
- data[0] = row1fixed >> 8;
- data[1] = row1fixed & 0xFF;
- data[2] = row2fixed >> 8;
- data[3] = row2fixed & 0xFF;
- data[4] = row3fixed >> 8;
- data[5] = row3fixed & 0xFF;
-
- return INV_SUCCESS;
- } else {
- return INV_ERROR_COMPASS_DATA_NOT_READY;
- }
-}
-
-static struct ext_slave_descr yas529_descr = {
- .init = NULL,
- .exit = NULL,
- .suspend = yas529_suspend,
- .resume = yas529_resume,
- .read = yas529_read,
- .config = NULL,
- .get_config = NULL,
- .name = "yas529",
- .type = EXT_SLAVE_TYPE_COMPASS,
- .id = COMPASS_ID_YAS529,
- .read_reg = 0x06,
- .read_len = 6,
- .endian = EXT_SLAVE_BIG_ENDIAN,
- .range = {19660, 8000},
- .trigger = NULL,
-};
-
-static
-struct ext_slave_descr *yas529_get_slave_descr(void)
-{
- return &yas529_descr;
-}
-
-/* -------------------------------------------------------------------------- */
-struct yas529_mod_private_data {
- struct i2c_client *client;
- struct ext_slave_platform_data *pdata;
-};
-
-static unsigned short normal_i2c[] = { I2C_CLIENT_END };
-
-static int yas529_mod_probe(struct i2c_client *client,
- const struct i2c_device_id *devid)
-{
- struct ext_slave_platform_data *pdata;
- struct yas529_mod_private_data *private_data;
- int result = 0;
-
- dev_info(&client->adapter->dev, "%s: %s\n", __func__, devid->name);
-
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
- result = -ENODEV;
- goto out_no_free;
- }
-
- pdata = client->dev.platform_data;
- if (!pdata) {
- dev_err(&client->adapter->dev,
- "Missing platform data for slave %s\n", devid->name);
- result = -EFAULT;
- goto out_no_free;
- }
-
- private_data = kzalloc(sizeof(*private_data), GFP_KERNEL);
- if (!private_data) {
- result = -ENOMEM;
- goto out_no_free;
- }
-
- i2c_set_clientdata(client, private_data);
- private_data->client = client;
- private_data->pdata = pdata;
-
- result = inv_mpu_register_slave(THIS_MODULE, client, pdata,
- yas529_get_slave_descr);
- if (result) {
- dev_err(&client->adapter->dev,
- "Slave registration failed: %s, %d\n",
- devid->name, result);
- goto out_free_memory;
- }
-
- return result;
-
-out_free_memory:
- kfree(private_data);
-out_no_free:
- dev_err(&client->adapter->dev, "%s failed %d\n", __func__, result);
- return result;
-
-}
-
-static int yas529_mod_remove(struct i2c_client *client)
-{
- struct yas529_mod_private_data *private_data =
- i2c_get_clientdata(client);
-
- dev_dbg(&client->adapter->dev, "%s\n", __func__);
-
- inv_mpu_unregister_slave(client, private_data->pdata,
- yas529_get_slave_descr);
-
- kfree(private_data);
- return 0;
-}
-
-static const struct i2c_device_id yas529_mod_id[] = {
- { "yas529", COMPASS_ID_YAS529 },
- {}
-};
-
-MODULE_DEVICE_TABLE(i2c, yas529_mod_id);
-
-static struct i2c_driver yas529_mod_driver = {
- .class = I2C_CLASS_HWMON,
- .probe = yas529_mod_probe,
- .remove = yas529_mod_remove,
- .id_table = yas529_mod_id,
- .driver = {
- .owner = THIS_MODULE,
- .name = "yas529_mod",
- },
- .address_list = normal_i2c,
-};
-
-static int __init yas529_mod_init(void)
-{
- int res = i2c_add_driver(&yas529_mod_driver);
- pr_info("%s: Probe name %s\n", __func__, "yas529_mod");
- if (res)
- pr_err("%s failed\n", __func__);
- return res;
-}
-
-static void __exit yas529_mod_exit(void)
-{
- pr_info("%s\n", __func__);
- i2c_del_driver(&yas529_mod_driver);
-}
-
-module_init(yas529_mod_init);
-module_exit(yas529_mod_exit);
-
-MODULE_AUTHOR("Invensense Corporation");
-MODULE_DESCRIPTION("Driver to integrate YAS529 sensor with the MPU");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("yas529_mod");
-
-/**
- * @}
- */
diff --git a/drivers/misc/inv_mpu/compass/yas530.c b/drivers/misc/inv_mpu/compass/yas530.c
deleted file mode 100644
index 263990f..0000000
--- a/drivers/misc/inv_mpu/compass/yas530.c
+++ /dev/null
@@ -1,596 +0,0 @@
-/*
- $License:
- Copyright (C) 2011 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/>.
- $
- */
-
-/**
- * @addtogroup COMPASSDL
- *
- * @{
- * @file yas530.c
- * @brief Magnetometer setup and handling methods for Yamaha YAS530
- * compass when used in a user-space solution (no kernel driver).
- */
-
-/* -------------------------------------------------------------------------- */
-
-#include <linux/i2c.h>
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/slab.h>
-
-#include <linux/module.h>
-#include <linux/delay.h>
-#include "mpu-dev.h"
-
-#include "log.h"
-#include <linux/mpu_411.h>
-#include "mlsl.h"
-#include "mldl_cfg.h"
-#undef MPL_LOG_TAG
-#define MPL_LOG_TAG "MPL-compass"
-
-/* -------------------------------------------------------------------------- */
-#define YAS530_REGADDR_DEVICE_ID (0x80)
-#define YAS530_REGADDR_ACTUATE_INIT_COIL (0x81)
-#define YAS530_REGADDR_MEASURE_COMMAND (0x82)
-#define YAS530_REGADDR_CONFIG (0x83)
-#define YAS530_REGADDR_MEASURE_INTERVAL (0x84)
-#define YAS530_REGADDR_OFFSET_X (0x85)
-#define YAS530_REGADDR_OFFSET_Y1 (0x86)
-#define YAS530_REGADDR_OFFSET_Y2 (0x87)
-#define YAS530_REGADDR_TEST1 (0x88)
-#define YAS530_REGADDR_TEST2 (0x89)
-#define YAS530_REGADDR_CAL (0x90)
-#define YAS530_REGADDR_MEASURE_DATA (0xb0)
-
-/* -------------------------------------------------------------------------- */
-static int Cx, Cy1, Cy2;
-static int /*a1, */ a2, a3, a4, a5, a6, a7, a8, a9;
-static int k;
-
-static unsigned char dx, dy1, dy2;
-static unsigned char d2, d3, d4, d5, d6, d7, d8, d9, d0;
-static unsigned char dck;
-
-/* -------------------------------------------------------------------------- */
-
-static int set_hardware_offset(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- char offset_x, char offset_y1, char offset_y2)
-{
- char data;
- int result = INV_SUCCESS;
-
- data = offset_x & 0x3f;
- result = inv_serial_single_write(mlsl_handle, pdata->address,
- YAS530_REGADDR_OFFSET_X, data);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- data = offset_y1 & 0x3f;
- result = inv_serial_single_write(mlsl_handle, pdata->address,
- YAS530_REGADDR_OFFSET_Y1, data);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- data = offset_y2 & 0x3f;
- result = inv_serial_single_write(mlsl_handle, pdata->address,
- YAS530_REGADDR_OFFSET_Y2, data);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- return result;
-}
-
-static int set_measure_command(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- int ldtc, int fors, int dlymes)
-{
- int result = INV_SUCCESS;
-
- result = inv_serial_single_write(mlsl_handle, pdata->address,
- YAS530_REGADDR_MEASURE_COMMAND, 0x01);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- return result;
-}
-
-static int measure_normal(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- int *busy, unsigned short *t,
- unsigned short *x, unsigned short *y1,
- unsigned short *y2)
-{
- unsigned char data[8];
- unsigned short b, to, xo, y1o, y2o;
- int result;
- ktime_t sleeptime;
- result = set_measure_command(mlsl_handle, slave, pdata, 0, 0, 0);
- sleeptime = ktime_set(0, 2 * NSEC_PER_MSEC);
- set_current_state(TASK_UNINTERRUPTIBLE);
- schedule_hrtimeout(&sleeptime, HRTIMER_MODE_REL);
-
- result = inv_serial_read(mlsl_handle, pdata->address,
- YAS530_REGADDR_MEASURE_DATA, 8, data);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- b = (data[0] >> 7) & 0x01;
- to = ((data[0] << 2) & 0x1fc) | ((data[1] >> 6) & 0x03);
- xo = ((data[2] << 5) & 0xfe0) | ((data[3] >> 3) & 0x1f);
- y1o = ((data[4] << 5) & 0xfe0) | ((data[5] >> 3) & 0x1f);
- y2o = ((data[6] << 5) & 0xfe0) | ((data[7] >> 3) & 0x1f);
-
- *busy = b;
- *t = to;
- *x = xo;
- *y1 = y1o;
- *y2 = y2o;
-
- return result;
-}
-
-static int check_offset(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- char offset_x, char offset_y1, char offset_y2,
- int *flag_x, int *flag_y1, int *flag_y2)
-{
- int result;
- int busy;
- short t, x, y1, y2;
-
- result = set_hardware_offset(mlsl_handle, slave, pdata,
- offset_x, offset_y1, offset_y2);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- result = measure_normal(mlsl_handle, slave, pdata,
- &busy, &t, &x, &y1, &y2);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- *flag_x = 0;
- *flag_y1 = 0;
- *flag_y2 = 0;
-
- if (x > 2048)
- *flag_x = 1;
- if (y1 > 2048)
- *flag_y1 = 1;
- if (y2 > 2048)
- *flag_y2 = 1;
- if (x < 2048)
- *flag_x = -1;
- if (y1 < 2048)
- *flag_y1 = -1;
- if (y2 < 2048)
- *flag_y2 = -1;
-
- return result;
-}
-
-static int measure_and_set_offset(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- char *offset)
-{
- int i;
- int result = INV_SUCCESS;
- char offset_x = 0, offset_y1 = 0, offset_y2 = 0;
- int flag_x = 0, flag_y1 = 0, flag_y2 = 0;
- static const int correct[5] = { 16, 8, 4, 2, 1 };
-
- for (i = 0; i < 5; i++) {
- result = check_offset(mlsl_handle, slave, pdata,
- offset_x, offset_y1, offset_y2,
- &flag_x, &flag_y1, &flag_y2);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- if (flag_x)
- offset_x += flag_x * correct[i];
- if (flag_y1)
- offset_y1 += flag_y1 * correct[i];
- if (flag_y2)
- offset_y2 += flag_y2 * correct[i];
- }
-
- result = set_hardware_offset(mlsl_handle, slave, pdata,
- offset_x, offset_y1, offset_y2);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- offset[0] = offset_x;
- offset[1] = offset_y1;
- offset[2] = offset_y2;
-
- return result;
-}
-
-static void coordinate_conversion(short x, short y1, short y2, short t,
- int32_t *xo, int32_t *yo, int32_t *zo)
-{
- int32_t sx, sy1, sy2, sy, sz;
- int32_t hx, hy, hz;
-
- sx = x - (Cx * t) / 100;
- sy1 = y1 - (Cy1 * t) / 100;
- sy2 = y2 - (Cy2 * t) / 100;
-
- sy = sy1 - sy2;
- sz = -sy1 - sy2;
-
- hx = k * ((100 * sx + a2 * sy + a3 * sz) / 10);
- hy = k * ((a4 * sx + a5 * sy + a6 * sz) / 10);
- hz = k * ((a7 * sx + a8 * sy + a9 * sz) / 10);
-
- *xo = hx;
- *yo = hy;
- *zo = hz;
-}
-
-static int yas530_suspend(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
-
- return result;
-}
-
-static int yas530_resume(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
-
- unsigned char dummyData = 0x00;
- char offset[3] = { 0, 0, 0 };
- unsigned char data[16];
- unsigned char read_reg[1];
-
- /* =============================================== */
-
- /* Step 1 - Test register initialization */
- dummyData = 0x00;
- result = inv_serial_single_write(mlsl_handle, pdata->address,
- YAS530_REGADDR_TEST1, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- result =
- inv_serial_single_write(mlsl_handle, pdata->address,
- YAS530_REGADDR_TEST2, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- /* Device ID read */
- result = inv_serial_read(mlsl_handle, pdata->address,
- YAS530_REGADDR_DEVICE_ID, 1, read_reg);
-
- /*Step 2 Read the CAL register */
- /* CAL data read */
- result = inv_serial_read(mlsl_handle, pdata->address,
- YAS530_REGADDR_CAL, 16, data);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
- /* CAL data Second Read */
- result = inv_serial_read(mlsl_handle, pdata->address,
- YAS530_REGADDR_CAL, 16, data);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- /*Cal data */
- dx = data[0];
- dy1 = data[1];
- dy2 = data[2];
- d2 = (data[3] >> 2) & 0x03f;
- d3 = ((data[3] << 2) & 0x0c) | ((data[4] >> 6) & 0x03);
- d4 = data[4] & 0x3f;
- d5 = (data[5] >> 2) & 0x3f;
- d6 = ((data[5] << 4) & 0x30) | ((data[6] >> 4) & 0x0f);
- d7 = ((data[6] << 3) & 0x78) | ((data[7] >> 5) & 0x07);
- d8 = ((data[7] << 1) & 0x3e) | ((data[8] >> 7) & 0x01);
- d9 = ((data[8] << 1) & 0xfe) | ((data[9] >> 7) & 0x01);
- d0 = (data[9] >> 2) & 0x1f;
- dck = ((data[9] << 1) & 0x06) | ((data[10] >> 7) & 0x01);
-
- /*Correction Data */
- Cx = (int)dx * 6 - 768;
- Cy1 = (int)dy1 * 6 - 768;
- Cy2 = (int)dy2 * 6 - 768;
- a2 = (int)d2 - 32;
- a3 = (int)d3 - 8;
- a4 = (int)d4 - 32;
- a5 = (int)d5 + 38;
- a6 = (int)d6 - 32;
- a7 = (int)d7 - 64;
- a8 = (int)d8 - 32;
- a9 = (int)d9;
- k = (int)d0 + 10;
-
- /*Obtain the [49:47] bits */
- dck &= 0x07;
-
- /*Step 3 : Storing the CONFIG with the CLK value */
- dummyData = 0x00 | (dck << 2);
- result = inv_serial_single_write(mlsl_handle, pdata->address,
- YAS530_REGADDR_CONFIG, dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- /*Step 4 : Set Acquisition Interval Register */
- dummyData = 0x00;
- result = inv_serial_single_write(mlsl_handle, pdata->address,
- YAS530_REGADDR_MEASURE_INTERVAL,
- dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- /*Step 5 : Reset Coil */
- dummyData = 0x00;
- result = inv_serial_single_write(mlsl_handle, pdata->address,
- YAS530_REGADDR_ACTUATE_INIT_COIL,
- dummyData);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- /* Offset Measurement and Set */
- result = measure_and_set_offset(mlsl_handle, slave, pdata, offset);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- return result;
-}
-
-static int yas530_read(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- unsigned char *data)
-{
- int result = INV_SUCCESS;
-
- int busy;
- short t, x, y1, y2;
- int32_t xyz[3];
- short rawfixed[3];
-
- result = measure_normal(mlsl_handle, slave, pdata,
- &busy, &t, &x, &y1, &y2);
- if (result) {
- LOG_RESULT_LOCATION(result);
- return result;
- }
-
- coordinate_conversion(x, y1, y2, t, &xyz[0], &xyz[1], &xyz[2]);
-
- rawfixed[0] = (short)(xyz[0] / 100);
- rawfixed[1] = (short)(xyz[1] / 100);
- rawfixed[2] = (short)(xyz[2] / 100);
-
- data[0] = rawfixed[0] >> 8;
- data[1] = rawfixed[0] & 0xFF;
- data[2] = rawfixed[1] >> 8;
- data[3] = rawfixed[1] & 0xFF;
- data[4] = rawfixed[2] >> 8;
- data[5] = rawfixed[2] & 0xFF;
-
- if (busy)
- return INV_ERROR_COMPASS_DATA_NOT_READY;
- return result;
-}
-
-static int yas530_get_config(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- struct ext_slave_config *data)
-{
- int result = INV_SUCCESS;
- //struct yas530_private_data *private_data = pdata->private_data;
-
- switch (data->key)
- {
- default:
- return INV_ERROR_FEATURE_NOT_IMPLEMENTED;
- }
- return result;
-}
-
-static struct ext_slave_descr yas530_descr = {
- .init = NULL,
- .exit = NULL,
- .suspend = yas530_suspend,
- .resume = yas530_resume,
- .read = yas530_read,
- .config = NULL,
- .get_config = yas530_get_config,
- .name = "yas530",
- .type = EXT_SLAVE_TYPE_COMPASS,
- .id = COMPASS_ID_YAS530,
- .read_reg = 0x06,
- .read_len = 6,
- .endian = EXT_SLAVE_BIG_ENDIAN,
- .range = {3276, 8001},
- .trigger = NULL,
-};
-
-static
-struct ext_slave_descr *yas530_get_slave_descr(void)
-{
- return &yas530_descr;
-}
-
-/* -------------------------------------------------------------------------- */
-struct yas530_mod_private_data {
- struct i2c_client *client;
- struct ext_slave_platform_data *pdata;
-};
-
-static unsigned short normal_i2c[] = { I2C_CLIENT_END };
-
-static int yas530_mod_probe(struct i2c_client *client,
- const struct i2c_device_id *devid)
-{
- struct ext_slave_platform_data *pdata;
- struct yas530_mod_private_data *private_data;
- int result = 0;
-
- dev_info(&client->adapter->dev, "%s: %s\n", __func__, devid->name);
-
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
- result = -ENODEV;
- goto out_no_free;
- }
-
- pdata = client->dev.platform_data;
- if (!pdata) {
- dev_err(&client->adapter->dev,
- "Missing platform data for slave %s\n", devid->name);
- result = -EFAULT;
- goto out_no_free;
- }
-
- private_data = kzalloc(sizeof(*private_data), GFP_KERNEL);
- if (!private_data) {
- result = -ENOMEM;
- goto out_no_free;
- }
-
- i2c_set_clientdata(client, private_data);
- private_data->client = client;
- private_data->pdata = pdata;
-
- result = inv_mpu_register_slave(THIS_MODULE, client, pdata,
- yas530_get_slave_descr);
- if (result) {
- dev_err(&client->adapter->dev,
- "Slave registration failed: %s, %d\n",
- devid->name, result);
- goto out_free_memory;
- }
-
- return result;
-
-out_free_memory:
- kfree(private_data);
-out_no_free:
- dev_err(&client->adapter->dev, "%s failed %d\n", __func__, result);
- return result;
-
-}
-
-static int yas530_mod_remove(struct i2c_client *client)
-{
- struct yas530_mod_private_data *private_data =
- i2c_get_clientdata(client);
-
- dev_dbg(&client->adapter->dev, "%s\n", __func__);
-
- inv_mpu_unregister_slave(client, private_data->pdata,
- yas530_get_slave_descr);
-
- kfree(private_data);
- return 0;
-}
-
-static const struct i2c_device_id yas530_mod_id[] = {
- { "yas530", COMPASS_ID_YAS530 },
- {}
-};
-
-MODULE_DEVICE_TABLE(i2c, yas530_mod_id);
-
-static struct i2c_driver yas530_mod_driver = {
- .class = I2C_CLASS_HWMON,
- .probe = yas530_mod_probe,
- .remove = yas530_mod_remove,
- .id_table = yas530_mod_id,
- .driver = {
- .owner = THIS_MODULE,
- .name = "yas530_mod",
- },
- .address_list = normal_i2c,
-};
-
-static int __init yas530_mod_init(void)
-{
- int res = i2c_add_driver(&yas530_mod_driver);
- pr_info("%s: Probe name %s\n", __func__, "yas530_mod");
- if (res)
- pr_err("%s failed\n", __func__);
- return res;
-}
-
-static void __exit yas530_mod_exit(void)
-{
- pr_info("%s\n", __func__);
- i2c_del_driver(&yas530_mod_driver);
-}
-
-module_init(yas530_mod_init);
-module_exit(yas530_mod_exit);
-
-MODULE_AUTHOR("Invensense Corporation");
-MODULE_DESCRIPTION("Driver to integrate YAS530 sensor with the MPU");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("yas530_mod");
-
-/**
- * @}
- */
diff --git a/drivers/misc/inv_mpu/compass/yas530_ext.c b/drivers/misc/inv_mpu/compass/yas530_ext.c
deleted file mode 100644
index 7a64258..0000000
--- a/drivers/misc/inv_mpu/compass/yas530_ext.c
+++ /dev/null
@@ -1,288 +0,0 @@
-#include <linux/i2c.h>
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/slab.h>
-
-#include <linux/module.h>
-#include <linux/delay.h>
-#include "mpu-dev.h"
-
-#include "log.h"
-#include <linux/mpu.h>
-#include "mlsl.h"
-#include "mldl_cfg.h"
-#undef MPL_LOG_TAG
-#define MPL_LOG_TAG "MPL-compass"
-
-struct yas530_ext_private_data {
- int flags;
- char offsets[3];
- const int *correction_matrix;
-};
-
-
-extern int geomagnetic_api_read(int *xyz, int *raw, int *xy1y2, int *accuracy);
-extern int geomagnetic_api_resume(void);
-extern int geomagnetic_api_suspend(void);
-
-
-static int yas530_ext_suspend(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
-
- geomagnetic_api_suspend();
-
- return result;
-}
-
-
-static int yas530_ext_resume(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- int result = INV_SUCCESS;
-
- struct yas530_ext_private_data *private_data = pdata->private_data;
-
- geomagnetic_api_resume();
-
- return result;
-}
-
-static int yas530_ext_read(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- unsigned char *data)
-{
- int result = INV_SUCCESS;
- int raw[3] = {0,};
- int xyz[3] = {0,};
- int accuracy = 0;
- int i = 0;
- short xyz_scaled[3] = {0,};
-
- geomagnetic_api_read(xyz, raw, NULL, &accuracy);
-
- xyz_scaled[0] = (short)(xyz[0]/100);
- xyz_scaled[1] = (short)(xyz[1]/100);
- xyz_scaled[2] = (short)(xyz[2]/100);
-
- data[0] = xyz_scaled[0] >> 8;
- data[1] = xyz_scaled[0] & 0xFF;
- data[2] = xyz_scaled[1] >> 8;
- data[3] = xyz_scaled[1] & 0xFF;
- data[4] = xyz_scaled[2] >> 8;
- data[5] = xyz_scaled[2] & 0xFF;
- data[6] = (unsigned char)accuracy;
-
-
- return result;
-
-}
-
-static int yas530_ext_config(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- struct ext_slave_config *data)
-{
- int result = INV_SUCCESS;
- struct yas530_private_data *private_data = pdata->private_data;
-
-
- return result;
-
-}
-
-
-static int yas530_ext_get_config(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata,
- struct ext_slave_config *data)
-{
- int result = INV_SUCCESS;
- struct yas530_ext_private_data *private_data = pdata->private_data;
-
- switch (data->key)
- {
- default:
- return INV_ERROR_FEATURE_NOT_IMPLEMENTED;
- }
- return result;
-}
-
-static int yas530_ext_init(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
-
- struct yas530_ext_private_data *private_data;
- int result = INV_SUCCESS;
- char offset[3] = {0, 0, 0};
-
- private_data = (struct yas530_ext_private_data *)
- kzalloc(sizeof(struct yas530_ext_private_data), GFP_KERNEL);
-
- if (!private_data)
- return INV_ERROR_MEMORY_EXAUSTED;
-
- private_data->correction_matrix = pdata->private_data;
-
- pdata->private_data = private_data;
-
- return result;
-}
-
-static int yas530_ext_exit(void *mlsl_handle,
- struct ext_slave_descr *slave,
- struct ext_slave_platform_data *pdata)
-{
- kfree(pdata->private_data);
- return INV_SUCCESS;
-}
-
-static struct ext_slave_descr yas530_ext_descr = {
- .init = yas530_ext_init,
- .exit = yas530_ext_exit,
- .suspend = yas530_ext_suspend,
- .resume = yas530_ext_resume,
- .read = yas530_ext_read,
- .config = yas530_ext_config,
- .get_config = yas530_ext_get_config,
- .name = "yas530ext",
- .type = EXT_SLAVE_TYPE_COMPASS,
- .id = COMPASS_ID_YAS530_EXT,
- .read_reg = 0x06,
- .read_len = 7,
- .endian = EXT_SLAVE_BIG_ENDIAN,
- .range = {3276, 8001},
- .trigger = NULL,
-};
-
-
-struct ext_slave_descr *yas530_ext_get_slave_descr(void)
-{
- return &yas530_ext_descr;
-}
-
-/* -------------------------------------------------------------------------- */
-struct yas530_ext_mod_private_data {
- struct i2c_client *client;
- struct ext_slave_platform_data *pdata;
-};
-
-static unsigned short normal_i2c[] = { I2C_CLIENT_END };
-
-static int yas530_ext_mod_probe(struct i2c_client *client,
- const struct i2c_device_id *devid)
-{
- struct ext_slave_platform_data *pdata;
- struct yas530_ext_mod_private_data *private_data;
- int result = 0;
-
- dev_info(&client->adapter->dev, "%s: %s\n", __func__, devid->name);
-
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
- result = -ENODEV;
- goto out_no_free;
- }
-
- pdata = client->dev.platform_data;
- if (!pdata) {
- dev_err(&client->adapter->dev,
- "Missing platform data for slave %s\n", devid->name);
- result = -EFAULT;
- goto out_no_free;
- }
-
- private_data = kzalloc(sizeof(*private_data), GFP_KERNEL);
- if (!private_data) {
- result = -ENOMEM;
- goto out_no_free;
- }
-
- i2c_set_clientdata(client, private_data);
- private_data->client = client;
- private_data->pdata = pdata;
-
- result = inv_mpu_register_slave(THIS_MODULE, client, pdata,
- yas530_ext_get_slave_descr);
- if (result) {
- dev_err(&client->adapter->dev,
- "Slave registration failed: %s, %d\n",
- devid->name, result);
- goto out_free_memory;
- }
-
- return result;
-
-out_free_memory:
- kfree(private_data);
-out_no_free:
- dev_err(&client->adapter->dev, "%s failed %d\n", __func__, result);
- return result;
-
-}
-
-static int yas530_ext_mod_remove(struct i2c_client *client)
-{
- struct yas530_ext_mod_private_data *private_data =
- i2c_get_clientdata(client);
-
- dev_dbg(&client->adapter->dev, "%s\n", __func__);
-
- inv_mpu_unregister_slave(client, private_data->pdata,
- yas530_ext_get_slave_descr);
-
- kfree(private_data);
- return 0;
-}
-
-static const struct i2c_device_id yas530_ext_mod_id[] = {
- { "yas530ext", COMPASS_ID_YAS530_EXT},
- {}
-};
-
-MODULE_DEVICE_TABLE(i2c, yas530_ext_mod_id);
-
-static struct i2c_driver yas530_ext_mod_driver = {
- .class = I2C_CLASS_HWMON,
- .probe = yas530_ext_mod_probe,
- .remove = yas530_ext_mod_remove,
- .id_table = yas530_ext_mod_id,
- .driver = {
- .owner = THIS_MODULE,
- .name = "yas530_ext_mod",
- },
- .address_list = normal_i2c,
-};
-
-static int __init yas530_ext_mod_init(void)
-{
- int res = i2c_add_driver(&yas530_ext_mod_driver);
- pr_info("%s: Probe name %s\n", __func__, "yas530_ext_mod");
- if (res)
- pr_err("%s failed\n", __func__);
- return res;
-}
-
-static void __exit yas530_ext_mod_exit(void)
-{
- pr_info("%s\n", __func__);
- i2c_del_driver(&yas530_ext_mod_driver);
-}
-
-module_init(yas530_ext_mod_init);
-module_exit(yas530_ext_mod_exit);
-
-MODULE_AUTHOR("Invensense Corporation");
-MODULE_DESCRIPTION("Driver to integrate YAS530 sensor with the MPU");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("yas530_ext_mod");
-
-/**
- * @}
- */
diff --git a/drivers/misc/inv_mpu/compass/yas530_ext.h b/drivers/misc/inv_mpu/compass/yas530_ext.h
deleted file mode 100644
index 0c343ec..0000000
--- a/drivers/misc/inv_mpu/compass/yas530_ext.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- $License:
- Copyright (C) 2011 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/>.
- $
- */
-
-
-#ifndef __YAS530_EXT_H__
-#define __YAS530_EXT_H__
-
-#include <linux/mpu.h>
-
-struct ext_slave_descr *yas530_ext_get_slave_descr(void);
-
-#endif