ret = i2c_smbus_read_byte_data(client, MMA7660_REG_MODE); if (ret < 0) {
dev_err(&client->dev, "failed to read sensor mode\n"); return ret;
}
if (mode == MMA7660_MODE_ACTIVE) {
ret &= ~MMA7660_REG_MODE_BIT_TON;
ret |= MMA7660_REG_MODE_BIT_MODE;
} else {
ret &= ~MMA7660_REG_MODE_BIT_TON;
ret &= ~MMA7660_REG_MODE_BIT_MODE;
}
ret = i2c_smbus_write_byte_data(client, MMA7660_REG_MODE, ret); if (ret < 0) {
dev_err(&client->dev, "failed to change sensor mode\n"); return ret;
}
/* * Read data. If the Alert bit is set, the register was read at * the same time as the device was attempting to update the content. * The solution is to read the register again. Do this only * MMA7660_I2C_READ_RETRIES times to avoid spending too much time * in the kernel.
*/ do {
ret = i2c_smbus_read_byte_data(client, address); if (ret < 0) {
dev_err(&client->dev, "register read failed\n"); return ret;
}
} while (retries-- > 0 && ret & MMA7660_REG_OUT_BIT_ALERT);
if (ret & MMA7660_REG_OUT_BIT_ALERT) {
dev_err(&client->dev, "all register read retries failed\n"); return -ETIMEDOUT;
}
return ret;
}
staticint mma7660_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask)
{ struct mma7660_data *data = iio_priv(indio_dev); int ret;
switch (mask) { case IIO_CHAN_INFO_RAW:
mutex_lock(&data->lock);
ret = mma7660_read_accel(data, chan->address);
mutex_unlock(&data->lock); if (ret < 0) return ret;
*val = sign_extend32(ret, 5); return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE:
*val = 0;
*val2 = mma7660_nscale; return IIO_VAL_INT_PLUS_NANO; default: return -EINVAL;
}
ret = mma7660_set_mode(iio_priv(indio_dev), MMA7660_MODE_STANDBY); if (ret)
dev_warn(&client->dev, "Failed to put device in stand-by mode (%pe), ignoring\n",
ERR_PTR(ret));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.