/** * max1363_ring_preenable() - setup the parameters of the ring before enabling * * The complex nature of the setting of the nuber of bytes per datum is due * to this driver currently ensuring that the timestamp is stored at an 8 * byte boundary. **/ static int max1363_ring_preenable(struct iio_dev *indio_dev) { struct max1363_state *st = indio_dev->dev_data; struct iio_ring_buffer *ring = indio_dev->ring; size_t d_size; unsigned long numvals; /* * Need to figure out the current mode based upon the requested * scan mask in iio_dev */ st->current_mode = max1363_match_mode(ring->scan_mask, st->chip_info); if (!st->current_mode) return -EINVAL; max1363_set_scan_mode(st); numvals = hweight_long(st->current_mode->modemask); if (ring->access.set_bytes_per_datum) { if (st->chip_info->bits != 8) d_size = numvals*2 + sizeof(s64); else d_size = numvals + sizeof(s64); if (d_size % 8) d_size += 8 - (d_size % 8); ring->access.set_bytes_per_datum(ring, d_size); } return 0; }
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; u8 rxbuf[2]; 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. * * Also, cannot read directly if buffered capture enabled. */ if (st->monitor_on || iio_buffer_enabled(indio_dev)) { ret = -EBUSY; goto error_ret; } /* 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 = st->recv(client, rxbuf, 2); if (data < 0) { ret = data; goto error_ret; } data = (rxbuf[1] | rxbuf[0] << 8) & ((1 << st->chip_info->bits) - 1); } else { /* Get reading */ data = st->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; }
int max1363_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *scan_mask) { struct max1363_state *st = iio_priv(indio_dev); /* * Need to figure out the current mode based upon the requested * scan mask in iio_dev */ st->current_mode = max1363_match_mode(scan_mask, st->chip_info); if (!st->current_mode) return -EINVAL; max1363_set_scan_mode(st); return 0; }
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; }