sensor: ak8975: add support for MPU9150

The AK8975 chip can be packaged together with a MPU6050 chip, resulting
in a MPU9150 chip. In this format, the MPU6050 part of the MPU9150 chip
needs to be turned on and pass-through mode enable in order to communicate
with the AK8975 chip.

Datasheet:
	http://43zrtwysvxb2gf29r5o0athu.wpengine.netdna-cdn.com/wp-content/uploads/2015/02/MPU-9150-Datasheet.pdf

Register Map:
	http://43zrtwysvxb2gf29r5o0athu.wpengine.netdna-cdn.com/wp-content/uploads/2015/02/MPU-9150-Register-Map.pdf

Change-Id: I120dff11c187689e2e6968c812aae2e3e3578bc6
Signed-off-by: Bogdan Davidoaia <bogdan.m.davidoaia@intel.com>
This commit is contained in:
Bogdan Davidoaia 2016-05-31 17:28:41 +03:00
parent c4c01a92f3
commit caa506102e
3 changed files with 59 additions and 0 deletions

View file

@ -66,6 +66,8 @@ config AK8975_I2C_ADDR
- 0x0D if CAD1 connected to GND nad CAD0 is connected to VDD
- 0x0E if CAD1 connected to VDD nad CAD0 is connected to GND
- 0x0F if CAD1 connected to VDD nad CAD0 is connected to VDD
If the AK8975 sensor is part of a MPU9159 chip, the I2C address
needs to be 0x0C.
config AK8975_I2C_MASTER_DEV_NAME
string
@ -75,3 +77,22 @@ config AK8975_I2C_MASTER_DEV_NAME
help
Specify the device name of the I2C master device to which the
AK8975 chip is connected.
config MPU9150
bool
prompt "Enable MPU9180 support"
depends on AK8975
default n
help
Enable this config option if the AK8975 sensor is part of a
MPU9150 chip.
config MPU9150_I2C_ADDR
hex
prompt "MPU9180 I2C address"
depends on AK8975 && MPU9150 && !MPU6050
range 0x68 0x69
default 0x68
help
I2C address of the MPU9150. If the driver for MPU6050 is enabled,
its address will be used and this option made unavailable.

View file

@ -128,6 +128,24 @@ int ak8975_init(struct device *dev)
return -EINVAL;
}
#ifdef CONFIG_MPU9150
/* wake up MPU9150 chip */
if (i2c_reg_update_byte(drv_data->i2c, MPU9150_I2C_ADDR,
MPU9150_REG_PWR_MGMT1, MPU9150_SLEEP_EN,
0) < 0) {
SYS_LOG_ERR("Failed to wake up MPU9150 chip.");
return -EIO;
}
/* enable MPU9150 pass-though to have access to AK8975 */
if (i2c_reg_update_byte(drv_data->i2c, MPU9150_I2C_ADDR,
MPU9150_REG_BYPASS_CFG, MPU9150_I2C_BYPASS_EN,
MPU9150_I2C_BYPASS_EN) < 0) {
SYS_LOG_ERR("Failed to enable pass-through mode for MPU9150.");
return -EIO;
}
#endif
/* check chip ID */
if (i2c_reg_read_byte(drv_data->i2c, CONFIG_AK8975_I2C_ADDR,
AK8975_REG_CHIP_ID, &id) < 0) {

View file

@ -37,6 +37,26 @@
#define AK8975_MEASURE_TIME_US 9000
#define AK8975_MICRO_GAUSS_PER_BIT 3000
#ifdef CONFIG_MPU9150
#if CONFIG_AK8975_I2C_ADDR != 0x0C
#error "I2C address must be 0x0C when AK8975 is part of a MPU9150 chip"
#endif
#ifdef CONFIG_MPU9150_I2C_ADDR
#define MPU9150_I2C_ADDR CONFIG_MPU9150_I2C_ADDR
#else
#define MPU9150_I2C_ADDR CONFIG_MPU6050_I2C_ADDR
#endif
#define MPU9150_REG_BYPASS_CFG 0x37
#define MPU9150_I2C_BYPASS_EN BIT(1)
#define MPU9150_REG_PWR_MGMT1 0x6B
#define MPU9150_SLEEP_EN BIT(6)
#endif /* CONFIG_MPU9150 */
struct ak8975_data {
struct device *i2c;