static int ad7298_read_raw(struct iio_dev *dev_info, struct iio_chan_spec const *chan, int *val, int *val2, long m) { int ret; struct ad7298_state *st = iio_priv(dev_info); unsigned int scale_uv; switch (m) { case 0: mutex_lock(&dev_info->mlock); if (iio_ring_enabled(dev_info)) { if (chan->address == AD7298_CH_TEMP) ret = -ENODEV; else ret = ad7298_scan_from_ring(dev_info, chan->address); } else { if (chan->address == AD7298_CH_TEMP) ret = ad7298_scan_temp(st, val); else ret = ad7298_scan_direct(st, chan->address); } mutex_unlock(&dev_info->mlock); if (ret < 0) return ret; if (chan->address != AD7298_CH_TEMP) *val = ret & RES_MASK(AD7298_BITS); return IIO_VAL_INT; case (1 << IIO_CHAN_INFO_SCALE_SHARED): scale_uv = (st->int_vref_mv * 1000) >> AD7298_BITS; *val = scale_uv / 1000; *val2 = (scale_uv % 1000) * 1000; return IIO_VAL_INT_PLUS_MICRO; case (1 << IIO_CHAN_INFO_SCALE_SEPARATE): *val = 1; *val2 = 0; return IIO_VAL_INT_PLUS_MICRO; } return -EINVAL; }
static ssize_t ad7606_scan(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); struct ad7606_state *st = dev_info->dev_data; struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); int ret; mutex_lock(&dev_info->mlock); if (iio_ring_enabled(dev_info)) ret = ad7606_scan_from_ring(st, this_attr->address); else ret = ad7606_scan_direct(st, this_attr->address); mutex_unlock(&dev_info->mlock); if (ret < 0) return ret; return sprintf(buf, "%d\n", (short) ret); }
static ssize_t ad7887_scan(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_dev *dev_info = dev_get_drvdata(dev); struct ad7887_state *st = dev_info->dev_data; struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); int ret; mutex_lock(&dev_info->mlock); if (iio_ring_enabled(dev_info)) ret = ad7887_scan_from_ring(st, 1 << this_attr->address); else ret = ad7887_scan_direct(st, this_attr->address); mutex_unlock(&dev_info->mlock); if (ret < 0) return ret; return sprintf(buf, "%d\n", (ret >> st->chip_info->left_shift) & RES_MASK(st->chip_info->bits)); }
static int max1363_read_single_chan(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, long m) { int ret = 0; s32 data; char rxbuf[2]; long mask; struct max1363_state *st = iio_priv(indio_dev); struct i2c_client *client = st->client; mutex_lock(&indio_dev->mlock); /* * If monitor mode is enabled, the method for reading a single * channel will have to be rather different and has not yet * been implemented. */ if (st->monitor_on) { ret = -EBUSY; goto error_ret; } /* If ring buffer capture is occurring, query the buffer */ if (iio_ring_enabled(indio_dev)) { mask = max1363_mode_table[chan->address].modemask; data = max1363_single_channel_from_ring(mask, st); if (data < 0) { ret = data; goto error_ret; } } else { /* Check to see if current scan mode is correct */ if (st->current_mode != &max1363_mode_table[chan->address]) { /* Update scan mode if needed */ st->current_mode = &max1363_mode_table[chan->address]; ret = max1363_set_scan_mode(st); if (ret < 0) goto error_ret; } if (st->chip_info->bits != 8) { /* Get reading */ data = i2c_master_recv(client, rxbuf, 2); if (data < 0) { ret = data; goto error_ret; } data = (s32)(rxbuf[1]) | ((s32)(rxbuf[0] & 0x0F)) << 8; } else { /* Get reading */ data = i2c_master_recv(client, rxbuf, 1); if (data < 0) { ret = data; goto error_ret; } data = rxbuf[0]; } } *val = data; error_ret: mutex_unlock(&indio_dev->mlock); return ret; }