summaryrefslogtreecommitdiff
path: root/driver/mag_bmm150.c
diff options
context:
space:
mode:
Diffstat (limited to 'driver/mag_bmm150.c')
-rw-r--r--driver/mag_bmm150.c170
1 files changed, 77 insertions, 93 deletions
diff --git a/driver/mag_bmm150.c b/driver/mag_bmm150.c
index ad1eba7ad0..5088e51c14 100644
--- a/driver/mag_bmm150.c
+++ b/driver/mag_bmm150.c
@@ -1,4 +1,4 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+/* Copyright 2015 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -25,75 +25,74 @@
#error "Not implemented"
#endif
-
#define CPUTS(outstr) cputs(CC_ACCEL, outstr)
-#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_ACCEL, format, ## args)
-
+#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_ACCEL, format, ##args)
/****************************************************************************
-* Copyright (C) 2011 - 2014 Bosch Sensortec GmbH
-*
-****************************************************************************/
+ * Copyright (C) 2011 - 2014 Bosch Sensortec GmbH
+ *
+ ****************************************************************************/
/***************************************************************************
-* License:
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*
-* Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-*
-* Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-*
-* Neither the name of the copyright holder nor the names of the
-* contributors may be used to endorse or promote products derived from
-* this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
-* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
-*
-* The information provided is believed to be accurate and reliable.
-* The copyright holder assumes no responsibility for the consequences of use
-* of such information nor for any infringement of patents or
-* other rights of third parties which may result from its use.
-* No license is granted by implication or otherwise under any patent or
-* patent rights of the copyright holder.
-*/
-
-#define BMI150_READ_16BIT_COM_REG(store_, addr_) do { \
- int val; \
- raw_mag_read8(s->port, s->i2c_spi_addr_flags, (addr_), &val); \
- store_ = val; \
- raw_mag_read8(s->port, s->i2c_spi_addr_flags, (addr_) + 1, &val); \
- store_ |= (val << 8); \
-} while (0)
+ * License:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of the copyright holder nor the names of the
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
+ *
+ * The information provided is believed to be accurate and reliable.
+ * The copyright holder assumes no responsibility for the consequences of use
+ * of such information nor for any infringement of patents or
+ * other rights of third parties which may result from its use.
+ * No license is granted by implication or otherwise under any patent or
+ * patent rights of the copyright holder.
+ */
+#define BMI150_READ_16BIT_COM_REG(store_, addr_) \
+ do { \
+ int val; \
+ raw_mag_read8(s->port, s->i2c_spi_addr_flags, (addr_), &val); \
+ store_ = val; \
+ raw_mag_read8(s->port, s->i2c_spi_addr_flags, (addr_) + 1, \
+ &val); \
+ store_ |= (val << 8); \
+ } while (0)
int bmm150_init(struct motion_sensor_t *s)
{
int ret;
int val;
struct bmm150_comp_registers *regs = BMM150_COMP_REG(s);
- struct mag_cal_t *moc = BMM150_CAL(s);
+ struct mag_cal_t *moc = BMM150_CAL(s);
/* Set the compass from Suspend to Sleep */
- ret = raw_mag_write8(s->port, s->i2c_spi_addr_flags,
- BMM150_PWR_CTRL, BMM150_PWR_ON);
+ ret = raw_mag_write8(s->port, s->i2c_spi_addr_flags, BMM150_PWR_CTRL,
+ BMM150_PWR_ON);
msleep(4);
/* Now we can read the device id */
- ret = raw_mag_read8(s->port, s->i2c_spi_addr_flags,
- BMM150_CHIP_ID, &val);
+ ret = raw_mag_read8(s->port, s->i2c_spi_addr_flags, BMM150_CHIP_ID,
+ &val);
if (ret)
return EC_ERROR_UNKNOWN;
@@ -101,27 +100,24 @@ int bmm150_init(struct motion_sensor_t *s)
return EC_ERROR_ACCESS_DENIED;
/* Read the private registers for compensation */
- ret = raw_mag_read8(s->port, s->i2c_spi_addr_flags,
- BMM150_REGA_DIG_X1, &val);
+ ret = raw_mag_read8(s->port, s->i2c_spi_addr_flags, BMM150_REGA_DIG_X1,
+ &val);
if (ret)
return EC_ERROR_UNKNOWN;
regs->dig1[X] = val;
- raw_mag_read8(s->port, s->i2c_spi_addr_flags,
- BMM150_REGA_DIG_Y1, &val);
+ raw_mag_read8(s->port, s->i2c_spi_addr_flags, BMM150_REGA_DIG_Y1, &val);
regs->dig1[Y] = val;
- raw_mag_read8(s->port, s->i2c_spi_addr_flags,
- BMM150_REGA_DIG_X2, &val);
+ raw_mag_read8(s->port, s->i2c_spi_addr_flags, BMM150_REGA_DIG_X2, &val);
regs->dig2[X] = val;
- raw_mag_read8(s->port, s->i2c_spi_addr_flags,
- BMM150_REGA_DIG_Y2, &val);
+ raw_mag_read8(s->port, s->i2c_spi_addr_flags, BMM150_REGA_DIG_Y2, &val);
regs->dig2[Y] = val;
- raw_mag_read8(s->port, s->i2c_spi_addr_flags,
- BMM150_REGA_DIG_XY1, &val);
+ raw_mag_read8(s->port, s->i2c_spi_addr_flags, BMM150_REGA_DIG_XY1,
+ &val);
regs->dig_xy1 = val;
- raw_mag_read8(s->port, s->i2c_spi_addr_flags,
- BMM150_REGA_DIG_XY2, &val);
+ raw_mag_read8(s->port, s->i2c_spi_addr_flags, BMM150_REGA_DIG_XY2,
+ &val);
regs->dig_xy2 = val;
BMI150_READ_16BIT_COM_REG(regs->dig_z1, BMM150_REGA_DIG_Z1_LSB);
@@ -130,21 +126,17 @@ int bmm150_init(struct motion_sensor_t *s)
BMI150_READ_16BIT_COM_REG(regs->dig_z4, BMM150_REGA_DIG_Z4_LSB);
BMI150_READ_16BIT_COM_REG(regs->dig_xyz1, BMM150_REGA_DIG_XYZ1_LSB);
-
/* Set the repetition in "Regular Preset" */
- raw_mag_write8(s->port, s->i2c_spi_addr_flags,
- BMM150_REPXY, BMM150_REP(SPECIAL, XY));
- raw_mag_write8(s->port, s->i2c_spi_addr_flags,
- BMM150_REPZ, BMM150_REP(SPECIAL, Z));
- ret = raw_mag_read8(s->port, s->i2c_spi_addr_flags,
- BMM150_REPXY, &val);
- ret = raw_mag_read8(s->port, s->i2c_spi_addr_flags,
- BMM150_REPZ, &val);
+ raw_mag_write8(s->port, s->i2c_spi_addr_flags, BMM150_REPXY,
+ BMM150_REP(SPECIAL, XY));
+ raw_mag_write8(s->port, s->i2c_spi_addr_flags, BMM150_REPZ,
+ BMM150_REP(SPECIAL, Z));
+ ret = raw_mag_read8(s->port, s->i2c_spi_addr_flags, BMM150_REPXY, &val);
+ ret = raw_mag_read8(s->port, s->i2c_spi_addr_flags, BMM150_REPZ, &val);
/*
* Set the compass forced mode, to sleep after each measure.
*/
- ret = raw_mag_write8(s->port, s->i2c_spi_addr_flags,
- BMM150_OP_CTRL,
+ ret = raw_mag_write8(s->port, s->i2c_spi_addr_flags, BMM150_OP_CTRL,
BMM150_OP_MODE_FORCED << BMM150_OP_MODE_OFFSET);
init_mag_cal(moc);
@@ -152,10 +144,8 @@ int bmm150_init(struct motion_sensor_t *s)
return ret;
}
-void bmm150_temp_compensate_xy(const struct motion_sensor_t *s,
- intv3_t raw,
- intv3_t comp,
- int r)
+void bmm150_temp_compensate_xy(const struct motion_sensor_t *s, intv3_t raw,
+ intv3_t comp, int r)
{
int inter, axis;
struct bmm150_comp_registers *regs = BMM150_COMP_REG(s);
@@ -191,10 +181,8 @@ void bmm150_temp_compensate_xy(const struct motion_sensor_t *s,
}
}
-void bmm150_temp_compensate_z(const struct motion_sensor_t *s,
- intv3_t raw,
- intv3_t comp,
- int r)
+void bmm150_temp_compensate_z(const struct motion_sensor_t *s, intv3_t raw,
+ intv3_t comp, int r)
{
int dividend, divisor;
struct bmm150_comp_registers *regs = BMM150_COMP_REG(s);
@@ -221,9 +209,7 @@ void bmm150_temp_compensate_z(const struct motion_sensor_t *s,
comp[Z] = BMM150_OVERFLOW_OUTPUT;
}
-void bmm150_normalize(const struct motion_sensor_t *s,
- intv3_t v,
- uint8_t *data)
+void bmm150_normalize(const struct motion_sensor_t *s, intv3_t v, uint8_t *data)
{
uint16_t r;
intv3_t raw;
@@ -247,8 +233,7 @@ void bmm150_normalize(const struct motion_sensor_t *s,
v[Z] += cal->bias[Z];
}
-int bmm150_set_offset(const struct motion_sensor_t *s,
- const intv3_t offset)
+int bmm150_set_offset(const struct motion_sensor_t *s, const intv3_t offset)
{
struct mag_cal_t *cal = BMM150_CAL(s);
cal->bias[X] = offset[X];
@@ -257,8 +242,7 @@ int bmm150_set_offset(const struct motion_sensor_t *s,
return EC_SUCCESS;
}
-int bmm150_get_offset(const struct motion_sensor_t *s,
- intv3_t offset)
+int bmm150_get_offset(const struct motion_sensor_t *s, intv3_t offset)
{
struct mag_cal_t *cal = BMM150_CAL(s);
offset[X] = cal->bias[X];