Exemplo n.º 1
0
static int ad7298_ring_preenable(struct iio_dev *indio_dev)
{
	struct ad7298_state *st = iio_priv(indio_dev);
	struct iio_buffer *ring = indio_dev->buffer;
	size_t d_size;
	int i, m;
	unsigned short command;
	int scan_count = bitmap_weight(indio_dev->active_scan_mask,
				       indio_dev->masklength);
	d_size = scan_count * (AD7298_STORAGE_BITS / 8);

	if (ring->scan_timestamp) {
		d_size += sizeof(s64);

		if (d_size % sizeof(s64))
			d_size += sizeof(s64) - (d_size % sizeof(s64));
	}

	if (ring->access->set_bytes_per_datum)
		ring->access->set_bytes_per_datum(ring, d_size);

	st->d_size = d_size;

	command = AD7298_WRITE | st->ext_ref;

	for (i = 0, m = AD7298_CH(0); i < AD7298_MAX_CHAN; i++, m >>= 1)
		if (test_bit(i, indio_dev->active_scan_mask))
			command |= m;

	st->tx_buf[0] = cpu_to_be16(command);

	/*                        */
	st->ring_xfer[0].tx_buf = &st->tx_buf[0];
	st->ring_xfer[0].len = 2;
	st->ring_xfer[0].cs_change = 1;
	st->ring_xfer[1].tx_buf = &st->tx_buf[1];
	st->ring_xfer[1].len = 2;
	st->ring_xfer[1].cs_change = 1;

	spi_message_init(&st->ring_msg);
	spi_message_add_tail(&st->ring_xfer[0], &st->ring_msg);
	spi_message_add_tail(&st->ring_xfer[1], &st->ring_msg);

	for (i = 0; i < scan_count; i++) {
		st->ring_xfer[i + 2].rx_buf = &st->rx_buf[i];
		st->ring_xfer[i + 2].len = 2;
		st->ring_xfer[i + 2].cs_change = 1;
		spi_message_add_tail(&st->ring_xfer[i + 2], &st->ring_msg);
	}
	/*                                              */
	st->ring_xfer[i + 1].cs_change = 0;

	return 0;
}
Exemplo n.º 2
0
/**
 * ad7298_ring_preenable() setup the parameters of the ring before enabling
 *
 * The complex nature of the setting of the number of bytes per datum is due
 * to this driver currently ensuring that the timestamp is stored at an 8
 * byte boundary.
 **/
static int ad7298_ring_preenable(struct iio_dev *indio_dev)
{
    struct ad7298_state *st = iio_priv(indio_dev);
    struct iio_ring_buffer *ring = indio_dev->ring;
    size_t d_size;
    int i, m;
    unsigned short command;

    d_size = ring->scan_count * (AD7298_STORAGE_BITS / 8);

    if (ring->scan_timestamp) {
        d_size += sizeof(s64);

        if (d_size % sizeof(s64))
            d_size += sizeof(s64) - (d_size % sizeof(s64));
    }

    if (ring->access->set_bytes_per_datum)
        ring->access->set_bytes_per_datum(ring, d_size);

    st->d_size = d_size;

    command = AD7298_WRITE | st->ext_ref;

    for (i = 0, m = AD7298_CH(0); i < AD7298_MAX_CHAN; i++, m >>= 1)
        if (ring->scan_mask & (1 << i))
            command |= m;

    st->tx_buf[0] = cpu_to_be16(command);

    /* build spi ring message */
    st->ring_xfer[0].tx_buf = &st->tx_buf[0];
    st->ring_xfer[0].len = 2;
    st->ring_xfer[0].cs_change = 1;
    st->ring_xfer[1].tx_buf = &st->tx_buf[1];
    st->ring_xfer[1].len = 2;
    st->ring_xfer[1].cs_change = 1;

    spi_message_init(&st->ring_msg);
    spi_message_add_tail(&st->ring_xfer[0], &st->ring_msg);
    spi_message_add_tail(&st->ring_xfer[1], &st->ring_msg);

    for (i = 0; i < ring->scan_count; i++) {
        st->ring_xfer[i + 2].rx_buf = &st->rx_buf[i];
        st->ring_xfer[i + 2].len = 2;
        st->ring_xfer[i + 2].cs_change = 1;
        spi_message_add_tail(&st->ring_xfer[i + 2], &st->ring_msg);
    }
    /* make sure last transfer cs_change is not set */
    st->ring_xfer[i + 1].cs_change = 0;

    return 0;
}
Exemplo n.º 3
0
/**
 * ad7298_update_scan_mode() setup the spi transfer buffer for the new scan mask
 **/
static int ad7298_update_scan_mode(struct iio_dev *indio_dev,
	const unsigned long *active_scan_mask)
{
	struct ad7298_state *st = iio_priv(indio_dev);
	int i, m;
	unsigned short command;
	int scan_count;

	/* Now compute overall size */
	scan_count = bitmap_weight(active_scan_mask, indio_dev->masklength);

	command = AD7298_WRITE | st->ext_ref;

	for (i = 0, m = AD7298_CH(0); i < AD7298_MAX_CHAN; i++, m >>= 1)
		if (test_bit(i, active_scan_mask))
			command |= m;

	st->tx_buf[0] = cpu_to_be16(command);

	/* build spi ring message */
	st->ring_xfer[0].tx_buf = &st->tx_buf[0];
	st->ring_xfer[0].len = 2;
	st->ring_xfer[0].cs_change = 1;
	st->ring_xfer[1].tx_buf = &st->tx_buf[1];
	st->ring_xfer[1].len = 2;
	st->ring_xfer[1].cs_change = 1;

	spi_message_init(&st->ring_msg);
	spi_message_add_tail(&st->ring_xfer[0], &st->ring_msg);
	spi_message_add_tail(&st->ring_xfer[1], &st->ring_msg);

	for (i = 0; i < scan_count; i++) {
		st->ring_xfer[i + 2].rx_buf = &st->rx_buf[i];
		st->ring_xfer[i + 2].len = 2;
		st->ring_xfer[i + 2].cs_change = 1;
		spi_message_add_tail(&st->ring_xfer[i + 2], &st->ring_msg);
	}
	/* make sure last transfer cs_change is not set */
	st->ring_xfer[i + 1].cs_change = 0;

	return 0;
}