staticint mpl3115_request(struct mpl3115_data *data)
{ int ret, tries = 15;
/* trigger measurement */
ret = i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1,
data->ctrl_reg1 | MPL3115_CTRL_OST); if (ret < 0) return ret;
while (tries-- > 0) {
ret = i2c_smbus_read_byte_data(data->client, MPL3115_CTRL_REG1); if (ret < 0) return ret; /* wait for data ready, i.e. OST cleared */ if (!(ret & MPL3115_CTRL_OST)) break;
msleep(20);
}
if (tries < 0) {
dev_err(&data->client->dev, "data not ready\n"); return -EIO;
}
return 0;
}
staticint mpl3115_read_info_raw(struct mpl3115_data *data, struct iio_chan_spec const *chan, int *val)
{ int ret;
switch (chan->type) { case IIO_PRESSURE: { /* in 0.25 pascal / LSB */
__be32 tmp = 0;
guard(mutex)(&data->lock);
ret = mpl3115_request(data); if (ret < 0) return ret;
ret = i2c_smbus_read_i2c_block_data(data->client,
MPL3115_OUT_PRESS,
3, (u8 *) &tmp); if (ret < 0) return ret;
*val = be32_to_cpu(tmp) >> chan->scan_type.shift; return IIO_VAL_INT;
} case IIO_TEMP: { /* in 0.0625 celsius / LSB */
__be16 tmp;
guard(mutex)(&data->lock);
ret = mpl3115_request(data); if (ret < 0) return ret;
ret = i2c_smbus_read_i2c_block_data(data->client,
MPL3115_OUT_TEMP,
2, (u8 *) &tmp); if (ret < 0) return ret;
static irqreturn_t mpl3115_trigger_handler(int irq, void *p)
{ struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; struct mpl3115_data *data = iio_priv(indio_dev); /* * 32-bit channel + 16-bit channel + padding + ts * Note that it is possible for only one of the first 2 * channels to be enabled. If that happens, the first element * of the buffer may be either 16 or 32-bits. As such we cannot * use a simple structure definition to express this data layout.
*/
u8 buffer[16] __aligned(8) = { }; int ret, pos = 0;
mutex_lock(&data->lock);
ret = mpl3115_request(data); if (ret < 0) {
mutex_unlock(&data->lock); goto done;
}
if (test_bit(0, indio_dev->active_scan_mask)) {
ret = i2c_smbus_read_i2c_block_data(data->client,
MPL3115_OUT_PRESS, 3, &buffer[pos]); if (ret < 0) {
mutex_unlock(&data->lock); goto done;
}
pos += 4;
}
if (test_bit(1, indio_dev->active_scan_mask)) {
ret = i2c_smbus_read_i2c_block_data(data->client,
MPL3115_OUT_TEMP, 2, &buffer[pos]); if (ret < 0) {
mutex_unlock(&data->lock); goto done;
}
}
mutex_unlock(&data->lock);
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.