BigW Consortium Gitlab

Commit a3080083 by David Clark

Added BMI088 Gyro/Accel sensor and Yellow driver

parent f1831b55
......@@ -47,3 +47,6 @@
[submodule "linux_kernel_modules/bme680/BME680_driver"]
path = linux_kernel_modules/bme680/BME680_driver
url = https://github.com/BoschSensortec/BME680_driver.git
[submodule "linux_kernel_modules/bmi088/BMI08x-Sensor-API"]
path = linux_kernel_modules/bmi088/BMI08x-Sensor-API
url = https://github.com/BoschSensortec/BMI08x-Sensor-API.git
cflags:
{
-DBMI08X_ENABLE_BMI088=1
-DBMI08X_ENABLE_BMI085=0
-DCONFIG_IIO
-DDEBUG
-DSIERRA
-I$MANGOH_ROOT/linux_kernel_modules/bmi088/BMI08x-Sensor-API
}
sources:
{
./BMI08x-Sensor-API/bmi085.c
./BMI08x-Sensor-API/bmi088.c
./BMI08x-Sensor-API/bmi08a.c
./BMI08x-Sensor-API/bmi08g.c
bmi088-regmap.c
bmi088-i2c.c
}
#include <linux/device.h>
#include <linux/module.h>
#include <linux/regmap.h>
#include "bmi08x_defs.h"
static bool bmi088a_is_writeable_reg(struct device *dev, unsigned int reg)
{
if ((reg >= BMI08X_ACCEL_FEATURE_CFG_REG) &&
(reg <= BMI08X_ACCEL_FEATURE_CFG_REG + BMI08X_ACCEL_ANYMOTION_LEN * 2))
return true;
switch (reg) {
case BMI08X_ACCEL_SOFTRESET_REG:
case BMI08X_ACCEL_PWR_CTRL_REG:
case BMI08X_ACCEL_PWR_CONF_REG:
case BMI08X_ACCEL_SELF_TEST_REG:
case BMI08X_ACCEL_INT1_INT2_MAP_DATA_REG:
case BMI08X_ACCEL_INT1_IO_CONF_REG:
case BMI08X_ACCEL_INT2_IO_CONF_REG:
case BMI08X_ACCEL_RANGE_REG:
case BMI08X_ACCEL_CONF_REG:
return true;
default:
dev_err(dev, "%s(): Error register(0x%04x) not writable\n", __func__, reg);
return false;
};
}
static bool bmi088a_is_volatile_reg(struct device *dev, unsigned int reg)
{
switch (reg) {
case BMI08X_ACCEL_PWR_CTRL_REG:
case BMI08X_ACCEL_PWR_CONF_REG:
case BMI08X_ACCEL_SELF_TEST_REG:
case BMI08X_ACCEL_INT1_INT2_MAP_DATA_REG:
case BMI08X_ACCEL_INT1_IO_CONF_REG:
case BMI08X_ACCEL_INT2_IO_CONF_REG:
case BMI08X_ACCEL_RANGE_REG:
case BMI08X_ACCEL_CONF_REG:
case BMI08X_TEMP_MSB_REG:
case BMI08X_TEMP_LSB_REG:
case BMI08X_ACCEL_SENSORTIME_2_REG:
case BMI08X_ACCEL_SENSORTIME_1_REG:
case BMI08X_ACCEL_SENSORTIME_0_REG:
case BMI08X_ACCEL_Z_MSB_REG:
case BMI08X_ACCEL_Z_LSB_REG:
case BMI08X_ACCEL_Y_MSB_REG:
case BMI08X_ACCEL_Y_LSB_REG:
case BMI08X_ACCEL_X_MSB_REG:
case BMI08X_ACCEL_X_LSB_REG:
case BMI08X_ACCEL_STATUS_REG:
case BMI08X_ACCEL_ERR_REG:
case BMI08X_ACCEL_CHIP_ID_REG:
return true;
default:
break;
}
return false;
}
const struct regmap_config bmi088a_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = BMI08X_ACCEL_SOFTRESET_REG,
.cache_type = REGCACHE_NONE,
.writeable_reg = bmi088a_is_writeable_reg,
.volatile_reg = bmi088a_is_volatile_reg,
};
EXPORT_SYMBOL(bmi088a_regmap_config);
static bool bmi088g_is_writeable_reg(struct device *dev, unsigned int reg)
{
switch (reg) {
case BMI08X_GYRO_SOFTRESET_REG:
case BMI08X_GYRO_SELF_TEST_REG:
case BMI08X_GYRO_INT3_INT4_IO_MAP_REG:
case BMI08X_GYRO_INT3_INT4_IO_CONF_REG:
case BMI08X_GYRO_INT_CTRL_REG:
case BMI08X_GYRO_LPM1_REG:
case BMI08X_GYRO_BANDWIDTH_REG:
case BMI08X_GYRO_RANGE_REG:
return true;
default:
dev_err(dev, "%s(): Error register(0x%04x) not writable\n", __func__, reg);
return false;
};
}
static bool bmi088g_is_volatile_reg(struct device *dev, unsigned int reg)
{
switch (reg) {
case BMI08X_GYRO_SELF_TEST_REG:
case BMI08X_GYRO_INT3_INT4_IO_MAP_REG:
case BMI08X_GYRO_INT3_INT4_IO_CONF_REG:
case BMI08X_GYRO_INT_CTRL_REG:
case BMI08X_GYRO_LPM1_REG:
case BMI08X_GYRO_BANDWIDTH_REG:
case BMI08X_GYRO_RANGE_REG:
case BMI08X_GYRO_INT_STAT_1_REG:
case BMI08X_GYRO_Z_MSB_REG:
case BMI08X_GYRO_Z_LSB_REG:
case BMI08X_GYRO_Y_MSB_REG:
case BMI08X_GYRO_Y_LSB_REG:
case BMI08X_GYRO_X_MSB_REG:
case BMI08X_GYRO_X_LSB_REG:
case BMI08X_GYRO_CHIP_ID_REG:
return true;
default:
break;
}
return false;
}
const struct regmap_config bmi088g_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = BMI08X_GYRO_SELF_TEST_REG,
.cache_type = REGCACHE_NONE,
.writeable_reg = bmi088g_is_writeable_reg,
.volatile_reg = bmi088g_is_volatile_reg,
};
EXPORT_SYMBOL(bmi088g_regmap_config);
#!/bin/sh
# Copyright (C) Sierra Wireless Inc. Use of this work is subject to license.
#
cd /etc/bme680/
insmod 3-bme680-i2c.ko
insmod 4-bmi088-i2c.ko
insmod 9-mangoh_yellow_dv1.ko
echo 1 > /sys/devices/78b8000.i2c/i2c-4/4-0018/iio:device1/in_accel_x_en
echo "ACCEL-X enable"
cat /sys/devices/78b8000.i2c/i2c-4/4-0018/iio:device1/in_accel_x_en
echo 1 > /sys/devices/78b8000.i2c/i2c-4/4-0018/iio:device1/in_accel_y_en
echo "ACCEL-Y enable"
cat /sys/devices/78b8000.i2c/i2c-4/4-0018/iio:device1/in_accel_y_en
echo 1 > /sys/devices/78b8000.i2c/i2c-4/4-0018/iio:device1/in_accel_z_en
echo "ACCEL-Z enable"
cat /sys/devices/78b8000.i2c/i2c-4/4-0018/iio:device1/in_accel_z_en
echo 0 > /sys/devices/78b8000.i2c/i2c-4/4-0018/iio:device1/in_accel_nomotion_sel
echo "ACCEL no motion selected"
cat /sys/devices/78b8000.i2c/i2c-4/4-0018/iio:device1/in_accel_nomotion_sel
echo 100 > /sys/devices/78b8000.i2c/i2c-4/4-0018/iio:device1/in_accel_duration
echo "ACCEL duration"
cat /sys/devices/78b8000.i2c/i2c-4/4-0018/iio:device1/in_accel_duration
echo 100 > /sys/devices/78b8000.i2c/i2c-4/4-0018/iio:device1/in_accel_threshold
echo "ACCEL threshold"
cat /sys/devices/78b8000.i2c/i2c-4/4-0018/iio:device1/in_accel_threshold
echo 1 > /sys/devices/78b8000.i2c/i2c-4/4-0068/iio\:device2/scan_elements/in_anglvel_x_en
echo 1 > /sys/devices/78b8000.i2c/i2c-4/4-0068/iio\:device2/scan_elements/in_anglvel_y_en
echo 1 > /sys/devices/78b8000.i2c/i2c-4/4-0068/iio\:device2/scan_elements/in_anglvel_z_en
echo 1 > /sys/devices/78b8000.i2c/i2c-4/4-0068/iio\:device2/scan_elements/in_timestamp_en
echo 5 > /sys/devices/78b8000.i2c/i2c-4/4-0068/iio\:device2/buffer/length
echo 1 > /sys/devices/78b8000.i2c/i2c-4/4-0068/iio\:device2/buffer/enable
echo 1 > /sys/devices/78b8000.i2c/i2c-4/4-0018/iio\:device1/scan_elements/in_accel_x_en
echo 1 > /sys/devices/78b8000.i2c/i2c-4/4-0018/iio\:device1/scan_elements/in_accel_y_en
echo 1 > /sys/devices/78b8000.i2c/i2c-4/4-0018/iio\:device1/scan_elements/in_accel_z_en
echo 1 > /sys/devices/78b8000.i2c/i2c-4/4-0018/iio\:device1/scan_elements/in_timestamp_en
echo 5 > /sys/devices/78b8000.i2c/i2c-4/4-0018/iio\:device1/buffer/length
echo 1 > /sys/devices/78b8000.i2c/i2c-4/4-0018/iio\:device1/buffer/enable
echo "TEMP"
cat /sys/devices/78b8000.i2c/i2c-4/4-0018/iio:device1/in_temp_input
echo "ACCEL-X"
cat /sys/devices/78b8000.i2c/i2c-4/4-0018/iio:device1/in_accel_x_input
echo "ACCEL-Y"
cat /sys/devices/78b8000.i2c/i2c-4/4-0018/iio:device1/in_accel_y_input
echo "ACCEL-Z"
cat /sys/devices/78b8000.i2c/i2c-4/4-0018/iio:device1/in_accel_z_input
echo "ANG VELOCITY-X"
cat /sys/devices/78b8000.i2c/i2c-4/4-0068/iio\:device2/in_anglvel_x_input
echo "ANG VELOCITY-Y"
cat /sys/devices/78b8000.i2c/i2c-4/4-0068/iio\:device2/in_anglvel_y_input
echo "ANG VELOCITY-Z"
cat /sys/devices/78b8000.i2c/i2c-4/4-0068/iio\:device2/in_anglvel_z_input
cat /dev/iio\:device1
cflags:
{
}
sources:
{
mangoh_yellow.c
}
params:
{
revision = "dv1"
}
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/i2c.h>
#include <linux/delay.h>
#include <linux/gpio/driver.h>
#include "mangoh_common.h"
/*
*-----------------------------------------------------------------------------
* Constants
*-----------------------------------------------------------------------------
*/
#define MANGOH_YELLOW_I2C_SW_BUS_BASE (PRIMARY_I2C_BUS + 1)
#define MANGOH_YELLOW_I2C_BUS_IOT0 (MANGOH_YELLOW_I2C_SW_BUS_BASE + 0)
#define MANGOH_YELLOW_I2C_BUS_BATTERY_CHARGER (MANGOH_YELLOW_I2C_SW_BUS_BASE + 1)
#define MANGOH_YELLOW_I2C_BUS_USB_HUB (MANGOH_YELLOW_I2C_SW_BUS_BASE + 1)
#define MANGOH_YELLOW_I2C_BUS_GPIO_EXPANDER (MANGOH_YELLOW_I2C_SW_BUS_BASE + 2)
#define MANGOH_YELLOW_I2C_BUS_EXP (MANGOH_YELLOW_I2C_SW_BUS_BASE + 3)
/*
*-----------------------------------------------------------------------------
* Types
*-----------------------------------------------------------------------------
*/
enum mangoh_yellow_board_rev {
MANGOH_YELLOW_BOARD_REV_DV1,
};
/*
*-----------------------------------------------------------------------------
* Static Function Declarations
*-----------------------------------------------------------------------------
*/
static void mangoh_yellow_release(struct device* dev);
static int mangoh_yellow_probe(struct platform_device* pdev);
static int mangoh_yellow_remove(struct platform_device* pdev);
/*
*-----------------------------------------------------------------------------
* Variables
*-----------------------------------------------------------------------------
*/
static char *revision = "dv1";
module_param(revision, charp, S_IRUGO);
MODULE_PARM_DESC(revision, "mangOH Yellow board revision");
static struct platform_driver mangoh_yellow_driver = {
.probe = mangoh_yellow_probe,
.remove = mangoh_yellow_remove,
.driver = {
.name = "mangoh yellow",
.owner = THIS_MODULE,
.bus = &platform_bus_type,
},
};
static struct mangoh_yellow_platform_data {
enum mangoh_yellow_board_rev board_rev;
} mangoh_yellow_pdata;
static struct mangoh_yellow_driver_data {
struct i2c_client* bme680;
struct i2c_client* bmi088a;
struct i2c_client* bmi088g;
} mangoh_yellow_driver_data = {
};
static struct platform_device mangoh_yellow_device = {
.name = "mangoh yellow",
.id = -1,
.dev = {
.release = mangoh_yellow_release,
.platform_data = &mangoh_yellow_pdata,
},
};
static struct i2c_board_info mangoh_yellow_bme680_devinfo = {
I2C_BOARD_INFO("bme680", 0x76),
};
static struct i2c_board_info mangoh_yellow_bmi088a_devinfo = {
I2C_BOARD_INFO("bmi088a", 0x18),
};
static struct i2c_board_info mangoh_yellow_bmi088g_devinfo = {
I2C_BOARD_INFO("bmi088g", 0x68),
};
static void mangoh_yellow_release(struct device* dev)
{
/* Nothing alloc'd, so nothign to free */
}
static int mangoh_yellow_probe(struct platform_device* pdev)
{
int ret = 0;
struct i2c_adapter *main_adapter;
dev_info(&pdev->dev, "%s(): probe\n", __func__);
main_adapter = i2c_get_adapter(PRIMARY_I2C_BUS);
if (!main_adapter) {
dev_err(&pdev->dev, "Failed to get primary I2C adapter (%d).\n",
PRIMARY_I2C_BUS);
ret = -ENODEV;
goto done;
}
/*
* This is a workaround of questionable validity for USB issues first
* seen on the mangOH Green.
*/
msleep(5000);
platform_set_drvdata(pdev, &mangoh_yellow_driver_data);
/* Map the I2C BME680 humidity/gas/temp/pressure sensor */
dev_dbg(&pdev->dev, "mapping bme680 gas/temperature/pressure sensor\n");
mangoh_yellow_driver_data.bme680 =
i2c_new_device(main_adapter, &mangoh_yellow_bme680_devinfo);
i2c_put_adapter(main_adapter);
if (!mangoh_yellow_driver_data.bme680) {
dev_err(&pdev->dev, "Gas/Humidity/Temp sensor is missing\n");
ret = -ENODEV;
goto cleanup;
}
/* Map the I2C BMI088 gyro/accel sensor */
dev_dbg(&pdev->dev, "mapping bmi088 gyro/accel sensor\n");
mangoh_yellow_driver_data.bmi088a =
i2c_new_device(main_adapter, &mangoh_yellow_bmi088a_devinfo);
i2c_put_adapter(main_adapter);
if (!mangoh_yellow_driver_data.bmi088a) {
dev_err(&pdev->dev, "bmi088 accel sensor is missing\n");
ret = -ENODEV;
goto cleanup;
}
mangoh_yellow_driver_data.bmi088g =
i2c_new_device(main_adapter, &mangoh_yellow_bmi088g_devinfo);
i2c_put_adapter(main_adapter);
if (!mangoh_yellow_driver_data.bmi088g) {
dev_err(&pdev->dev, "bmi088 gyro sensor is missing\n");
ret = -ENODEV;
goto cleanup;
}
cleanup:
i2c_put_adapter(main_adapter);
if (ret != 0)
mangoh_yellow_remove(pdev);
done:
return ret;
}
static void try_unregister_i2c_device(struct i2c_client *client)
{
if (client != NULL) {
i2c_unregister_device(client);
i2c_put_adapter(client->adapter);
}
}
static int mangoh_yellow_remove(struct platform_device* pdev)
{
struct mangoh_yellow_driver_data *dd = platform_get_drvdata(pdev);
dev_info(&pdev->dev, "Removing mangoh red platform device\n");
try_unregister_i2c_device(dd->bmi088a);
try_unregister_i2c_device(dd->bmi088g);
try_unregister_i2c_device(dd->bme680);
return 0;
}
static int __init mangoh_yellow_init(void)
{
platform_driver_register(&mangoh_yellow_driver);
printk(KERN_DEBUG "mangoh: registered platform driver\n");
mangoh_yellow_pdata.board_rev = MANGOH_YELLOW_BOARD_REV_DV1;
if (platform_device_register(&mangoh_yellow_device)) {
platform_driver_unregister(&mangoh_yellow_driver);
return -ENODEV;
}
return 0;
}
static void __exit mangoh_yellow_exit(void)
{
platform_device_unregister(&mangoh_yellow_device);
platform_driver_unregister(&mangoh_yellow_driver);
}
module_init(mangoh_yellow_init);
module_exit(mangoh_yellow_exit);
MODULE_ALIAS(PLATFORM_MODULE_PREFIX "mangoh yellow");
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Sierra Wireless");
MODULE_DESCRIPTION("Add devices on mangOH Yellow hardware board");
MODULE_VERSION("1.0");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment